Skip to content

Commit 47c6379

Browse files
author
Unity Technologies
committed
Unity 2021.2.0a5 C# reference source code
1 parent e83cf78 commit 47c6379

File tree

704 files changed

+38317
-12848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

704 files changed

+38317
-12848
lines changed

Editor/Mono/2D/SpriteAtlas/SpriteAtlasImporter.bindings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace UnityEditor.U2D
1616
{
1717
// SpriteAtlas Importer lets you modify [[SpriteAtlas]]
1818
[NativeHeader("Editor/Src/2D/SpriteAtlas/SpriteAtlasImporter.h")]
19+
[ExcludeFromPreset]
1920
public sealed partial class SpriteAtlasImporter : AssetImporter
2021
{
2122
extern internal static void MigrateAllSpriteAtlases();

Editor/Mono/2D/SpriteAtlas/SpriteAtlasImporterInspector.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) Unity Technologies. For terms of use, see
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

5+
using System.IO;
56
using System.Collections.Generic;
67
using UnityEngine;
78
using UnityEngine.Experimental.Rendering;
@@ -14,6 +15,7 @@
1415
namespace UnityEditor.U2D
1516
{
1617
[CustomEditor(typeof(SpriteAtlasImporter))]
18+
[ExcludeFromPreset]
1719
internal class SpriteAtlasImporterInspector : Editor
1820
{
1921
class SpriteAtlasInspectorPlatformSettingView : TexturePlatformSettingsView
@@ -57,7 +59,7 @@ class Styles
5759

5860
public readonly GUIContent generateMipMapLabel = EditorGUIUtility.TrTextContent("Generate Mip Maps");
5961
public readonly GUIContent sRGBLabel = EditorGUIUtility.TrTextContent("sRGB", "Texture content is stored in gamma space.");
60-
public readonly GUIContent readWrite = EditorGUIUtility.TrTextContent("Read/Write Enabled", "Enable to be able to access the raw pixel data from code.");
62+
public readonly GUIContent readWrite = EditorGUIUtility.TrTextContent("Read/Write", "Enable to be able to access the raw pixel data from code.");
6163
public readonly GUIContent variantMultiplierLabel = EditorGUIUtility.TrTextContent("Scale", "Down scale ratio.");
6264
public readonly GUIContent copyMasterButton = EditorGUIUtility.TrTextContent("Copy Master's Settings", "Copy all master's settings into this variant.");
6365

@@ -186,6 +188,14 @@ bool IsTargetMaster()
186188
return !spriteAtlasAsset.isVariant;
187189
}
188190

191+
internal override string targetTitle
192+
{
193+
get
194+
{
195+
return Path.GetFileNameWithoutExtension(m_AssetPath) + " (Sprite Atlas)";
196+
}
197+
}
198+
189199
private string LoadSourceAsset()
190200
{
191201
var assetPath = AssetDatabase.GetAssetPath(target);

Editor/Mono/2D/SpriteAtlas/SpriteAtlasInspector.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Styles
5858

5959
public readonly GUIContent generateMipMapLabel = EditorGUIUtility.TrTextContent("Generate Mip Maps");
6060
public readonly GUIContent sRGBLabel = EditorGUIUtility.TrTextContent("sRGB", "Texture content is stored in gamma space.");
61-
public readonly GUIContent readWrite = EditorGUIUtility.TrTextContent("Read/Write Enabled", "Enable to be able to access the raw pixel data from code.");
61+
public readonly GUIContent readWrite = EditorGUIUtility.TrTextContent("Read/Write", "Enable to be able to access the raw pixel data from code.");
6262
public readonly GUIContent variantMultiplierLabel = EditorGUIUtility.TrTextContent("Scale", "Down scale ratio.");
6363
public readonly GUIContent packButton = EditorGUIUtility.TrTextContent("Pack Preview", "Pack this atlas.");
6464

@@ -212,12 +212,13 @@ void OnEnable()
212212
PopulatePlatformSettingsOptions();
213213

214214
m_Packables = serializedObject.FindProperty("m_EditorData.packables");
215-
m_PackableList = new ReorderableList(serializedObject, m_Packables, true, false, true, true);
215+
m_PackableList = new ReorderableList(serializedObject, m_Packables, true, true, true, true);
216+
m_PackableList.drawHeaderCallback = DrawPackablesHeader;
216217
m_PackableList.onAddCallback = AddPackable;
217218
m_PackableList.onRemoveCallback = RemovePackable;
218219
m_PackableList.drawElementCallback = DrawPackableElement;
219220
m_PackableList.elementHeight = EditorGUIUtility.singleLineHeight;
220-
m_PackableList.headerHeight = 3f;
221+
m_PackableList.headerHeight = 3f + EditorGUIUtility.singleLineHeight;
221222

222223
SyncPlatformSettings();
223224

@@ -305,6 +306,11 @@ void RenameSecondaryPlatformSettings(string oldName, string newName)
305306
}
306307
}
307308

309+
void DrawPackablesHeader(Rect headerRect)
310+
{
311+
EditorGUI.LabelField(headerRect, EditorGUIUtility.TempContent("Packables"));
312+
}
313+
308314
void AddPackable(ReorderableList list)
309315
{
310316
ObjectSelector.get.Show(null, typeof(Object), null, false);

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ private void RenderOutOfRangeOverlay(Rect rect)
11461146

11471147
private void SynchronizeLayout()
11481148
{
1149-
m_HorizontalSplitter.realSizes[1] = (int)Mathf.Min(m_Position.width - m_HorizontalSplitter.realSizes[0], m_HorizontalSplitter.realSizes[1]);
1149+
m_HorizontalSplitter.realSizes[1] = (int)Mathf.Max(Mathf.Min(m_Position.width - m_HorizontalSplitter.realSizes[0], m_HorizontalSplitter.realSizes[1]), 0);
11501150

11511151
// Synchronize frame rate
11521152
if (selection.animationClip != null)

Editor/Mono/Animation/AnimationWindow/AnimationWindowControl.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ public override void OnSelectionChanged()
167167

168168
void OnPlayModeStateChanged(PlayModeStateChange state)
169169
{
170-
if (state == PlayModeStateChange.ExitingPlayMode)
170+
if (state == PlayModeStateChange.ExitingPlayMode ||
171+
state == PlayModeStateChange.ExitingEditMode)
171172
{
172173
StopPreview();
173174
StopPlayback();
@@ -222,7 +223,7 @@ public override void GoToPreviousKeyframe()
222223
List<AnimationWindowCurve> curves = (state.showCurveEditor && state.activeCurves.Count > 0) ? state.activeCurves : state.allCurves;
223224

224225
float newTime = AnimationWindowUtility.GetPreviousKeyframeTime(curves.ToArray(), time.time, state.clipFrameRate);
225-
SetCurrentTime(state.SnapToFrame(newTime, AnimationWindowState.SnapMode.SnapToClipFrame));
226+
SetCurrentTime(state.SnapToFrame(newTime, AnimationWindowState.SnapMode.SnapToFrame));
226227
}
227228

228229
public void GoToPreviousKeyframe(PropertyModification[] modifications)
@@ -240,7 +241,7 @@ public void GoToPreviousKeyframe(PropertyModification[] modifications)
240241
}
241242

242243
float newTime = AnimationWindowUtility.GetPreviousKeyframeTime(curves.ToArray(), time.time, state.clipFrameRate);
243-
SetCurrentTime(state.SnapToFrame(newTime, AnimationWindowState.SnapMode.SnapToClipFrame));
244+
SetCurrentTime(state.SnapToFrame(newTime, AnimationWindowState.SnapMode.SnapToFrame));
244245

245246
state.Repaint();
246247
}
@@ -250,7 +251,7 @@ public override void GoToNextKeyframe()
250251
List<AnimationWindowCurve> curves = (state.showCurveEditor && state.activeCurves.Count > 0) ? state.activeCurves : state.allCurves;
251252

252253
float newTime = AnimationWindowUtility.GetNextKeyframeTime(curves.ToArray(), time.time, state.clipFrameRate);
253-
SetCurrentTime(state.SnapToFrame(newTime, AnimationWindowState.SnapMode.SnapToClipFrame));
254+
SetCurrentTime(state.SnapToFrame(newTime, AnimationWindowState.SnapMode.SnapToFrame));
254255
}
255256

256257
public void GoToNextKeyframe(PropertyModification[] modifications)
@@ -268,7 +269,7 @@ public void GoToNextKeyframe(PropertyModification[] modifications)
268269
}
269270

270271
float newTime = AnimationWindowUtility.GetNextKeyframeTime(curves.ToArray(), time.time, state.clipFrameRate);
271-
SetCurrentTime(state.SnapToFrame(newTime, AnimationWindowState.SnapMode.SnapToClipFrame));
272+
SetCurrentTime(state.SnapToFrame(newTime, AnimationWindowState.SnapMode.SnapToFrame));
272273

273274
state.Repaint();
274275
}

Editor/Mono/Animation/AnimationWindow/AnimationWindowEventInspector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void OnEditAnimationEvents(AnimationWindowEvent[] awEvents)
4949

5050
bool singleFunctionName = Array.TrueForAll(data.selectedEvents, evt => evt.functionName == firstEvent.functionName);
5151

52-
GUI.changed = false;
52+
EditorGUI.BeginChangeCheck();
5353

5454
if (data.root != null)
5555
{
@@ -158,7 +158,7 @@ public static void OnEditAnimationEvents(AnimationWindowEvent[] awEvents)
158158
}
159159
}
160160

161-
if (GUI.changed)
161+
if (EditorGUI.EndChangeCheck())
162162
SetData(awEvents, data);
163163
}
164164

Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum SnapMode
2626
{
2727
Disabled = 0,
2828
SnapToFrame = 1,
29+
[Obsolete("SnapToClipFrame has been made redundant with SnapToFrame, SnapToFrame will behave the same.")]
2930
SnapToClipFrame = 2
3031
}
3132

Editor/Mono/Animation/AnimationWindow/AnimationWindowUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ public static bool ForceGrouping(EditorCurveBinding binding)
13171317
if (typeof(Renderer).IsAssignableFrom(binding.type))
13181318
{
13191319
string group = GetPropertyGroupName(binding.propertyName);
1320-
return group == "material._Color";
1320+
return group == "material._Color" || group == "material._BaseColor";
13211321
}
13221322
return false;
13231323
}

Editor/Mono/Animation/AnimationWindow/DopeSheetEditor.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ private void DopeLineRepaint(DopeLine dopeline)
495495

496496
if (DoDragAndDrop(dopeline, dopeline.position, false))
497497
{
498-
float time = Mathf.Max(state.PixelToTime(Event.current.mousePosition.x, AnimationWindowState.SnapMode.SnapToClipFrame), 0f);
498+
float time = Mathf.Max(state.PixelToTime(Event.current.mousePosition.x, AnimationWindowState.SnapMode.SnapToFrame), 0f);
499499

500500
Color keyColor = Color.gray.RGBMultiplied(1.2f);
501501
Texture2D texture = null;
@@ -563,7 +563,7 @@ private GenericMenu GenerateMenu(DopeLine dopeline)
563563
hoveringKeys.Add(key);
564564
}
565565

566-
AnimationKeyTime mouseKeyTime = AnimationKeyTime.Time(state.PixelToTime(Event.current.mousePosition.x, AnimationWindowState.SnapMode.SnapToClipFrame), state.frameRate);
566+
AnimationKeyTime mouseKeyTime = AnimationKeyTime.Time(state.PixelToTime(Event.current.mousePosition.x, AnimationWindowState.SnapMode.SnapToFrame), state.frameRate);
567567

568568
string str = L10n.Tr("Add Key");
569569
if (dopeline.isEditable && hoveringKeys.Count == 0)
@@ -640,7 +640,7 @@ private void HandleDragging()
640640
foreach (AnimationWindowKeyframe selectedKey in state.selectedKeys)
641641
firstSelectedKeyTime = Mathf.Min(selectedKey.time, firstSelectedKeyTime);
642642

643-
float currentTime = state.SnapToFrame(state.PixelToTime(Event.current.mousePosition.x), AnimationWindowState.SnapMode.SnapToClipFrame);
643+
float currentTime = state.SnapToFrame(state.PixelToTime(Event.current.mousePosition.x), AnimationWindowState.SnapMode.SnapToFrame);
644644

645645
if (m_IsDragging)
646646
{
@@ -1005,7 +1005,7 @@ private void HandleMouseDown(DopeLine dopeline)
10051005

10061006
private void HandleDopelineDoubleclick(DopeLine dopeline)
10071007
{
1008-
float timeAtMousePosition = state.PixelToTime(Event.current.mousePosition.x, AnimationWindowState.SnapMode.SnapToClipFrame);
1008+
float timeAtMousePosition = state.PixelToTime(Event.current.mousePosition.x, AnimationWindowState.SnapMode.SnapToFrame);
10091009
AnimationKeyTime mouseKeyTime = AnimationKeyTime.Time(timeAtMousePosition, state.frameRate);
10101010
AnimationWindowUtility.AddKeyframes(state, dopeline.curves, mouseKeyTime);
10111011

@@ -1029,7 +1029,7 @@ private Rect GetKeyframeRect(DopeLine dopeline, AnimationWindowKeyframe keyframe
10291029
if (dopeline.isPptrDopeline && dopeline.tallMode && (keyframe == null || keyframe.value != null))
10301030
width = dopeline.position.height;
10311031

1032-
return new Rect(state.TimeToPixel(state.SnapToFrame(time, AnimationWindowState.SnapMode.SnapToClipFrame)) + GetKeyframeOffset(dopeline, keyframe), dopeline.position.yMin, width, dopeline.position.height);
1032+
return new Rect(state.TimeToPixel(state.SnapToFrame(time, AnimationWindowState.SnapMode.SnapToFrame)) + GetKeyframeOffset(dopeline, keyframe), dopeline.position.yMin, width, dopeline.position.height);
10331033
}
10341034

10351035
// This means "how much is the rendered keyframe offset in pixels for x-axis".
@@ -1164,7 +1164,7 @@ private bool DoDragAndDrop(DopeLine dopeLine, Rect position, bool perform)
11641164

11651165
if (perform)
11661166
{
1167-
float time = Mathf.Max(state.PixelToTime(Event.current.mousePosition.x, AnimationWindowState.SnapMode.SnapToClipFrame), 0f);
1167+
float time = Mathf.Max(state.PixelToTime(Event.current.mousePosition.x, AnimationWindowState.SnapMode.SnapToFrame), 0f);
11681168
AnimationWindowCurve targetCurve = GetCurveOfType(dopeLine, targetType);
11691169
PerformDragAndDrop(targetCurve, time);
11701170
}
@@ -1423,8 +1423,8 @@ public Rect GetCurrentPixelRect()
14231423
{
14241424
float height = AnimationWindowHierarchyGUI.k_DopeSheetRowHeight;
14251425
Rect r = AnimationWindowUtility.FromToRect(m_SelectStartPoint, m_SelectMousePoint);
1426-
r.xMin = owner.state.TimeToPixel(owner.state.PixelToTime(r.xMin, AnimationWindowState.SnapMode.SnapToClipFrame), AnimationWindowState.SnapMode.SnapToClipFrame);
1427-
r.xMax = owner.state.TimeToPixel(owner.state.PixelToTime(r.xMax, AnimationWindowState.SnapMode.SnapToClipFrame), AnimationWindowState.SnapMode.SnapToClipFrame);
1426+
r.xMin = owner.state.TimeToPixel(owner.state.PixelToTime(r.xMin, AnimationWindowState.SnapMode.SnapToFrame), AnimationWindowState.SnapMode.SnapToFrame);
1427+
r.xMax = owner.state.TimeToPixel(owner.state.PixelToTime(r.xMax, AnimationWindowState.SnapMode.SnapToFrame), AnimationWindowState.SnapMode.SnapToFrame);
14281428
r.yMin = Mathf.Floor(r.yMin / height) * height;
14291429
r.yMax = (Mathf.Floor(r.yMax / height) + 1) * height;
14301430
return r;
@@ -1434,8 +1434,8 @@ public Rect GetCurrentTimeRect()
14341434
{
14351435
float height = AnimationWindowHierarchyGUI.k_DopeSheetRowHeight;
14361436
Rect r = AnimationWindowUtility.FromToRect(m_SelectStartPoint, m_SelectMousePoint);
1437-
r.xMin = owner.state.PixelToTime(r.xMin, AnimationWindowState.SnapMode.SnapToClipFrame);
1438-
r.xMax = owner.state.PixelToTime(r.xMax, AnimationWindowState.SnapMode.SnapToClipFrame);
1437+
r.xMin = owner.state.PixelToTime(r.xMin, AnimationWindowState.SnapMode.SnapToFrame);
1438+
r.xMax = owner.state.PixelToTime(r.xMax, AnimationWindowState.SnapMode.SnapToFrame);
14391439
r.yMin = Mathf.Floor(r.yMin / height) * height;
14401440
r.yMax = (Mathf.Floor(r.yMax / height) + 1) * height;
14411441
return r;

Editor/Mono/Animation/StateMachine.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -521,42 +521,46 @@ internal void RemoveAnyStateTransitionRecursive(AnimatorStateTransition transiti
521521

522522
public AnimatorTransition AddStateMachineTransition(AnimatorStateMachine sourceStateMachine)
523523
{
524-
AnimatorStateMachine sm = null;
525-
return AddStateMachineTransition(sourceStateMachine, sm);
524+
AnimatorTransition newTransition = new AnimatorTransition();
525+
AddStateMachineTransition(sourceStateMachine, newTransition);
526+
return newTransition;
526527
}
527528

528529
public AnimatorTransition AddStateMachineTransition(AnimatorStateMachine sourceStateMachine, AnimatorStateMachine destinationStateMachine)
529530
{
530-
undoHandler.DoUndo(this, "StateMachine Transition Added");
531-
532-
AnimatorTransition[] transitionsVector = GetStateMachineTransitions(sourceStateMachine);
533531
AnimatorTransition newTransition = new AnimatorTransition();
534-
if (destinationStateMachine)
535-
{
536-
newTransition.destinationStateMachine = destinationStateMachine;
537-
}
538-
539-
if (AssetDatabase.GetAssetPath(this) != "")
540-
AssetDatabase.AddObjectToAsset(newTransition, AssetDatabase.GetAssetPath(this));
541-
542-
newTransition.hideFlags = HideFlags.HideInHierarchy;
543-
ArrayUtility.Add(ref transitionsVector, newTransition);
544-
SetStateMachineTransitions(sourceStateMachine, transitionsVector);
545-
532+
newTransition.destinationStateMachine = destinationStateMachine;
533+
AddStateMachineTransition(sourceStateMachine, newTransition);
546534
return newTransition;
547535
}
548536

549537
public AnimatorTransition AddStateMachineTransition(AnimatorStateMachine sourceStateMachine, AnimatorState destinationState)
550538
{
551-
AnimatorTransition newTransition = AddStateMachineTransition(sourceStateMachine);
539+
AnimatorTransition newTransition = new AnimatorTransition();
552540
newTransition.destinationState = destinationState;
541+
AddStateMachineTransition(sourceStateMachine, newTransition);
553542
return newTransition;
554543
}
555544

545+
internal void AddStateMachineTransition(AnimatorStateMachine sourceStateMachine, AnimatorTransition transition)
546+
{
547+
undoHandler.DoUndo(this, "StateMachine Transition Added");
548+
549+
AnimatorTransition[] transitionsVector = GetStateMachineTransitions(sourceStateMachine);
550+
551+
if (AssetDatabase.GetAssetPath(this) != "")
552+
AssetDatabase.AddObjectToAsset(transition, AssetDatabase.GetAssetPath(this));
553+
554+
transition.hideFlags = HideFlags.HideInHierarchy;
555+
ArrayUtility.Add(ref transitionsVector, transition);
556+
SetStateMachineTransitions(sourceStateMachine, transitionsVector);
557+
}
558+
556559
public AnimatorTransition AddStateMachineExitTransition(AnimatorStateMachine sourceStateMachine)
557560
{
558-
AnimatorTransition newTransition = AddStateMachineTransition(sourceStateMachine);
561+
AnimatorTransition newTransition = new AnimatorTransition();
559562
newTransition.isExit = true;
563+
AddStateMachineTransition(sourceStateMachine, newTransition);
560564
return newTransition;
561565
}
562566

0 commit comments

Comments
 (0)