Skip to content

Commit 7a338a1

Browse files
author
Unity Technologies
committed
Unity 2019.1.0a8 C# reference source code
1 parent 6a4ef27 commit 7a338a1

File tree

670 files changed

+52518
-10328
lines changed

Some content is hidden

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

670 files changed

+52518
-10328
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,8 @@ void DrawPackableElement(Rect rect, int index, bool selected, bool focused)
246246
var controlID = EditorGUIUtility.GetControlID(s_Styles.packableElementHash, FocusType.Passive);
247247
var previousObject = property.objectReferenceValue;
248248

249-
EditorGUI.BeginChangeCheck();
250249
var changedObject = EditorGUI.DoObjectField(rect, rect, controlID, previousObject, typeof(Object), null, ValidateObjectForPackableFieldAssignment, false);
251-
if (EditorGUI.EndChangeCheck())
250+
if (changedObject != previousObject)
252251
{
253252
// Always call Remove() on the previous object if we swapping the object field item.
254253
// This ensure the Sprites was pack in this atlas will be refreshed of it unbound.

Editor/Mono/2D/SpriteEditorModule/ISpriteEditorModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Linq;
77
using System.Collections.Generic;
88
using UnityEngine;
9-
using UnityEngine.Experimental.UIElements;
9+
using UnityEngine.UIElements;
1010

1111
namespace UnityEditor.Experimental.U2D
1212
{

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpriteFrameModuleBaseView.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using UnityEditor.Experimental.U2D;
6-
using UnityEditor.Experimental.UIElements;
7-
using UnityEngine.Experimental.UIElements;
6+
using UnityEditor.UIElements;
7+
using UnityEngine.UIElements;
88
using UnityEngine;
99
using UnityEditorInternal;
1010
using UnityEngine.U2D.Interface;
@@ -119,11 +119,11 @@ private void UpdatePositionField(Rect rect)
119119
private void AddMainUI(VisualElement mainView)
120120
{
121121
var visualTree = EditorGUIUtility.Load("UXML/SpriteEditor/SpriteFrameModuleInspector.uxml") as VisualTreeAsset;
122-
m_SelectedFrameInspector = visualTree.CloneTree(null).Q("spriteFrameModuleInspector");
122+
m_SelectedFrameInspector = visualTree.CloneTree().Q("spriteFrameModuleInspector");
123123

124124
m_NameElement = m_SelectedFrameInspector.Q("name");
125125
m_NameField = m_SelectedFrameInspector.Q<PropertyControl<string>>("spriteName");
126-
m_NameField.OnValueChanged((evt) =>
126+
m_NameField.RegisterValueChangedCallback((evt) =>
127127
{
128128
if (hasSelected)
129129
{
@@ -142,7 +142,7 @@ private void AddMainUI(VisualElement mainView)
142142

143143
m_PositionElement = m_SelectedFrameInspector.Q("position");
144144
m_PositionFieldX = m_PositionElement.Q<PropertyControl<long>>("positionX");
145-
m_PositionFieldX.OnValueChanged((evt) =>
145+
m_PositionFieldX.RegisterValueChangedCallback((evt) =>
146146
{
147147
if (hasSelected)
148148
{
@@ -154,7 +154,7 @@ private void AddMainUI(VisualElement mainView)
154154
});
155155

156156
m_PositionFieldY = m_PositionElement.Q<PropertyControl<long>>("positionY");
157-
m_PositionFieldY.OnValueChanged((evt) =>
157+
m_PositionFieldY.RegisterValueChangedCallback((evt) =>
158158
{
159159
if (hasSelected)
160160
{
@@ -166,7 +166,7 @@ private void AddMainUI(VisualElement mainView)
166166
});
167167

168168
m_PositionFieldW = m_PositionElement.Q<PropertyControl<long>>("positionW");
169-
m_PositionFieldW.OnValueChanged((evt) =>
169+
m_PositionFieldW.RegisterValueChangedCallback((evt) =>
170170
{
171171
if (hasSelected)
172172
{
@@ -178,7 +178,7 @@ private void AddMainUI(VisualElement mainView)
178178
});
179179

180180
m_PositionFieldH = m_PositionElement.Q<PropertyControl<long>>("positionH");
181-
m_PositionFieldH.OnValueChanged((evt) =>
181+
m_PositionFieldH.RegisterValueChangedCallback((evt) =>
182182
{
183183
if (hasSelected)
184184
{
@@ -191,7 +191,7 @@ private void AddMainUI(VisualElement mainView)
191191

192192
var borderElement = m_SelectedFrameInspector.Q("border");
193193
m_BorderFieldL = borderElement.Q<PropertyControl<long>>("borderL");
194-
m_BorderFieldL.OnValueChanged((evt) =>
194+
m_BorderFieldL.RegisterValueChangedCallback((evt) =>
195195
{
196196
if (hasSelected)
197197
{
@@ -203,7 +203,7 @@ private void AddMainUI(VisualElement mainView)
203203
});
204204

205205
m_BorderFieldT = borderElement.Q<PropertyControl<long>>("borderT");
206-
m_BorderFieldT.OnValueChanged((evt) =>
206+
m_BorderFieldT.RegisterValueChangedCallback((evt) =>
207207
{
208208
if (hasSelected)
209209
{
@@ -216,7 +216,7 @@ private void AddMainUI(VisualElement mainView)
216216
});
217217

218218
m_BorderFieldR = borderElement.Q<PropertyControl<long>>("borderR");
219-
m_BorderFieldR.OnValueChanged((evt) =>
219+
m_BorderFieldR.RegisterValueChangedCallback((evt) =>
220220
{
221221
if (hasSelected)
222222
{
@@ -228,7 +228,7 @@ private void AddMainUI(VisualElement mainView)
228228
});
229229

230230
m_BorderFieldB = borderElement.Q<PropertyControl<long>>("borderB");
231-
m_BorderFieldB.OnValueChanged((evt) =>
231+
m_BorderFieldB.RegisterValueChangedCallback((evt) =>
232232
{
233233
if (hasSelected)
234234
{
@@ -241,7 +241,7 @@ private void AddMainUI(VisualElement mainView)
241241

242242
m_PivotField = m_SelectedFrameInspector.Q<EnumField>("pivotField");
243243
m_PivotField.Init(SpriteAlignment.Center);
244-
m_PivotField.OnValueChanged((evt) =>
244+
m_PivotField.RegisterValueChangedCallback((evt) =>
245245
{
246246
if (hasSelected)
247247
{
@@ -257,7 +257,7 @@ private void AddMainUI(VisualElement mainView)
257257

258258
m_PivotUnitModeField = m_SelectedFrameInspector.Q<EnumField>("pivotUnitModeField");
259259
m_PivotUnitModeField.Init(PivotUnitMode.Normalized);
260-
m_PivotUnitModeField.OnValueChanged((evt) =>
260+
m_PivotUnitModeField.RegisterValueChangedCallback((evt) =>
261261
{
262262
if (hasSelected)
263263
{
@@ -272,7 +272,7 @@ private void AddMainUI(VisualElement mainView)
272272

273273
m_CustomPivotElement = m_SelectedFrameInspector.Q("customPivot");
274274
m_CustomPivotFieldX = m_CustomPivotElement.Q<PropertyControl<double>>("customPivotX");
275-
m_CustomPivotFieldX.OnValueChanged((evt) =>
275+
m_CustomPivotFieldX.RegisterValueChangedCallback((evt) =>
276276
{
277277
if (hasSelected)
278278
{
@@ -288,7 +288,7 @@ private void AddMainUI(VisualElement mainView)
288288
});
289289

290290
m_CustomPivotFieldY = m_CustomPivotElement.Q<PropertyControl<double>>("customPivotY");
291-
m_CustomPivotFieldY.OnValueChanged((evt) =>
291+
m_CustomPivotFieldY.RegisterValueChangedCallback((evt) =>
292292
{
293293
if (hasSelected)
294294
{

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpritePolygonModeModuleView.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
using System.Collections.Generic;
66
using UnityEngine;
77
using UnityEditorInternal;
8-
using UnityEditor.Experimental.UIElements;
9-
using UnityEngine.Experimental.UIElements;
10-
using UnityEngine.Experimental.UIElements.StyleEnums;
11-
using UIElementButton = UnityEngine.Experimental.UIElements.Button;
8+
using UnityEditor.UIElements;
9+
using UnityEngine.UIElements;
10+
using UIElementButton = UnityEngine.UIElements.Button;
1211

1312
namespace UnityEditor
1413
{
@@ -27,7 +26,7 @@ private static class SpritePolygonModeStyles
2726
private void AddMainUI(VisualElement element)
2827
{
2928
var visualTree = EditorGUIUtility.Load("UXML/SpriteEditor/PolygonChangeShapeWindow.uxml") as VisualTreeAsset;
30-
m_PolygonShapeView = visualTree.CloneTree(null).Q<VisualElement>("polygonShapeWindow");
29+
m_PolygonShapeView = visualTree.CloneTree().Q<VisualElement>("polygonShapeWindow");
3130
m_PolygonShapeView.RegisterCallback<MouseDownEvent>((e) => { e.StopPropagation(); });
3231
m_PolygonShapeView.RegisterCallback<MouseUpEvent>((e) => { e.StopPropagation(); });
3332
SetupPolygonChangeShapeWindowElements(m_PolygonShapeView);
@@ -97,7 +96,7 @@ private void SetupPolygonChangeShapeWindowElements(VisualElement moduleView)
9796
{
9897
var sidesField = moduleView.Q<PropertyControl<long>>("labelIntegerField");
9998
sidesField.SetValueWithoutNotify(polygonSides);
100-
sidesField.OnValueChanged((evt) =>
99+
sidesField.RegisterValueChangedCallback((evt) =>
101100
{
102101
polygonSides = (int)evt.newValue;
103102
ShowHideWarningMessage();
@@ -118,10 +117,10 @@ private void SetupPolygonChangeShapeWindowElements(VisualElement moduleView)
118117
void ShowHideWarningMessage()
119118
{
120119
m_WarningMessage.visible = !isSidesValid;
121-
m_WarningMessage.style.positionType = m_WarningMessage.visible ? PositionType.Relative : PositionType.Absolute;
120+
m_WarningMessage.style.position = m_WarningMessage.visible ? Position.Relative : Position.Absolute;
122121

123122
m_ChangeButton.visible = isSidesValid;
124-
m_ChangeButton.style.positionType = m_ChangeButton.visible ? PositionType.Relative : PositionType.Absolute;
123+
m_ChangeButton.style.position = m_ChangeButton.visible ? Position.Relative : Position.Absolute;
125124
}
126125

127126
private bool isSidesValid

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,6 @@ internal enum WrapModeFixed
2222
PingPong = (int)WrapMode.PingPong
2323
}
2424

25-
class AnimationShortcutContex : IShortcutToolContext
26-
{
27-
AnimEditor m_AnimEditor;
28-
public AnimationShortcutContex(AnimEditor animEditor)
29-
{
30-
m_AnimEditor = animEditor;
31-
}
32-
33-
public bool active
34-
{
35-
get { return !animEditor.stateDisabled && !animEditor.state.animatorIsOptimized; }
36-
}
37-
38-
public AnimEditor animEditor
39-
{
40-
get { return m_AnimEditor; }
41-
}
42-
}
43-
4425
internal class AnimEditor : ScriptableObject
4526
{
4627
// Active Animation windows
@@ -102,8 +83,6 @@ static private Color inRangeColor
10283
}
10384
}
10485

105-
AnimationShortcutContex m_AnimationShortcutContex;
106-
10786
internal const int kSliderThickness = 15;
10887
internal const int kLayoutRowHeight = EditorGUI.kWindowToolbarHeight + 1;
10988
internal const int kIntFieldWidth = 35;
@@ -356,9 +335,6 @@ public void OnEnable()
356335

357336
m_CurveEditor.curvesUpdated += SaveChangedCurvesFromCurveEditor;
358337
m_CurveEditor.OnEnable();
359-
360-
m_AnimationShortcutContex = new AnimationShortcutContex(this);
361-
ShortcutIntegration.instance.contextManager.RegisterToolContext(m_AnimationShortcutContex);
362338
}
363339

364340
public void OnDisable()
@@ -375,7 +351,6 @@ public void OnDisable()
375351
m_DopeSheet.OnDisable();
376352

377353
m_State.OnDisable();
378-
ShortcutIntegration.instance.contextManager.DeregisterToolContext(m_AnimationShortcutContex);
379354
}
380355

381356
public void OnDestroy()
@@ -729,10 +704,13 @@ private void LinkOptionsOnGUI()
729704

730705
static void ExecuteShortcut(ShortcutArguments args, Action<AnimEditor> exp)
731706
{
732-
var animEditorContext = (AnimationShortcutContex)args.context;
733-
var animEditor = animEditorContext.animEditor;
707+
var animationWindow = (AnimationWindow)args.context;
708+
var animEditor = animationWindow.animEditor;
709+
710+
if (EditorWindow.focusedWindow != animationWindow)
711+
return;
734712

735-
if (EditorWindow.focusedWindow != animEditor.m_OwnerWindow)
713+
if (animEditor.stateDisabled || animEditor.state.animatorIsOptimized)
736714
return;
737715

738716
exp(animEditor);
@@ -746,14 +724,14 @@ static void ExecuteShortcut(ShortcutArguments args, Action<IAnimationWindowContr
746724
}
747725

748726
[FormerlyPrefKeyAs("Animation/Show Curves", "c")]
749-
[Shortcut("Animation/Show Curves", typeof(AnimationShortcutContex), KeyCode.C)]
727+
[Shortcut("Animation/Show Curves", typeof(AnimationWindow), KeyCode.C)]
750728
static void ShowCurves(ShortcutArguments args)
751729
{
752730
ExecuteShortcut(args, animEditor => { animEditor.SwitchBetweenCurvesAndDopesheet(); });
753731
}
754732

755733
[FormerlyPrefKeyAs("Animation/Play Animation", " ")]
756-
[Shortcut("Animation/Play Animation", typeof(AnimationShortcutContex), KeyCode.Space)]
734+
[Shortcut("Animation/Play Animation", typeof(AnimationWindow), KeyCode.Space)]
757735
static void TogglePlayAnimation(ShortcutArguments args)
758736
{
759737
ExecuteShortcut(args, controlInterface =>
@@ -766,76 +744,75 @@ static void TogglePlayAnimation(ShortcutArguments args)
766744
}
767745

768746
[FormerlyPrefKeyAs("Animation/Next Frame", ".")]
769-
[Shortcut("Animation/Next Frame", typeof(AnimationShortcutContex), KeyCode.Period)]
747+
[Shortcut("Animation/Next Frame", typeof(AnimationWindow), KeyCode.Period)]
770748
static void NextFrame(ShortcutArguments args)
771749
{
772750
ExecuteShortcut(args, controlInterface => controlInterface.GoToNextFrame());
773751
}
774752

775753
[FormerlyPrefKeyAs("Animation/Previous Frame", ",")]
776-
[Shortcut("Animation/Previous Frame", typeof(AnimationShortcutContex), KeyCode.Comma)]
754+
[Shortcut("Animation/Previous Frame", typeof(AnimationWindow), KeyCode.Comma)]
777755
static void PreviousFrame(ShortcutArguments args)
778756
{
779757
ExecuteShortcut(args, controlInterface => controlInterface.GoToPreviousFrame());
780758
}
781759

782760
[FormerlyPrefKeyAs("Animation/Previous Keyframe", "&,")]
783-
[Shortcut("Animation/Previous Keyframe", typeof(AnimationShortcutContex), KeyCode.Comma, ShortcutModifiers.Alt)]
761+
[Shortcut("Animation/Previous Keyframe", typeof(AnimationWindow), KeyCode.Comma, ShortcutModifiers.Alt)]
784762
static void PreviousKeyFrame(ShortcutArguments args)
785763
{
786764
ExecuteShortcut(args, controlInterface => controlInterface.GoToPreviousKeyframe());
787765
}
788766

789767
[FormerlyPrefKeyAs("Animation/Next Keyframe", "&.")]
790-
[Shortcut("Animation/Next Keyframe", typeof(AnimationShortcutContex), KeyCode.Period, ShortcutModifiers.Alt)]
768+
[Shortcut("Animation/Next Keyframe", typeof(AnimationWindow), KeyCode.Period, ShortcutModifiers.Alt)]
791769
static void NextKeyFrame(ShortcutArguments args)
792770
{
793771
ExecuteShortcut(args, controlInterface => controlInterface.GoToNextKeyframe());
794772
}
795773

796774
[FormerlyPrefKeyAs("Animation/First Keyframe", "#,")]
797-
[Shortcut("Animation/First Keyframe", typeof(AnimationShortcutContex), KeyCode.Comma, ShortcutModifiers.Shift)]
775+
[Shortcut("Animation/First Keyframe", typeof(AnimationWindow), KeyCode.Comma, ShortcutModifiers.Shift)]
798776
static void FirstKeyFrame(ShortcutArguments args)
799777
{
800778
ExecuteShortcut(args, controlInterface => controlInterface.GoToFirstKeyframe());
801779
}
802780

803781
[FormerlyPrefKeyAs("Animation/Last Keyframe", "#.")]
804-
[Shortcut("Animation/Last Keyframe", typeof(AnimationShortcutContex), KeyCode.Period, ShortcutModifiers.Shift)]
782+
[Shortcut("Animation/Last Keyframe", typeof(AnimationWindow), KeyCode.Period, ShortcutModifiers.Shift)]
805783
static void LastKeyFrame(ShortcutArguments args)
806784
{
807785
ExecuteShortcut(args, controlInterface => controlInterface.GoToLastKeyframe());
808786
}
809787

810788
[FormerlyPrefKeyAs("Animation/Key Selected", "k")]
811-
[Shortcut("Animation/Key Selected", typeof(AnimationShortcutContex), KeyCode.K)]
789+
[Shortcut("Animation/Key Selected", null, KeyCode.K)]
812790
static void KeySelected(ShortcutArguments args)
813791
{
814-
var animEditorContext = (AnimationShortcutContex)args.context;
815-
var animEditor = animEditorContext.animEditor;
816-
817-
if (!animEditor.m_State.previewing)
792+
AnimationWindow animationWindow = AnimationWindow.GetAllAnimationWindows().Find(aw => (aw.state.previewing || aw == EditorWindow.focusedWindow));
793+
if (animationWindow == null)
818794
return;
819795

796+
var animEditor = animationWindow.animEditor;
797+
820798
animEditor.SaveCurveEditorKeySelection();
821799
AnimationWindowUtility.AddSelectedKeyframes(animEditor.m_State, animEditor.controlInterface.time);
822-
if (!animEditor.m_OwnerWindow.hasFocus)
823-
animEditor.controlInterface.ClearCandidates();
800+
animEditor.controlInterface.ClearCandidates();
824801
animEditor.UpdateSelectedKeysToCurveEditor();
825802

826803
animEditor.Repaint();
827804
}
828805

829806
[FormerlyPrefKeyAs("Animation/Key Modified", "#k")]
830-
[Shortcut("Animation/Key Modified", typeof(AnimationShortcutContex), KeyCode.K, ShortcutModifiers.Shift)]
807+
[Shortcut("Animation/Key Modified", null, KeyCode.K, ShortcutModifiers.Shift)]
831808
static void KeyModified(ShortcutArguments args)
832809
{
833-
var animEditorContext = (AnimationShortcutContex)args.context;
834-
var animEditor = animEditorContext.animEditor;
835-
836-
if (!animEditor.m_State.previewing)
810+
AnimationWindow animationWindow = AnimationWindow.GetAllAnimationWindows().Find(aw => (aw.state.previewing || aw == EditorWindow.focusedWindow));
811+
if (animationWindow == null)
837812
return;
838813

814+
var animEditor = animationWindow.animEditor;
815+
839816
animEditor.SaveCurveEditorKeySelection();
840817
animEditor.controlInterface.ProcessCandidates();
841818
animEditor.UpdateSelectedKeysToCurveEditor();
@@ -1226,6 +1203,7 @@ private void InitializeCurveEditor()
12261203
settings.allowDeleteLastKeyInCurve = true;
12271204
settings.rectangleToolFlags = CurveEditorSettings.RectangleToolFlags.FullRectangleTool;
12281205
settings.undoRedoSelection = true;
1206+
settings.flushCurveCache = false; // Curve Wrappers are cached in AnimationWindowState.
12291207

12301208
m_CurveEditor.shownArea = new Rect(1, 1, 1, 1);
12311209
m_CurveEditor.settings = settings;

0 commit comments

Comments
 (0)