@@ -16,13 +16,13 @@ namespace FbxExporters.UnitTests
16
16
public class DefaultSelectionTest : ExporterTestBase
17
17
{
18
18
protected GameObject m_root ;
19
- protected bool m_centerObjectsSetting ;
19
+ protected bool m_centerObjectsSetting ;
20
20
21
- [ SetUp ]
22
- public void Init ( )
23
- {
24
- m_centerObjectsSetting = FbxExporters . EditorTools . ExportSettings . instance . centerObjects ;
25
- }
21
+ [ SetUp ]
22
+ public void Init ( )
23
+ {
24
+ m_centerObjectsSetting = FbxExporters . EditorTools . ExportSettings . instance . centerObjects ;
25
+ }
26
26
27
27
[ TearDown ]
28
28
public override void Term ( )
@@ -31,8 +31,8 @@ public override void Term ()
31
31
if ( m_root ) {
32
32
UnityEngine . Object . DestroyImmediate ( m_root ) ;
33
33
}
34
- // restore original setting
35
- FbxExporters . EditorTools . ExportSettings . instance . centerObjects = m_centerObjectsSetting ;
34
+ // restore original setting
35
+ FbxExporters . EditorTools . ExportSettings . instance . centerObjects = m_centerObjectsSetting ;
36
36
}
37
37
38
38
[ Test ]
@@ -53,65 +53,65 @@ public void TestDefaultSelection ()
53
53
// - if there are multiple root GameObjects, export
54
54
// the global transform of root GameObjects, and local transform
55
55
// of descendants.
56
- // if Center Objects is checked in the preferences,
57
- // then export the translations so they are centered
58
- // around the center of the union of the bounding boxes.
56
+ // if Center Objects is checked in the preferences,
57
+ // then export the translations so they are centered
58
+ // around the center of the union of the bounding boxes.
59
59
60
60
m_root = CreateHierarchy ( ) ;
61
61
Assert . IsNotNull ( m_root ) ;
62
62
63
63
// test Export Root
64
64
// Expected result: everything gets exported
65
65
// Expected transform: root is zeroed out, all other transforms unchanged
66
- var exportedRoot = ExportSelection ( new Object [ ] { m_root } ) ;
67
- CompareHierarchies ( m_root , exportedRoot , true , false ) ;
66
+ var exportedRoot = ExportSelection ( new Object [ ] { m_root } ) ;
67
+ CompareHierarchies ( m_root , exportedRoot , true , false ) ;
68
68
CompareGlobalTransform ( exportedRoot . transform ) ;
69
69
70
70
// test Export Parent1, Child1
71
71
// Expected result: Parent1, Child1, Child2
72
72
// Expected transform: Parent1 zeroed out, all other transforms unchanged
73
- var parent1 = m_root . transform . Find ( "Parent1" ) ;
73
+ var parent1 = m_root . transform . Find ( "Parent1" ) ;
74
74
var child1 = parent1 . Find ( "Child1" ) ;
75
- exportedRoot = ExportSelection ( new Object [ ] { parent1 . gameObject , child1 . gameObject } ) ;
76
- CompareHierarchies ( parent1 . gameObject , exportedRoot , true , false ) ;
75
+ exportedRoot = ExportSelection ( new Object [ ] { parent1 . gameObject , child1 . gameObject } ) ;
76
+ CompareHierarchies ( parent1 . gameObject , exportedRoot , true , false ) ;
77
77
CompareGlobalTransform ( exportedRoot . transform ) ;
78
78
79
79
// test Export Child2
80
80
// Expected result: Child2
81
81
// Expected transform: Child2 zeroed out
82
- var child2 = parent1 . Find ( "Child2" ) . gameObject ;
83
- exportedRoot = ExportSelection ( new Object [ ] { child2 } ) ;
84
- CompareHierarchies ( child2 , exportedRoot , true , false ) ;
82
+ var child2 = parent1 . Find ( "Child2" ) . gameObject ;
83
+ exportedRoot = ExportSelection ( new Object [ ] { child2 } ) ;
84
+ CompareHierarchies ( child2 , exportedRoot , true , false ) ;
85
85
CompareGlobalTransform ( exportedRoot . transform ) ;
86
86
87
87
// test Export Child2, Parent2
88
88
// Expected result: Parent2, Child3, Child2
89
89
// Expected transform: Child2 and Parent2 maintain global transform
90
- var parent2 = m_root . transform . Find ( "Parent2" ) ;
91
- var exportSet = new Object [ ] { child2 , parent2 } ;
92
- // for passing to FindCenter()
93
- var goExportSet = new GameObject [ ] { child2 . gameObject , parent2 . gameObject } ;
90
+ var parent2 = m_root . transform . Find ( "Parent2" ) ;
91
+ var exportSet = new Object [ ] { child2 , parent2 } ;
92
+ // for passing to FindCenter()
93
+ var goExportSet = new GameObject [ ] { child2 . gameObject , parent2 . gameObject } ;
94
94
95
- // test without centering objects
96
- FbxExporters . EditorTools . ExportSettings . instance . centerObjects = false ;
95
+ // test without centering objects
96
+ FbxExporters . EditorTools . ExportSettings . instance . centerObjects = false ;
97
97
98
- exportedRoot = ExportSelection ( exportSet ) ;
98
+ exportedRoot = ExportSelection ( exportSet ) ;
99
99
List < GameObject > children = new List < GameObject > ( ) ;
100
100
foreach ( Transform child in exportedRoot . transform ) {
101
101
children . Add ( child . gameObject ) ;
102
102
}
103
- CompareHierarchies ( new GameObject [ ] { child2 , parent2 . gameObject } , children . ToArray ( ) ) ;
103
+ CompareHierarchies ( new GameObject [ ] { child2 , parent2 . gameObject } , children . ToArray ( ) ) ;
104
104
105
- // test with centered objects
106
- FbxExporters . EditorTools . ExportSettings . instance . centerObjects = true ;
107
- var newCenter = FbxExporters . Editor . ModelExporter . FindCenter ( goExportSet ) ;
105
+ // test with centered objects
106
+ FbxExporters . EditorTools . ExportSettings . instance . centerObjects = true ;
107
+ var newCenter = FbxExporters . Editor . ModelExporter . FindCenter ( goExportSet ) ;
108
108
109
- exportedRoot = ExportSelection ( exportSet ) ;
110
- children = new List < GameObject > ( ) ;
111
- foreach ( Transform child in exportedRoot . transform ) {
112
- children . Add ( child . gameObject ) ;
113
- }
114
- CompareHierarchies ( new GameObject [ ] { child2 , parent2 . gameObject } , children . ToArray ( ) , newCenter ) ;
109
+ exportedRoot = ExportSelection ( exportSet ) ;
110
+ children = new List < GameObject > ( ) ;
111
+ foreach ( Transform child in exportedRoot . transform ) {
112
+ children . Add ( child . gameObject ) ;
113
+ }
114
+ CompareHierarchies ( new GameObject [ ] { child2 , parent2 . gameObject } , children . ToArray ( ) , newCenter ) ;
115
115
}
116
116
117
117
/// <summary>
@@ -121,10 +121,11 @@ public void TestDefaultSelection ()
121
121
/// </summary>
122
122
/// <param name="actual">Actual.</param>
123
123
/// <param name="expected">Expected.</param>
124
- /// <param name="center">New center for expected transform, if present.</param>
125
- private void CompareGlobalTransform ( Transform actual , Transform expected = null , Vector3 center = default ( Vector3 ) ) {
124
+ /// <param name="center">New center for expected transform, if present.</param>
125
+ private void CompareGlobalTransform ( Transform actual , Transform expected = null , Vector3 center = default ( Vector3 ) )
126
+ {
126
127
var actualMatrix = ConstructTRSMatrix ( actual ) ;
127
- var expectedMatrix = expected == null ? new FbxAMatrix ( ) : ConstructTRSMatrix ( expected , false , center ) ;
128
+ var expectedMatrix = expected == null ? new FbxAMatrix ( ) : ConstructTRSMatrix ( expected , false , center ) ;
128
129
Assert . AreEqual ( expectedMatrix , actualMatrix ) ;
129
130
}
130
131
@@ -134,23 +135,23 @@ private void CompareGlobalTransform(Transform actual, Transform expected=null, V
134
135
/// <returns>The TRS matrix.</returns>
135
136
/// <param name="t">Transform.</param>
136
137
/// <param name="local">If set to <c>true</c> use local transform.</param>
137
- /// <param name="center">New center for global transform.</param>
138
- private FbxAMatrix ConstructTRSMatrix ( Transform t , bool local = true , Vector3 center = default ( Vector3 ) )
138
+ /// <param name="center">New center for global transform.</param>
139
+ private FbxAMatrix ConstructTRSMatrix ( Transform t , bool local = true , Vector3 center = default ( Vector3 ) )
139
140
{
140
- var translation = local ? t . localPosition : FbxExporters . Editor . ModelExporter . GetRecenteredTranslation ( t , center ) ;
141
- var rotation = local ? t . localEulerAngles : t . eulerAngles ;
142
- var scale = local ? t . localScale : t . lossyScale ;
141
+ var translation = local ? t . localPosition : FbxExporters . Editor . ModelExporter . GetRecenteredTranslation ( t , center ) ;
142
+ var rotation = local ? t . localEulerAngles : t . eulerAngles ;
143
+ var scale = local ? t . localScale : t . lossyScale ;
143
144
return new FbxAMatrix (
144
145
new FbxVector4 ( translation . x , translation . y , translation . z ) ,
145
146
new FbxVector4 ( rotation . x , rotation . y , rotation . z ) ,
146
147
new FbxVector4 ( scale . x , scale . y , scale . z )
147
148
) ;
148
149
}
149
150
150
- /// <summary>
151
- /// Creates test hierarchy.
152
- /// </summary>
153
- /// <returns>The hierarchy root.</returns>
151
+ /// <summary>
152
+ /// Creates test hierarchy.
153
+ /// </summary>
154
+ /// <returns>The hierarchy root.</returns>
154
155
private GameObject CreateHierarchy ( )
155
156
{
156
157
// Create the following hierarchy:
@@ -188,40 +189,41 @@ private GameObject CreateHierarchy ()
188
189
return root ;
189
190
}
190
191
191
- /// <summary>
192
- /// Sets the transform.
193
- /// </summary>
194
- /// <param name="t">Transform.</param>
195
- /// <param name="pos">Position.</param>
196
- /// <param name="rot">Rotation.</param>
197
- /// <param name="scale">Scale.</param>
198
- private void SetTransform ( Transform t , Vector3 pos , Vector3 rot , Vector3 scale ) {
192
+ /// <summary>
193
+ /// Sets the transform.
194
+ /// </summary>
195
+ /// <param name="t">Transform.</param>
196
+ /// <param name="pos">Position.</param>
197
+ /// <param name="rot">Rotation.</param>
198
+ /// <param name="scale">Scale.</param>
199
+ private void SetTransform ( Transform t , Vector3 pos , Vector3 rot , Vector3 scale )
200
+ {
199
201
t . localPosition = pos ;
200
202
t . localEulerAngles = rot ;
201
203
t . localScale = scale ;
202
204
}
203
205
204
- /// <summary>
205
- /// Creates a GameObject.
206
- /// </summary>
207
- /// <returns>The created GameObject.</returns>
208
- /// <param name="name">Name.</param>
209
- /// <param name="parent">Parent.</param>
210
- private GameObject CreateGameObject ( string name , Transform parent = null )
206
+ /// <summary>
207
+ /// Creates a GameObject.
208
+ /// </summary>
209
+ /// <returns>The created GameObject.</returns>
210
+ /// <param name="name">Name.</param>
211
+ /// <param name="parent">Parent.</param>
212
+ private GameObject CreateGameObject ( string name , Transform parent = null )
211
213
{
212
214
var go = new GameObject ( name ) ;
213
215
go . transform . SetParent ( parent ) ;
214
216
return go ;
215
- }
217
+ }
216
218
217
- /// <summary>
218
- /// Compares the hierarchies.
219
- /// </summary>
220
- /// <param name="expectedHierarchy">Expected hierarchy.</param>
221
- /// <param name="actualHierarchy">Actual hierarchy.</param>
222
- /// <param name="ignoreName">If set to <c>true</c> ignore name.</param>
223
- /// <param name="compareTransform">If set to <c>true</c> compare transform.</param>
224
- private void CompareHierarchies (
219
+ /// <summary>
220
+ /// Compares the hierarchies.
221
+ /// </summary>
222
+ /// <param name="expectedHierarchy">Expected hierarchy.</param>
223
+ /// <param name="actualHierarchy">Actual hierarchy.</param>
224
+ /// <param name="ignoreName">If set to <c>true</c> ignore name.</param>
225
+ /// <param name="compareTransform">If set to <c>true</c> compare transform.</param>
226
+ private void CompareHierarchies (
225
227
GameObject expectedHierarchy , GameObject actualHierarchy ,
226
228
bool ignoreName = false , bool compareTransform = true )
227
229
{
@@ -245,21 +247,21 @@ private void CompareHierarchies(
245
247
}
246
248
}
247
249
248
- /// <summary>
249
- /// Compares the hierarchies.
250
- /// </summary>
251
- /// <param name="expectedHierarchy">Expected hierarchy.</param>
252
- /// <param name="actualHierarchy">Actual hierarchy.</param>
253
- /// <param name="center">New center for global transforms.</param>
254
- private void CompareHierarchies ( GameObject [ ] expectedHierarchy , GameObject [ ] actualHierarchy , Vector3 center = default ( Vector3 ) )
250
+ /// <summary>
251
+ /// Compares the hierarchies.
252
+ /// </summary>
253
+ /// <param name="expectedHierarchy">Expected hierarchy.</param>
254
+ /// <param name="actualHierarchy">Actual hierarchy.</param>
255
+ /// <param name="center">New center for global transforms.</param>
256
+ private void CompareHierarchies ( GameObject [ ] expectedHierarchy , GameObject [ ] actualHierarchy , Vector3 center = default ( Vector3 ) )
255
257
{
256
258
Assert . AreEqual ( expectedHierarchy . Length , actualHierarchy . Length ) ;
257
259
258
260
System . Array . Sort ( expectedHierarchy , delegate ( GameObject x , GameObject y ) {
259
- return x . name . CompareTo ( y . name ) ;
261
+ return x . name . CompareTo ( y . name ) ;
260
262
} ) ;
261
263
System . Array . Sort ( actualHierarchy , delegate ( GameObject x , GameObject y ) {
262
- return x . name . CompareTo ( y . name ) ;
264
+ return x . name . CompareTo ( y . name ) ;
263
265
} ) ;
264
266
265
267
for ( int i = 0 ; i < expectedHierarchy . Length ; i ++ ) {
0 commit comments