1
+ using UnityEngine ;
2
+ using UnityEditor ;
3
+ using NUnit . Framework ;
4
+ using System . Collections . Generic ;
5
+
6
+ namespace FbxExporters . UnitTests
7
+ {
8
+ public class MyKeyComparer : IComparer < Keyframe >
9
+ {
10
+ public int Compare ( Keyframe a , Keyframe b )
11
+ {
12
+ Debug . Log ( string . Format ( "a.value: {0}, b.value: {1}, a.time: {2}, b.time: {3}" , a . value , b . value , a . time , b . time ) ) ;
13
+ return a . time == b . time && a . value == b . value ? 0 : 1 ;
14
+ }
15
+ }
16
+
17
+ public class FbxCameraTest : ExporterTestBase
18
+ {
19
+
20
+ [ Test ]
21
+ public void AnimationWithCameraFOVTest ( )
22
+ {
23
+ string filename = GetRandomFbxFilePath ( ) ;
24
+ GameObject go = new GameObject ( ) ;
25
+ go . name = "originalCamera" ;
26
+ Camera camera = go . AddComponent ( typeof ( Camera ) ) as Camera ;
27
+ Animation anim = go . AddComponent ( typeof ( Animation ) ) as Animation ;
28
+
29
+ Keyframe [ ] keys = new Keyframe [ 3 ] ;
30
+ keys [ 0 ] = new Keyframe ( 0.0f , 1f ) ;
31
+ keys [ 1 ] = new Keyframe ( 1.0f , 2f ) ;
32
+ keys [ 2 ] = new Keyframe ( 2.0f , 3f ) ;
33
+
34
+ AnimationCurve curve = new AnimationCurve ( keys ) ;
35
+
36
+ AnimationClip clip = new AnimationClip ( ) ;
37
+
38
+ clip . legacy = true ;
39
+
40
+ clip . SetCurve ( "" , typeof ( Camera ) , "field of view" , curve ) ;
41
+
42
+ anim . AddClip ( clip , "test" ) ;
43
+
44
+ //export the object
45
+ var exported = FbxExporters . Editor . ModelExporter . ExportObject ( filename , go ) ;
46
+
47
+ Assert . That ( exported , Is . EqualTo ( filename ) ) ;
48
+
49
+ // TODO: Uni-34492 change importer settings of (newly exported model)
50
+ // so that it's not resampled and it is legacy animation
51
+ {
52
+ ModelImporter modelImporter = AssetImporter . GetAtPath ( filename ) as ModelImporter ;
53
+ Assert . That ( modelImporter , Is . Not . Null ) ;
54
+ modelImporter . resampleCurves = false ;
55
+ AssetDatabase . ImportAsset ( filename ) ;
56
+ modelImporter . animationType = ModelImporterAnimationType . Legacy ;
57
+ AssetDatabase . ImportAsset ( filename ) ;
58
+ }
59
+
60
+ Object [ ] objects = AssetDatabase . LoadAllAssetsAtPath ( filename ) ;
61
+
62
+ AnimationClip exportedClip = null ;
63
+ foreach ( Object o in objects )
64
+ {
65
+ exportedClip = o as AnimationClip ;
66
+ if ( exportedClip != null ) break ;
67
+ }
68
+
69
+ Assert . IsNotNull ( exportedClip ) ;
70
+ exportedClip . legacy = true ;
71
+
72
+ EditorCurveBinding exportedEditorCurveBinding = AnimationUtility . GetCurveBindings ( exportedClip ) [ 0 ] ;
73
+
74
+ AnimationCurve exportedCurve = AnimationUtility . GetEditorCurve ( exportedClip , exportedEditorCurveBinding ) ;
75
+
76
+ Assert . That ( exportedCurve . keys . Length , Is . EqualTo ( keys . Length ) ) ;
77
+
78
+ //check imported animation against original
79
+ Assert . That ( exportedCurve . keys , Is . EqualTo ( keys ) . Using < Keyframe > ( new MyKeyComparer ( ) ) , string . Format ( "key doesn't match" ) ) ;
80
+ }
81
+
82
+ }
83
+ }
0 commit comments