Skip to content

Commit 8934722

Browse files
author
David Lassonde
committed
Fixed obsolete API calls
1 parent e43ccfe commit 8934722

File tree

5 files changed

+61
-15
lines changed

5 files changed

+61
-15
lines changed

Assets/com.unity.formats.fbx.tests/FbxAnimationTest.cs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ public virtual int Compare(Keyframe a, Keyframe b)
305305

306306
public class KeyTangentComparer : IComparer<Keyframe>
307307
{
308+
AnimationCurve curveA = null;
309+
AnimationCurve curveB = null;
310+
Dictionary<Keyframe,int> keyFrameToIndexA;
311+
Dictionary<Keyframe,int> keyFrameToIndexB;
312+
308313
public int CompareKeyTangents(Keyframe a, Keyframe b)
309314
{
310315
bool result = true;
@@ -313,21 +318,55 @@ public int CompareKeyTangents(Keyframe a, Keyframe b)
313318
#if DEBUG_UNITTEST
314319
Debug.Log(string.Format("{2} a.time: {0}, b.time: {1}", a.time, b.time,result));
315320
#endif
316-
// TODO : use AnimationUtility.GetLeftTangentMode
317-
// requires reference to AnimationCurve and keyindex
318-
result &= (a.tangentMode == b.tangentMode);
321+
322+
result &= (AnimationUtility.GetKeyLeftTangentMode(curveA,keyFrameToIndexA[a]) == AnimationUtility.GetKeyLeftTangentMode(curveB,keyFrameToIndexB[b]));
323+
result &= (AnimationUtility.GetKeyRightTangentMode(curveA,keyFrameToIndexA[a]) == AnimationUtility.GetKeyRightTangentMode(curveB,keyFrameToIndexB[b]));
319324
#if DEBUG_UNITTEST
320-
Debug.Log(string.Format("{2} a.tangentMode={0} b.tangentMode={1}",
321-
((AnimationUtility.TangentMode)a.tangentMode).ToString(),
322-
((AnimationUtility.TangentMode)b.tangentMode).ToString(),result));
325+
Debug.Log(string.Format("comparison result = {0}\n" +
326+
"keyframe a left tangent mode = {1}\n" +
327+
"keyframe b left tangent mode = {2}\n" +
328+
"keyframe a right tangent mode = {3}\n" +
329+
"keyframe b right tangent mode = {4}\n",
330+
result,
331+
((AnimationUtility.TangentMode) AnimationUtility.GetKeyLeftTangentMode(curveA,keyFrameToIndexA[a])).ToString(),
332+
((AnimationUtility.TangentMode) AnimationUtility.GetKeyLeftTangentMode(curveB,keyFrameToIndexB[b])).ToString(),
333+
((AnimationUtility.TangentMode) AnimationUtility.GetKeyRightTangentMode(curveA,keyFrameToIndexA[a])).ToString(),
334+
((AnimationUtility.TangentMode) AnimationUtility.GetKeyRightTangentMode(curveB,keyFrameToIndexB[b])).ToString()));
323335
#endif
324336
return result ? 0 : 1;
325337
}
326338

327339
public int Compare(Keyframe a, Keyframe b)
328340
{
341+
if (curveA == null || curveB == null)
342+
{
343+
#if DEBUG_UNITTEST
344+
Debug.Log(string.Format("The animation curves were not set for this KeyTangentComparer});
345+
#endif
346+
347+
return 1;
348+
}
329349
return CompareKeyTangents(a,b);
330350
}
351+
352+
public void SetAnimationCurves(AnimationCurve a, AnimationCurve b)
353+
{
354+
curveA = a;
355+
curveB = b;
356+
357+
// Keep a dictionary of Keyframe->index for both curves
358+
keyFrameToIndexA = new Dictionary<Keyframe,int>();
359+
foreach (int index in Enumerable.Range(0,a.keys.Length))
360+
{
361+
keyFrameToIndexA[a.keys[index]] = index;
362+
}
363+
364+
keyFrameToIndexB = new Dictionary<Keyframe,int>();
365+
foreach (int index in Enumerable.Range(0,b.keys.Length))
366+
{
367+
keyFrameToIndexB[b.keys[index]] = index;
368+
}
369+
}
331370
}
332371

333372
public class AnimTester
@@ -552,6 +591,13 @@ public static void KeysTest (AnimationCurve expectedAnimCurve, AnimationCurve ac
552591
Assert.That (actualAnimCurve.length, Is.EqualTo(expectedAnimCurve.length), string.Format("{0} number of keys doesn't match", message));
553592

554593
Assert.That(actualAnimCurve.keys, Is.EqualTo(expectedAnimCurve.keys).Using<Keyframe>(keyComparer), string.Format("{0} key doesn't match", message));
594+
595+
// Setup our tangent comparer if it is the one we are using
596+
var tangentComparer = keyComparer as KeyTangentComparer;
597+
if (tangentComparer != null)
598+
{
599+
tangentComparer.SetAnimationCurves(actualAnimCurve, expectedAnimCurve);
600+
}
555601
}
556602

557603
public static void KeysTest (float [] expectedKeyTimes, float [] expectedKeyValues, AnimationCurve actualAnimCurve, string message, IComparer<Keyframe> keyComparer=null)

Packages/com.unity.formats.fbx/Editor/Scripts/ConvertToModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public static GameObject ApplyOrCreatePrefab(GameObject instance,
316316
string prefabFullPath = null)
317317
{
318318
if(PrefabUtility.GetPrefabType(instance) == PrefabType.PrefabInstance) {
319-
return PrefabUtility.ReplacePrefab(instance, PrefabUtility.GetPrefabParent(instance));
319+
return PrefabUtility.ReplacePrefab(instance, PrefabUtility.GetCorrespondingObjectFromSource(instance));
320320
}
321321

322322
// Otherwise, create a new prefab. First choose its filename/path.
@@ -388,7 +388,7 @@ public static GameObject GetFbxAssetOrNull(GameObject go) {
388388
switch(unityPrefabType) {
389389
case PrefabType.ModelPrefabInstance:
390390
if (go.Equals(PrefabUtility.FindPrefabRoot (go))) {
391-
return PrefabUtility.GetPrefabParent(go) as GameObject;
391+
return PrefabUtility.GetCorrespondingObjectFromSource(go) as GameObject;
392392
} else {
393393
return null;
394394
}

Packages/com.unity.formats.fbx/Editor/Scripts/FbxExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ protected bool ExportInstance (GameObject unityGo, FbxNode fbxNode, FbxScene fbx
12881288
if (unityPrefabType != PrefabType.PrefabInstance &&
12891289
unityPrefabType != PrefabType.ModelPrefabInstance) return false;
12901290

1291-
Object unityPrefabParent = PrefabUtility.GetPrefabParent (unityGo);
1291+
Object unityPrefabParent = PrefabUtility.GetCorrespondingObjectFromSource(unityGo);
12921292

12931293
if (Verbose)
12941294
Debug.Log (string.Format ("exporting instance {0}({1})", unityGo.name, unityPrefabParent.name));

Packages/com.unity.formats.fbx/Editor/Scripts/FbxPrefabAutoUpdater.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public static bool OnValidateMenuItem()
257257
bool containsLinkedPrefab = false;
258258
foreach (GameObject selectedObject in selection)
259259
{
260-
GameObject prefab = UnityEditor.PrefabUtility.GetPrefabParent(selectedObject) as GameObject;
260+
GameObject prefab = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(selectedObject) as GameObject;
261261
if (prefab && prefab.GetComponentInChildren<FbxPrefab>())
262262
{
263263
containsLinkedPrefab = true;
@@ -281,7 +281,7 @@ public static void UpdateLinkedPrefab(GameObject prefabOrInstance)
281281
prefab = prefabOrInstance;
282282
break;
283283
case PrefabType.PrefabInstance:
284-
prefab = PrefabUtility.GetPrefabParent(prefabOrInstance) as GameObject;
284+
prefab = PrefabUtility.GetCorrespondingObjectFromSource(prefabOrInstance) as GameObject;
285285
break;
286286
default:
287287
return;
@@ -1407,7 +1407,7 @@ void CompareAndUpdate()
14071407
m_fbxPrefab.gameObject));
14081408
}
14091409
var fbxPrefabInstance = prefabInstanceRoot.GetComponentsInChildren<FbxPrefab>().FirstOrDefault(
1410-
fbxPrefab => UnityEditor.PrefabUtility.GetPrefabParent(fbxPrefab) == m_fbxPrefab);
1410+
fbxPrefab => UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(fbxPrefab) == m_fbxPrefab);
14111411
if (!fbxPrefabInstance) {
14121412
throw new System.Exception(string.Format("Internal error: couldn't find the right FbxPrefab after instantiating."));
14131413
}

Packages/com.unity.formats.fbx/Editor/Scripts/ReviewLastSavedModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public static UnityEditor.EditorWindow GetMainGameView()
300300
private static void SubscribeToEvents ()
301301
{
302302
// ensure we only subscribe once
303-
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
304-
UnityEditor.EditorApplication.hierarchyWindowChanged += UpdateLastSavedModel;
303+
UnityEditor.EditorApplication.hierarchyChanged -= UpdateLastSavedModel;
304+
UnityEditor.EditorApplication.hierarchyChanged += UpdateLastSavedModel;
305305
}
306306

307307
private static void UnsubscribeFromEvents ()
@@ -311,7 +311,7 @@ private static void UnsubscribeFromEvents ()
311311
LastModel = null;
312312
LastFilePath = null;
313313

314-
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
314+
UnityEditor.EditorApplication.hierarchyChanged -= UpdateLastSavedModel;
315315
}
316316

317317
private static bool AutoUpdateEnabled ()

0 commit comments

Comments
 (0)