@@ -74,21 +74,36 @@ public void TestDefaultSelection ()
74
74
var root = CreateHierarchy ( ) ;
75
75
Assert . IsNotNull ( root ) ;
76
76
77
- var exportedRoot = ExportSelection ( root , new Object [ ] { root } ) ;
78
-
79
77
// test Export Root
80
78
// Expected result: everything gets exported
79
+ var exportedRoot = ExportSelection ( new Object [ ] { root } ) ;
80
+ CompareHierarchies ( root , exportedRoot , true ) ;
81
81
82
82
// test Export Parent1, Child1
83
83
// Expected result: Parent1, Child1, Child2
84
+ var parent1 = root . transform . Find ( "Parent1" ) ;
85
+ var child1 = parent1 . Find ( "Child1" ) ;
86
+ exportedRoot = ExportSelection ( new Object [ ] { parent1 . gameObject , child1 . gameObject } ) ;
87
+ CompareHierarchies ( parent1 . gameObject , exportedRoot , true ) ;
84
88
85
89
// test Export Child2
86
90
// Expected result: Child2
91
+ var child2 = parent1 . Find ( "Child2" ) . gameObject ;
92
+ exportedRoot = ExportSelection ( new Object [ ] { child2 } ) ;
93
+ CompareHierarchies ( child2 , exportedRoot , true ) ;
87
94
88
95
// test Export Child2, Parent2
89
96
// Expected result: Parent2, Child3, Child2
97
+ var parent2 = root . transform . Find ( "Parent2" ) ;
98
+ exportedRoot = ExportSelection ( new Object [ ] { child2 , parent2 } ) ;
99
+
100
+ List < GameObject > children = new List < GameObject > ( ) ;
101
+ foreach ( Transform child in exportedRoot . transform ) {
102
+ children . Add ( child . gameObject ) ;
103
+ }
104
+ CompareHierarchies ( new GameObject [ ] { child2 , parent2 . gameObject } , children . ToArray ( ) ) ;
90
105
91
- // UnityEngine.Object.DestroyImmediate (root);
106
+ UnityEngine . Object . DestroyImmediate ( root ) ;
92
107
}
93
108
94
109
private GameObject CreateHierarchy ( )
@@ -121,15 +136,40 @@ private GameObject CreateGameObject(string name, Transform parent = null)
121
136
return go ;
122
137
}
123
138
124
- private void CompareHierarchies ( GameObject expectedHierarchy , GameObject actualHierarchy , bool ignoreRoot = false )
139
+ private void CompareHierarchies ( GameObject expectedHierarchy , GameObject actualHierarchy , bool ignoreName = false )
125
140
{
126
- if ( ! ignoreRoot ) {
141
+ if ( ! ignoreName ) {
127
142
Assert . AreEqual ( expectedHierarchy . name , actualHierarchy . name ) ;
128
- Assert . AreEqual ( expectedHierarchy . transform . childCount , actualHierarchy . transform . childCount ) ;
143
+ }
144
+
145
+ var expectedTransform = expectedHierarchy . transform ;
146
+ var actualTransform = actualHierarchy . transform ;
147
+ Assert . AreEqual ( expectedTransform . childCount , actualTransform . childCount ) ;
148
+
149
+ foreach ( Transform expectedChild in expectedTransform ) {
150
+ var actualChild = actualTransform . Find ( expectedChild . name ) ;
151
+ Assert . IsNotNull ( actualChild ) ;
152
+ CompareHierarchies ( expectedChild . gameObject , actualChild . gameObject ) ;
153
+ }
154
+ }
155
+
156
+ private void CompareHierarchies ( GameObject [ ] expectedHierarchy , GameObject [ ] actualHierarchy )
157
+ {
158
+ Assert . AreEqual ( expectedHierarchy . Length , actualHierarchy . Length ) ;
159
+
160
+ System . Array . Sort ( expectedHierarchy , delegate ( GameObject x , GameObject y ) {
161
+ return x . name . CompareTo ( y . name ) ;
162
+ } ) ;
163
+ System . Array . Sort ( actualHierarchy , delegate ( GameObject x , GameObject y ) {
164
+ return x . name . CompareTo ( y . name ) ;
165
+ } ) ;
166
+
167
+ for ( int i = 0 ; i < expectedHierarchy . Length ; i ++ ) {
168
+ CompareHierarchies ( expectedHierarchy [ i ] , actualHierarchy [ i ] ) ;
129
169
}
130
170
}
131
171
132
- private GameObject ExportSelection ( GameObject origRoot , Object [ ] selected )
172
+ private GameObject ExportSelection ( Object [ ] selected )
133
173
{
134
174
// export selected to a file, then return the root
135
175
var filename = GetRandomFileNamePath ( ) ;
@@ -138,7 +178,6 @@ private GameObject ExportSelection(GameObject origRoot, Object[] selected)
138
178
var fbxFileName = FbxExporters . Editor . ModelExporter . ExportObjects ( filename , selected ) as string ;
139
179
Debug . unityLogger . logEnabled = true ;
140
180
141
- Debug . LogWarning ( filename + ", " + fbxFileName ) ;
142
181
Assert . IsNotNull ( fbxFileName ) ;
143
182
144
183
// make filepath relative to project folder
0 commit comments