Skip to content

Commit 2ecf4d3

Browse files
author
Unity Technologies
committed
Unity 2017.1.0b1 C# reference source code
1 parent 96f4367 commit 2ecf4d3

138 files changed

Lines changed: 5483 additions & 2287 deletions

File tree

Some content is hidden

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

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static private Color inRangeColor
9090
internal static PrefKey kAnimationNextKeyframe = new PrefKey("Animation/Next Keyframe", "&.");
9191
internal static PrefKey kAnimationFirstKey = new PrefKey("Animation/First Keyframe", "#,");
9292
internal static PrefKey kAnimationLastKey = new PrefKey("Animation/Last Keyframe", "#.");
93-
internal static PrefKey kAnimationRecordKeyframe = new PrefKey("Animation/Record Keyframe", "k");
93+
internal static PrefKey kAnimationRecordKeyframeSelected = new PrefKey("Animation/Key Selected", "k");
94+
internal static PrefKey kAnimationRecordKeyframeModified = new PrefKey("Animation/Key Modified", "#k");
9495
internal static PrefKey kAnimationShowCurvesToggle = new PrefKey("Animation/Show Curves", "c");
9596

9697
internal const int kSliderThickness = 15;
@@ -351,6 +352,8 @@ public void OnEnable()
351352

352353
m_CurveEditor.curvesUpdated += SaveChangedCurvesFromCurveEditor;
353354
m_CurveEditor.OnEnable();
355+
356+
EditorApplication.globalEventHandler += HandleGlobalHotkeys;
354357
}
355358

356359
public void OnDisable()
@@ -367,6 +370,8 @@ public void OnDisable()
367370
m_DopeSheet.OnDisable();
368371

369372
m_State.OnDisable();
373+
374+
EditorApplication.globalEventHandler -= HandleGlobalHotkeys;
370375
}
371376

372377
public void OnDestroy()
@@ -792,11 +797,47 @@ private void HandleHotKeys()
792797
Event.current.Use();
793798
}
794799

795-
if (kAnimationRecordKeyframe.activated)
800+
if (kAnimationRecordKeyframeSelected.activated)
801+
{
802+
SaveCurveEditorKeySelection();
803+
AnimationWindowUtility.AddSelectedKeyframes(m_State, controlInterface.time);
804+
UpdateSelectedKeysToCurveEditor();
805+
806+
Event.current.Use();
807+
}
808+
809+
if (kAnimationRecordKeyframeModified.activated)
810+
{
811+
SaveCurveEditorKeySelection();
812+
controlInterface.ProcessCandidates();
813+
UpdateSelectedKeysToCurveEditor();
814+
815+
Event.current.Use();
816+
}
817+
}
818+
819+
public void HandleGlobalHotkeys()
820+
{
821+
if (!m_State.previewing)
822+
return;
823+
824+
if (!GUI.enabled || m_State.disabled)
825+
return;
826+
827+
if (kAnimationRecordKeyframeSelected.activated)
828+
{
829+
SaveCurveEditorKeySelection();
830+
AnimationWindowUtility.AddSelectedKeyframes(m_State, controlInterface.time);
831+
controlInterface.ClearCandidates();
832+
UpdateSelectedKeysToCurveEditor();
833+
834+
Event.current.Use();
835+
}
836+
837+
if (kAnimationRecordKeyframeModified.activated)
796838
{
797839
SaveCurveEditorKeySelection();
798-
var keyTime = AnimationKeyTime.Time(m_State.currentTime, m_State.frameRate);
799-
AnimationWindowUtility.AddSelectedKeyframes(m_State, keyTime);
840+
controlInterface.ProcessCandidates();
800841
UpdateSelectedKeysToCurveEditor();
801842

802843
Event.current.Use();
@@ -1049,10 +1090,27 @@ private void UpdateSelectedKeysToCurveEditor()
10491090
private void SaveCurveEditorKeySelection()
10501091
{
10511092
// Synchronize current selection in curve editor and save selection snapshot in undo redo.
1052-
UpdateSelectedKeysToCurveEditor();
1093+
if (m_State.showCurveEditor)
1094+
UpdateSelectedKeysFromCurveEditor();
1095+
else
1096+
UpdateSelectedKeysToCurveEditor();
1097+
10531098
m_CurveEditor.SaveKeySelection(AnimationWindowState.kEditCurveUndoLabel);
10541099
}
10551100

1101+
public void BeginKeyModification()
1102+
{
1103+
SaveCurveEditorKeySelection();
1104+
1105+
m_State.SaveKeySelection(AnimationWindowState.kEditCurveUndoLabel);
1106+
m_State.ClearKeySelections();
1107+
}
1108+
1109+
public void EndKeyModification()
1110+
{
1111+
UpdateSelectedKeysToCurveEditor();
1112+
}
1113+
10561114
private void HandleCopyPaste()
10571115
{
10581116
if (Event.current.type == EventType.ValidateCommand || Event.current.type == EventType.ExecuteCommand)

Editor/Mono/Animation/AnimationWindow/AnimationContextualPropertyMenu.cs

Lines changed: 114 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class AnimationPropertyContextualMenu
1515
{
1616
public static AnimationPropertyContextualMenu Instance = new AnimationPropertyContextualMenu();
1717

18-
private List<IAnimationContextualResponder> m_Responders = new List<IAnimationContextualResponder>();
18+
IAnimationContextualResponder m_Responder;
1919

2020
private static GUIContent addKeyContent = EditorGUIUtility.TextContent("Add Key");
2121
private static GUIContent updateKeyContent = EditorGUIUtility.TextContent("Update Key");
@@ -29,117 +29,140 @@ internal class AnimationPropertyContextualMenu
2929
public AnimationPropertyContextualMenu()
3030
{
3131
EditorApplication.contextualPropertyMenu += OnPropertyContextMenu;
32+
MaterialEditor.contextualPropertyMenu += OnPropertyContextMenu;
3233
}
3334

34-
public void AddResponder(IAnimationContextualResponder responder)
35+
public void SetResponder(IAnimationContextualResponder responder)
3536
{
36-
m_Responders.Add(responder);
37-
}
38-
39-
public void RemoveResponder(IAnimationContextualResponder responder)
40-
{
41-
m_Responders.Remove(responder);
37+
m_Responder = responder;
4238
}
4339

4440
void OnPropertyContextMenu(GenericMenu menu, SerializedProperty property)
4541
{
46-
if (m_Responders.Count == 0)
42+
if (m_Responder == null)
4743
return;
4844

49-
bool isPropertyAnimatable = m_Responders.Exists(responder => responder.IsAnimatable(property));
45+
PropertyModification[] modifications = AnimationWindowUtility.SerializedPropertyToPropertyModifications(property);
46+
47+
bool isPropertyAnimatable = m_Responder.IsAnimatable(modifications);
5048
if (isPropertyAnimatable)
5149
{
52-
bool isEditable = m_Responders.Exists(responder => responder.IsEditable(property));
53-
bool hasKey = isEditable && m_Responders.Exists(responder => responder.KeyExists(property));
54-
bool hasCandidate = isEditable && m_Responders.Exists(responder => responder.CandidateExists(property));
55-
bool hasCurve = isEditable && (hasKey || m_Responders.Exists(responder => responder.CurveExists(property)));
50+
var targetObject = property.serializedObject.targetObject;
51+
if (m_Responder.IsEditable(targetObject))
52+
OnPropertyContextMenu(menu, modifications);
53+
else
54+
OnDisabledPropertyContextMenu(menu);
55+
}
56+
}
5657

57-
bool hasAnyCandidate = isEditable && m_Responders.Exists(responder => responder.HasAnyCandidates());
58-
bool hasAnyCurve = isEditable && m_Responders.Exists(responder => responder.HasAnyCurves());
58+
void OnPropertyContextMenu(GenericMenu menu, MaterialProperty property, Renderer targetObject)
59+
{
60+
if (m_Responder == null)
61+
return;
5962

60-
// Important to pass a copy, the original can get Next called on it
61-
// before the callback invoked
62-
var propertyCopy = property.Copy();
63+
if (property.targets == null || property.targets.Length == 0)
64+
return;
6365

64-
if (isEditable)
65-
{
66-
menu.AddItem(((hasKey && hasCandidate) ? updateKeyContent : addKeyContent), false, () =>
67-
{
68-
m_Responders.ForEach(responder => responder.AddKey(propertyCopy));
69-
});
70-
}
71-
else
72-
{
73-
menu.AddDisabledItem(addKeyContent);
74-
}
66+
PropertyModification[] modifications = MaterialAnimationUtility.MaterialPropertyToPropertyModifications(property, targetObject);
67+
if (m_Responder.IsEditable(targetObject))
68+
OnPropertyContextMenu(menu, modifications);
69+
else
70+
OnDisabledPropertyContextMenu(menu);
71+
}
7572

76-
if (hasKey)
77-
{
78-
menu.AddItem(removeKeyContent, false, () =>
79-
{
80-
m_Responders.ForEach(responder => responder.RemoveKey(propertyCopy));
81-
});
82-
}
83-
else
84-
{
85-
menu.AddDisabledItem(removeKeyContent);
86-
}
73+
void OnPropertyContextMenu(GenericMenu menu, PropertyModification[] modifications)
74+
{
75+
bool hasKey = m_Responder.KeyExists(modifications);
76+
bool hasCandidate = m_Responder.CandidateExists(modifications);
77+
bool hasCurve = (hasKey || m_Responder.CurveExists(modifications));
8778

88-
if (hasCurve)
89-
{
90-
menu.AddItem(removeCurveContent, false, () =>
91-
{
92-
m_Responders.ForEach(responder => responder.RemoveCurve(propertyCopy));
93-
});
94-
}
95-
else
96-
{
97-
menu.AddDisabledItem(removeCurveContent);
98-
}
79+
bool hasAnyCandidate = m_Responder.HasAnyCandidates();
80+
bool hasAnyCurve = m_Responder.HasAnyCurves();
9981

100-
menu.AddSeparator(string.Empty);
101-
if (hasAnyCandidate)
82+
menu.AddItem(((hasKey && hasCandidate) ? updateKeyContent : addKeyContent), false, () =>
10283
{
103-
menu.AddItem(addCandidatesContent, false, () =>
104-
{
105-
m_Responders.ForEach(responder => responder.AddCandidateKeys());
106-
});
107-
}
108-
else
109-
{
110-
menu.AddDisabledItem(addCandidatesContent);
111-
}
84+
m_Responder.AddKey(modifications);
85+
});
11286

113-
if (hasAnyCurve)
114-
{
115-
menu.AddItem(addAnimatedContent, false, () =>
116-
{
117-
m_Responders.ForEach(responder => responder.AddAnimatedKeys());
118-
});
119-
}
120-
else
121-
{
122-
menu.AddDisabledItem(addAnimatedContent);
123-
}
87+
if (hasKey)
88+
{
89+
menu.AddItem(removeKeyContent, false, () =>
90+
{
91+
m_Responder.RemoveKey(modifications);
92+
});
93+
}
94+
else
95+
{
96+
menu.AddDisabledItem(removeKeyContent);
97+
}
12498

125-
menu.AddSeparator(string.Empty);
126-
if (hasCurve)
127-
{
128-
menu.AddItem(goToPreviousKeyContent, false, () =>
129-
{
130-
m_Responders.ForEach(responder => responder.GoToPreviousKeyframe(propertyCopy));
131-
});
132-
menu.AddItem(goToNextKeyContent, false, () =>
133-
{
134-
m_Responders.ForEach(responder => responder.GoToNextKeyframe(propertyCopy));
135-
});
136-
}
137-
else
138-
{
139-
menu.AddDisabledItem(goToPreviousKeyContent);
140-
menu.AddDisabledItem(goToNextKeyContent);
141-
}
99+
if (hasCurve)
100+
{
101+
menu.AddItem(removeCurveContent, false, () =>
102+
{
103+
m_Responder.RemoveCurve(modifications);
104+
});
105+
}
106+
else
107+
{
108+
menu.AddDisabledItem(removeCurveContent);
109+
}
110+
111+
menu.AddSeparator(string.Empty);
112+
if (hasAnyCandidate)
113+
{
114+
menu.AddItem(addCandidatesContent, false, () =>
115+
{
116+
m_Responder.AddCandidateKeys();
117+
});
118+
}
119+
else
120+
{
121+
menu.AddDisabledItem(addCandidatesContent);
142122
}
123+
124+
if (hasAnyCurve)
125+
{
126+
menu.AddItem(addAnimatedContent, false, () =>
127+
{
128+
m_Responder.AddAnimatedKeys();
129+
});
130+
}
131+
else
132+
{
133+
menu.AddDisabledItem(addAnimatedContent);
134+
}
135+
136+
menu.AddSeparator(string.Empty);
137+
if (hasCurve)
138+
{
139+
menu.AddItem(goToPreviousKeyContent, false, () =>
140+
{
141+
m_Responder.GoToPreviousKeyframe(modifications);
142+
});
143+
menu.AddItem(goToNextKeyContent, false, () =>
144+
{
145+
m_Responder.GoToNextKeyframe(modifications);
146+
});
147+
}
148+
else
149+
{
150+
menu.AddDisabledItem(goToPreviousKeyContent);
151+
menu.AddDisabledItem(goToNextKeyContent);
152+
}
153+
}
154+
155+
void OnDisabledPropertyContextMenu(GenericMenu menu)
156+
{
157+
menu.AddDisabledItem(addKeyContent);
158+
menu.AddDisabledItem(removeKeyContent);
159+
menu.AddDisabledItem(removeCurveContent);
160+
menu.AddSeparator(string.Empty);
161+
menu.AddDisabledItem(addCandidatesContent);
162+
menu.AddDisabledItem(addAnimatedContent);
163+
menu.AddSeparator(string.Empty);
164+
menu.AddDisabledItem(goToPreviousKeyContent);
165+
menu.AddDisabledItem(goToNextKeyContent);
143166
}
144167
}
145168
}

0 commit comments

Comments
 (0)