Skip to content

Commit 8c06031

Browse files
author
Unity Technologies
committed
Unity 2018.3.0a2 C# reference source code
1 parent 84af4f4 commit 8c06031

111 files changed

Lines changed: 3291 additions & 917 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/AnimationUtility.bindings.cs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,37 +190,46 @@ public static Type PropertyModificationToEditorCurveBinding(PropertyModification
190190
extern public static EditorCurveBinding[] GetObjectReferenceCurveBindings([NotNull] AnimationClip clip);
191191

192192
extern public static ObjectReferenceKeyframe[] GetObjectReferenceCurve([NotNull] AnimationClip clip, EditorCurveBinding binding);
193-
extern public static void SetObjectReferenceCurve([NotNull] AnimationClip clip, EditorCurveBinding binding, ObjectReferenceKeyframe[] keyframes);
194193

195-
extern public static AnimationCurve GetEditorCurve([NotNull] AnimationClip clip, EditorCurveBinding binding);
196-
extern public static void SetEditorCurve([NotNull] AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve);
194+
public static void SetObjectReferenceCurve(AnimationClip clip, EditorCurveBinding binding, ObjectReferenceKeyframe[] keyframes)
195+
{
196+
Internal_SetObjectReferenceCurve(clip, binding, keyframes, true);
197+
Internal_InvokeOnCurveWasModified(clip, binding, keyframes != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);
198+
}
197199

198-
// Todo. Should be converted to c++.
199-
internal static void SetEditorCurves(AnimationClip clip, EditorCurveBinding[] bindings, AnimationCurve[] curves)
200+
internal static void SetObjectReferenceCurveNoSync(AnimationClip clip, EditorCurveBinding binding, ObjectReferenceKeyframe[] keyframes)
200201
{
201-
if (clip == null)
202-
throw new ArgumentNullException("clip");
203-
if (curves == null)
204-
throw new ArgumentNullException("curves");
205-
if (bindings == null)
206-
throw new ArgumentNullException("bindings");
202+
Internal_SetObjectReferenceCurve(clip, binding, keyframes, false);
203+
Internal_InvokeOnCurveWasModified(clip, binding, keyframes != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);
204+
}
207205

208-
if (bindings.Length != curves.Length)
209-
throw new ArgumentException("bindings and curves array sizes do not match");
206+
extern private static void Internal_SetObjectReferenceCurve([NotNull] AnimationClip clip, EditorCurveBinding binding, ObjectReferenceKeyframe[] keyframes, bool updateMuscleClip);
210207

211-
for (int i = 0; i < bindings.Length; ++i)
212-
{
213-
Internal_SetEditorCurve(clip, bindings[i], curves[i], false);
208+
extern public static AnimationCurve GetEditorCurve([NotNull] AnimationClip clip, EditorCurveBinding binding);
214209

215-
if (onCurveWasModified != null)
216-
onCurveWasModified(clip, bindings[i], curves[i] != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);
217-
}
210+
public static void SetEditorCurve(AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve)
211+
{
212+
Internal_SetEditorCurve(clip, binding, curve, true);
213+
Internal_InvokeOnCurveWasModified(clip, binding, curve != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);
214+
}
218215

219-
Internal_SyncEditorCurves(clip);
216+
internal static void SetEditorCurveNoSync(AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve)
217+
{
218+
Internal_SetEditorCurve(clip, binding, curve, false);
219+
Internal_InvokeOnCurveWasModified(clip, binding, curve != null ? CurveModifiedType.CurveModified : CurveModifiedType.CurveDeleted);
220220
}
221221

222-
extern private static void Internal_SetEditorCurve(AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve, bool syncEditorCurve);
223-
extern private static void Internal_SyncEditorCurves(AnimationClip clip);
222+
extern private static void Internal_SetEditorCurve([NotNull] AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve, bool syncEditorCurves);
223+
224+
extern internal static void SyncEditorCurves([NotNull] AnimationClip clip);
225+
226+
private static void Internal_InvokeOnCurveWasModified(AnimationClip clip, EditorCurveBinding binding, CurveModifiedType type)
227+
{
228+
if (onCurveWasModified != null)
229+
{
230+
onCurveWasModified(clip, binding, type);
231+
}
232+
}
224233

225234
[NativeThrows]
226235
extern internal static void UpdateTangentsFromModeSurrounding([NotNull] AnimationCurve curve, int index);

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ private void SaveChangedCurvesFromCurveEditor()
10371037
foreach (var kvp in curvesToUpdate)
10381038
{
10391039
Undo.RegisterCompleteObjectUndo(kvp.Key, AnimationWindowState.kEditCurveUndoLabel);
1040-
AnimationUtility.SetEditorCurves(kvp.Key, kvp.Value.bindings.ToArray(), kvp.Value.curves.ToArray());
1040+
AnimationWindowUtility.SaveCurves(kvp.Key, kvp.Value.bindings, kvp.Value.curves);
10411041
}
10421042

10431043
m_State.ResampleAnimation();

Editor/Mono/Animation/AnimationWindow/AnimationRecording.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -783,31 +783,5 @@ static void ProcessAnimatorModification(IAnimationRecordingState state, Animator
783783

784784
state.SaveCurve(curve);
785785
}
786-
787-
static public void SaveModifiedCurve(AnimationWindowCurve curve, AnimationClip clip)
788-
{
789-
curve.m_Keyframes.Sort((a, b) => a.time.CompareTo(b.time));
790-
791-
if (curve.isPPtrCurve)
792-
{
793-
ObjectReferenceKeyframe[] objectCurve = curve.ToObjectCurve();
794-
795-
if (objectCurve.Length == 0)
796-
objectCurve = null;
797-
798-
AnimationUtility.SetObjectReferenceCurve(clip, curve.binding, objectCurve);
799-
}
800-
else
801-
{
802-
AnimationCurve animationCurve = curve.ToAnimationCurve();
803-
804-
if (animationCurve.keys.Length == 0)
805-
animationCurve = null;
806-
else
807-
QuaternionCurveTangentCalculation.UpdateTangentsFromMode(animationCurve, clip, curve.binding);
808-
809-
AnimationUtility.SetEditorCurve(clip, curve.binding, animationCurve);
810-
}
811-
}
812786
}
813787
}

Editor/Mono/Animation/AnimationWindow/AnimationWindowControl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public bool DiscardModification(PropertyModification modification)
3737
public void SaveCurve(AnimationWindowCurve curve)
3838
{
3939
Undo.RegisterCompleteObjectUndo(curve.clip, "Edit Candidate Curve");
40-
AnimationRecording.SaveModifiedCurve(curve, curve.clip);
40+
AnimationWindowUtility.SaveCurve(curve.clip, curve);
4141
}
4242

4343
public void AddPropertyModification(EditorCurveBinding binding, PropertyModification propertyModification, bool keepPrefabOverride)
@@ -78,7 +78,7 @@ public bool DiscardModification(PropertyModification modification)
7878

7979
public void SaveCurve(AnimationWindowCurve curve)
8080
{
81-
m_State.SaveCurve(curve);
81+
m_State.SaveCurve(curve.clip, curve);
8282
}
8383

8484
public void AddPropertyModification(EditorCurveBinding binding, PropertyModification propertyModification, bool keepPrefabOverride)
@@ -613,7 +613,7 @@ public override void ProcessCandidates()
613613
curves.Add(curve);
614614
}
615615

616-
AnimationWindowUtility.AddKeyframes(state, curves.ToArray(), time);
616+
AnimationWindowUtility.AddKeyframes(state, curves, time);
617617

618618
EndKeyModification();
619619

@@ -824,7 +824,7 @@ public void AddAnimatedKeys()
824824
{
825825
BeginKeyModification();
826826

827-
AnimationWindowUtility.AddKeyframes(state, state.allCurves.ToArray(), time);
827+
AnimationWindowUtility.AddKeyframes(state, state.allCurves, time);
828828
ClearCandidates();
829829

830830
EndKeyModification();

Editor/Mono/Animation/AnimationWindow/AnimationWindowHierarchyGUI.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
394394
else
395395
existingKeyframe.value = value;
396396

397-
state.SaveCurve(curve, undoLabel);
397+
state.SaveCurve(curve.clip, curve, undoLabel);
398398
curvesChanged = true;
399399
}
400400
}
@@ -610,13 +610,13 @@ private GenericMenu GenerateMenu(List<AnimationWindowHierarchyNode> interactedNo
610610
private void AddKeysAtCurrentTime(object obj) { AddKeysAtCurrentTime((List<AnimationWindowCurve>)obj); }
611611
private void AddKeysAtCurrentTime(List<AnimationWindowCurve> curves)
612612
{
613-
AnimationWindowUtility.AddKeyframes(state, curves.ToArray(), state.time);
613+
AnimationWindowUtility.AddKeyframes(state, curves, state.time);
614614
}
615615

616616
private void DeleteKeysAtCurrentTime(object obj) { DeleteKeysAtCurrentTime((List<AnimationWindowCurve>)obj); }
617617
private void DeleteKeysAtCurrentTime(List<AnimationWindowCurve> curves)
618618
{
619-
AnimationWindowUtility.RemoveKeyframes(state, curves.ToArray(), state.time);
619+
AnimationWindowUtility.RemoveKeyframes(state, curves, state.time);
620620
}
621621

622622
private void ChangeRotationInterpolation(System.Object interpolationMode)

Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,28 @@ public void SaveKeySelection(string undoLabel)
407407
Undo.RegisterCompleteObjectUndo(m_KeySelection, undoLabel);
408408
}
409409

410-
public void SaveCurve(AnimationWindowCurve curve)
410+
public void SaveCurve(AnimationClip clip, AnimationWindowCurve curve)
411411
{
412-
SaveCurve(curve, kEditCurveUndoLabel);
412+
SaveCurve(clip, curve, kEditCurveUndoLabel);
413413
}
414414

415-
public void SaveCurve(AnimationWindowCurve curve, string undoLabel)
415+
public void SaveCurve(AnimationClip clip, AnimationWindowCurve curve, string undoLabel)
416416
{
417417
if (!curve.animationIsEditable)
418418
Debug.LogError("Curve is not editable and shouldn't be saved.");
419419

420-
Undo.RegisterCompleteObjectUndo(curve.clip, undoLabel);
421-
AnimationRecording.SaveModifiedCurve(curve, curve.clip);
420+
Undo.RegisterCompleteObjectUndo(clip, undoLabel);
421+
AnimationWindowUtility.SaveCurve(clip, curve);
422+
Repaint();
423+
}
424+
425+
public void SaveCurves(AnimationClip clip, ICollection<AnimationWindowCurve> curves, string undoLabel)
426+
{
427+
if (curves.Count == 0)
428+
return;
429+
430+
Undo.RegisterCompleteObjectUndo(clip, undoLabel);
431+
AnimationWindowUtility.SaveCurves(clip, curves);
422432
Repaint();
423433
}
424434

@@ -457,8 +467,7 @@ private void SaveSelectedKeys(string undoLabel)
457467
}
458468
}
459469

460-
foreach (AnimationWindowCurve curve in saveCurves)
461-
SaveCurve(curve, undoLabel);
470+
SaveCurves(activeAnimationClip, saveCurves, undoLabel);
462471
}
463472

464473
public void RemoveCurve(AnimationWindowCurve curve, string undoLabel)
@@ -812,18 +821,21 @@ public void DeleteKeys(List<AnimationWindowKeyframe> keys)
812821
{
813822
SaveKeySelection(kEditCurveUndoLabel);
814823

824+
HashSet<AnimationWindowCurve> curves = new HashSet<AnimationWindowCurve>();
825+
815826
foreach (AnimationWindowKeyframe keyframe in keys)
816827
{
817828
if (!keyframe.curve.animationIsEditable)
818829
continue;
819830

831+
curves.Add(keyframe.curve);
832+
820833
UnselectKey(keyframe);
821834
keyframe.curve.m_Keyframes.Remove(keyframe);
822-
823-
// TODO: optimize by not saving curve for each keyframe
824-
SaveCurve(keyframe.curve, kEditCurveUndoLabel);
825835
}
826836

837+
SaveCurves(activeAnimationClip, curves, kEditCurveUndoLabel);
838+
827839
ResampleAnimation();
828840
}
829841

@@ -1150,7 +1162,7 @@ public void PasteKeys()
11501162
newKeyframe.curve.m_Keyframes.Add(newKeyframe);
11511163
SelectKey(newKeyframe);
11521164
// TODO: Optimize to only save curve once instead once per keyframe
1153-
SaveCurve(newKeyframe.curve, kEditCurveUndoLabel);
1165+
SaveCurve(newKeyframe.curve.clip, newKeyframe.curve, kEditCurveUndoLabel);
11541166

11551167
lastTargetCurve = newKeyframe.curve;
11561168
lastTime = newKeyframe.time;
@@ -1362,6 +1374,19 @@ public void SelectHierarchyItem(int hierarchyNodeID, bool additive, bool trigger
13621374
HandleHierarchySelectionChanged(selectedInstanceIDs, triggerSceneSelectionSync);
13631375
}
13641376

1377+
public void SelectHierarchyItems(IEnumerable<int> hierarchyNodeIDs, bool additive, bool triggerSceneSelectionSync)
1378+
{
1379+
if (!additive)
1380+
ClearHierarchySelection();
1381+
1382+
hierarchyState.selectedIDs.AddRange(hierarchyNodeIDs);
1383+
1384+
int[] selectedInstanceIDs = hierarchyState.selectedIDs.ToArray();
1385+
1386+
// We need to manually trigger this event, because injecting data to m_SelectedInstanceIDs directly doesn't trigger one via TreeView
1387+
HandleHierarchySelectionChanged(selectedInstanceIDs, triggerSceneSelectionSync);
1388+
}
1389+
13651390
public void UnSelectHierarchyItem(DopeLine dopeline)
13661391
{
13671392
UnSelectHierarchyItem(dopeline.hierarchyNodeID);
@@ -1383,13 +1408,21 @@ public bool HasHierarchySelection()
13831408
return true;
13841409
}
13851410

1386-
public List<int> GetAffectedHierarchyIDs(List<AnimationWindowKeyframe> keyframes)
1411+
public HashSet<int> GetAffectedHierarchyIDs(List<AnimationWindowKeyframe> keyframes)
13871412
{
1388-
List<int> hierarchyIDs = new List<int>();
1413+
HashSet<int> hierarchyIDs = new HashSet<int>();
13891414

1390-
foreach (DopeLine dopeline in GetAffectedDopelines(keyframes))
1391-
if (!hierarchyIDs.Contains(dopeline.hierarchyNodeID))
1392-
hierarchyIDs.Add(dopeline.hierarchyNodeID);
1415+
foreach (AnimationWindowKeyframe keyframe in keyframes)
1416+
{
1417+
var curve = keyframe.curve;
1418+
1419+
int hierarchyID = AnimationWindowUtility.GetPropertyNodeID(0, curve.path, curve.type, curve.propertyName);
1420+
if (hierarchyIDs.Add(hierarchyID))
1421+
{
1422+
string propertyGroupName = AnimationWindowUtility.GetPropertyGroupName(curve.propertyName);
1423+
hierarchyIDs.Add(AnimationWindowUtility.GetPropertyNodeID(0, curve.path, curve.type, propertyGroupName));
1424+
}
1425+
}
13931426

13941427
return hierarchyIDs;
13951428
}
@@ -1438,7 +1471,7 @@ private void SyncSceneSelection(int[] selectedNodeIDs)
14381471
if (rootGameObject == null)
14391472
return;
14401473

1441-
List<int> selectedGameObjectIDs = new List<int>();
1474+
List<int> selectedGameObjectIDs = new List<int>(selectedNodeIDs.Length);
14421475
foreach (var selectedNodeID in selectedNodeIDs)
14431476
{
14441477
AnimationWindowHierarchyNode node = hierarchyData.FindItem(selectedNodeID) as AnimationWindowHierarchyNode;
@@ -1491,9 +1524,10 @@ public float clipFrameRate
14911524
int frame = AnimationKeyTime.Time(key.time, clipFrameRate).frame;
14921525
key.time = AnimationKeyTime.Frame(frame, value).time;
14931526
}
1494-
SaveCurve(curve, kEditCurveUndoLabel);
14951527
}
14961528

1529+
SaveCurves(activeAnimationClip, allCurves, kEditCurveUndoLabel);
1530+
14971531
AnimationEvent[] events = AnimationUtility.GetAnimationEvents(activeAnimationClip);
14981532
foreach (AnimationEvent ev in events)
14991533
{

0 commit comments

Comments
 (0)