@@ -21,91 +21,99 @@ public class FbxPrefabAutoUpdaterTest : ExporterTestBase
21
21
[ SetUp ]
22
22
public void Init ( )
23
23
{
24
- var capsule = GameObject . CreatePrimitive ( PrimitiveType . Capsule ) ;
25
- m_fbx = ExportSelection ( capsule ) ;
26
- m_fbxPath = AssetDatabase . GetAssetPath ( m_fbx ) ;
24
+ var capsule = GameObject . CreatePrimitive ( PrimitiveType . Capsule ) ;
25
+ m_fbx = ExportSelection ( capsule ) ;
26
+ m_fbxPath = AssetDatabase . GetAssetPath ( m_fbx ) ;
27
27
28
28
// Instantiate the fbx and create a prefab from it.
29
29
// Delete the object right away (don't even wait for term).
30
- var fbxInstance = PrefabUtility . InstantiatePrefab ( m_fbx ) as GameObject ;
31
- new FbxPrefabAutoUpdater . FbxPrefabUtility ( fbxInstance . AddComponent < FbxPrefab > ( ) ) . SetSourceModel ( m_fbx ) ;
32
- m_prefabPath = GetRandomPrefabAssetPath ( ) ;
33
- m_prefab = PrefabUtility . CreatePrefab ( m_prefabPath , fbxInstance ) ;
30
+ var fbxInstance = PrefabUtility . InstantiatePrefab ( m_fbx ) as GameObject ;
31
+ new FbxPrefabAutoUpdater . FbxPrefabUtility ( fbxInstance . AddComponent < FbxPrefab > ( ) ) . SetSourceModel ( m_fbx ) ;
32
+ m_prefabPath = GetRandomPrefabAssetPath ( ) ;
33
+ m_prefab = PrefabUtility . CreatePrefab ( m_prefabPath , fbxInstance ) ;
34
34
AssetDatabase . Refresh ( ) ;
35
- Assert . AreEqual ( m_prefabPath , AssetDatabase . GetAssetPath ( m_prefab ) ) ;
36
- GameObject . DestroyImmediate ( fbxInstance ) ;
35
+ Assert . AreEqual ( m_prefabPath , AssetDatabase . GetAssetPath ( m_prefab ) ) ;
36
+ GameObject . DestroyImmediate ( fbxInstance ) ;
37
37
}
38
38
39
39
[ Test ]
40
40
public void BasicTest ( )
41
41
{
42
- var fbxPrefabPath = FbxPrefabAutoUpdater . FindFbxPrefabAssetPath ( ) ;
43
- Assert . IsFalse ( string . IsNullOrEmpty ( fbxPrefabPath ) ) ;
44
- Assert . IsTrue ( fbxPrefabPath . EndsWith ( FbxPrefabAutoUpdater . FBX_PREFAB_FILE ) ) ;
42
+ var fbxPrefabPath = FbxPrefabAutoUpdater . FindFbxPrefabAssetPath ( ) ;
43
+ Assert . IsFalse ( string . IsNullOrEmpty ( fbxPrefabPath ) ) ;
44
+ Assert . IsTrue ( fbxPrefabPath . EndsWith ( FbxPrefabAutoUpdater . FBX_PREFAB_FILE ) ) ;
45
45
46
- Assert . IsTrue ( FbxPrefabAutoUpdater . IsFbxAsset ( "Assets/path/to/foo.fbx" ) ) ;
47
- Assert . IsFalse ( FbxPrefabAutoUpdater . IsFbxAsset ( "Assets/path/to/foo.png" ) ) ;
46
+ Assert . IsTrue ( FbxPrefabAutoUpdater . IsFbxAsset ( "Assets/path/to/foo.fbx" ) ) ;
47
+ Assert . IsFalse ( FbxPrefabAutoUpdater . IsFbxAsset ( "Assets/path/to/foo.png" ) ) ;
48
48
49
- Assert . IsTrue ( FbxPrefabAutoUpdater . IsPrefabAsset ( "Assets/path/to/foo.prefab" ) ) ;
50
- Assert . IsFalse ( FbxPrefabAutoUpdater . IsPrefabAsset ( "Assets/path/to/foo.fbx" ) ) ;
51
- Assert . IsFalse ( FbxPrefabAutoUpdater . IsPrefabAsset ( "Assets/path/to/foo.png" ) ) ;
49
+ Assert . IsTrue ( FbxPrefabAutoUpdater . IsPrefabAsset ( "Assets/path/to/foo.prefab" ) ) ;
50
+ Assert . IsFalse ( FbxPrefabAutoUpdater . IsPrefabAsset ( "Assets/path/to/foo.fbx" ) ) ;
51
+ Assert . IsFalse ( FbxPrefabAutoUpdater . IsPrefabAsset ( "Assets/path/to/foo.png" ) ) ;
52
52
53
- var imported = new HashSet < string > ( new string [ ] { "Assets/path/to/foo.fbx" , m_fbxPath } ) ;
54
- Assert . IsTrue ( FbxPrefabAutoUpdater . MayHaveFbxPrefabToFbxAsset ( m_prefabPath , fbxPrefabPath ,
53
+ var imported = new HashSet < string > ( new string [ ] { "Assets/path/to/foo.fbx" , m_fbxPath } ) ;
54
+ Assert . IsTrue ( FbxPrefabAutoUpdater . MayHaveFbxPrefabToFbxAsset ( m_prefabPath , fbxPrefabPath ,
55
55
imported ) ) ;
56
56
}
57
57
58
58
[ Test ]
59
59
public void RectTransformTest ( )
60
60
{
61
- Vector3 scaleForward = new Vector3 ( 1 , 2 , 3 ) ;
62
- Vector3 positionForward = new Vector3 ( 100 , 200 , 300 ) ;
63
- Vector3 rotationForward = new Vector3 ( 1 , 2 , 3 ) ;
61
+ Vector3 scaleForward = new Vector3 ( 1 , 2 , 3 ) ;
62
+ Vector3 positionForward = new Vector3 ( 100 , 200 , 300 ) ;
63
+ Vector3 rotationForward = new Vector3 ( 1 , 2 , 3 ) ;
64
64
65
- Vector3 scaleBackward = new Vector3 ( 3 , 2 , 1 ) ;
66
- Vector3 positionBackward = new Vector3 ( 300 , 200 , 100 ) ;
67
- Vector3 rotationBackward = new Vector3 ( 3 , 2 , 1 ) ;
65
+ Vector3 scaleBackward = new Vector3 ( 3 , 2 , 1 ) ;
66
+ Vector3 positionBackward = new Vector3 ( 300 , 200 , 100 ) ;
67
+ Vector3 rotationBackward = new Vector3 ( 3 , 2 , 1 ) ;
68
68
69
69
//Create a hierarchy with a RectTransform
70
- var cube = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
71
- var capsule = GameObject . CreatePrimitive ( PrimitiveType . Capsule ) ;
72
- capsule . AddComponent < RectTransform > ( ) ;
73
-
74
- capsule . GetComponent < RectTransform > ( ) . localScale = scaleForward ;
75
- capsule . GetComponent < RectTransform > ( ) . localPosition = positionForward ;
76
- capsule . GetComponent < RectTransform > ( ) . localRotation = Quaternion . Euler ( rotationForward ) ;
70
+ var cube = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
71
+ var capsule = GameObject . CreatePrimitive ( PrimitiveType . Capsule ) ;
72
+ capsule . transform . SetParent ( cube . transform ) ;
77
73
78
- capsule . transform . parent = cube . transform ;
74
+ var rectTransform = capsule . AddComponent < RectTransform > ( ) ;
79
75
80
- string filePath = GetRandomFbxFilePath ( ) ;
76
+ rectTransform . localScale = scaleForward ;
77
+ rectTransform . localPosition = positionForward ;
78
+ rectTransform . localRotation = Quaternion . Euler ( rotationForward ) ;
79
+ #if UNITY_2017_3_OR_NEWER
80
+ rectTransform . ForceUpdateRectTransforms ( ) ;
81
+ #endif
81
82
82
- //instantiate our hierarchy as a prefab
83
- var oldInstance = ConvertToModel . Convert ( cube , fbxFullPath : filePath ) ;
84
- Assert . IsTrue ( oldInstance ) ;
85
-
86
- Assert . IsTrue ( oldInstance . transform . GetChild ( 0 ) . GetComponent < RectTransform > ( ) . localScale == scaleForward ) ;
87
- Assert . IsTrue ( oldInstance . transform . GetChild ( 0 ) . GetComponent < RectTransform > ( ) . localPosition == positionForward ) ;
88
- Assert . IsTrue ( oldInstance . transform . GetChild ( 0 ) . GetComponent < RectTransform > ( ) . localRotation == Quaternion . Euler ( rotationForward ) ) ;
83
+ string filePath1 = GetRandomFbxFilePath ( ) ;
89
84
90
- //Create an "updated" hierarchy
91
- var cube2 = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
92
- var capsule2 = GameObject . CreatePrimitive ( PrimitiveType . Capsule ) ;
93
- capsule2 . AddComponent < RectTransform > ( ) ;
85
+ //instantiate our hierarchy as a prefab
86
+ var oldInstance = ConvertToModel . Convert ( cube , fbxFullPath : filePath1 ) ;
87
+ Assert . IsTrue ( oldInstance ) ;
94
88
95
- capsule2 . GetComponent < RectTransform > ( ) . localScale = scaleBackward ;
96
- capsule2 . GetComponent < RectTransform > ( ) . localPosition = positionBackward ;
97
- capsule2 . GetComponent < RectTransform > ( ) . localRotation = Quaternion . Euler ( rotationBackward ) ;
89
+ rectTransform = oldInstance . transform . GetChild ( 0 ) . GetComponent < RectTransform > ( ) ;
98
90
99
- capsule2 . transform . parent = cube2 . transform ;
91
+ Assert . IsTrue ( rectTransform . localScale == scaleForward ) ;
92
+ Assert . IsTrue ( rectTransform . localPosition == positionForward ) ;
93
+ Assert . IsTrue ( rectTransform . localRotation == Quaternion . Euler ( rotationForward ) ) ;
100
94
95
+ //Create an "updated" hierarchy
96
+ var cube2 = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
97
+ var capsule2 = GameObject . CreatePrimitive ( PrimitiveType . Capsule ) ;
98
+ capsule2 . transform . SetParent ( cube2 . transform ) ;
99
+
100
+ rectTransform = capsule2 . AddComponent < RectTransform > ( ) ;
101
+
102
+ rectTransform . localScale = scaleBackward ;
103
+ rectTransform . localPosition = positionBackward ;
104
+ rectTransform . localRotation = Quaternion . Euler ( rotationBackward ) ;
105
+ #if UNITY_2017_3_OR_NEWER
106
+ rectTransform . ForceUpdateRectTransforms ( ) ;
107
+ #endif
101
108
//export our updated hierarchy to the same file path as the original
102
109
SleepForFileTimestamp ( ) ;
103
- FbxExporters . Editor . ModelExporter . ExportObject ( filePath , cube2 ) ;
110
+ FbxExporters . Editor . ModelExporter . ExportObject ( filePath1 , cube2 ) ;
104
111
AssetDatabase . Refresh ( ) ;
105
112
106
- Assert . IsTrue ( oldInstance . transform . GetChild ( 0 ) . GetComponent < RectTransform > ( ) . localScale == scaleBackward ) ;
107
- Assert . IsTrue ( oldInstance . transform . GetChild ( 0 ) . GetComponent < RectTransform > ( ) . localPosition == positionBackward ) ;
108
- Assert . IsTrue ( oldInstance . transform . GetChild ( 0 ) . GetComponent < RectTransform > ( ) . localRotation == Quaternion . Euler ( rotationBackward ) ) ;
113
+ rectTransform = oldInstance . transform . GetChild ( 0 ) . GetComponent < RectTransform > ( ) ;
114
+ Assert . IsTrue ( rectTransform . localScale == scaleBackward ) ;
115
+ Assert . IsTrue ( rectTransform . localPosition == positionBackward ) ;
116
+ Assert . IsTrue ( rectTransform . localRotation == Quaternion . Euler ( rotationBackward ) ) ;
109
117
110
118
GameObject . DestroyImmediate ( cube ) ;
111
119
GameObject . DestroyImmediate ( cube2 ) ;
0 commit comments