7
7
8
8
using UnityEngine ;
9
9
using UnityEditor ;
10
- using UnityEngine . TestTools ;
11
10
using NUnit . Framework ;
12
11
using System . IO ;
13
12
using System . Collections . Generic ;
14
- using FbxSdk ;
15
13
16
14
namespace FbxExporters . UnitTests
17
15
{
@@ -37,7 +35,7 @@ public void Init ()
37
35
// Delete the object right away (don't even wait for term).
38
36
var fbxInstance = PrefabUtility . InstantiatePrefab ( m_fbx ) as GameObject ;
39
37
fbxInstance . AddComponent < FbxPrefab > ( ) . SetSourceModel ( m_fbx ) ;
40
- m_prefabPath = GetRandomFileNamePath ( extName : ".prefab" ) ;
38
+ m_prefabPath = GetRandomPrefabAssetPath ( ) ;
41
39
m_prefab = PrefabUtility . CreatePrefab ( m_prefabPath , fbxInstance ) ;
42
40
AssetDatabase . Refresh ( ) ;
43
41
Assert . AreEqual ( m_prefabPath , AssetDatabase . GetAssetPath ( m_prefab ) ) ;
@@ -110,17 +108,17 @@ public void ExpensivePerformanceTest ()
110
108
//
111
109
// Then modify one fbx model. Shouldn't take longer than 1s.
112
110
var hierarchy = CreateGameObject ( "the_root" ) ;
113
- var baseName = GetRandomFileNamePath ( extName : "" ) ;
114
- FbxExporters . Editor . ModelExporter . ExportObject ( baseName + ".fbx" , hierarchy ) ;
111
+ var baseName = GetRandomFbxFilePath ( ) ;
112
+ FbxExporters . Editor . ModelExporter . ExportObject ( baseName , hierarchy ) ;
115
113
116
114
// Create N fbx models by copying files. Import them all at once.
117
115
var names = new string [ n ] ;
118
116
names [ 0 ] = baseName ;
119
117
stopwatch . Reset ( ) ;
120
118
stopwatch . Start ( ) ;
121
119
for ( int i = 1 ; i < n ; ++ i ) {
122
- names [ i ] = GetRandomFileNamePath ( extName : "" ) ;
123
- System . IO . File . Copy ( names [ 0 ] + ".fbx" , names [ i ] + ".fbx" ) ;
120
+ names [ i ] = GetRandomFbxFilePath ( ) ;
121
+ System . IO . File . Copy ( names [ 0 ] , names [ i ] ) ;
124
122
}
125
123
Debug . Log ( "Created fbx files in " + stopwatch . ElapsedMilliseconds ) ;
126
124
@@ -136,7 +134,7 @@ public void ExpensivePerformanceTest ()
136
134
stopwatch . Start ( ) ;
137
135
var fbxFiles = new GameObject [ n / 2 ] ;
138
136
for ( int i = 0 ; i < n / 2 ; ++ i ) {
139
- fbxFiles [ i ] = AssetDatabase . LoadMainAssetAtPath ( names [ i ] + ".fbx" ) as GameObject ;
137
+ fbxFiles [ i ] = AssetDatabase . LoadMainAssetAtPath ( names [ i ] ) as GameObject ;
140
138
Assert . IsTrue ( fbxFiles [ i ] ) ;
141
139
}
142
140
Debug . Log ( "Loaded fbx files in " + stopwatch . ElapsedMilliseconds ) ;
@@ -148,34 +146,35 @@ public void ExpensivePerformanceTest ()
148
146
Assert . IsTrue ( instance ) ;
149
147
var fbxPrefab = instance . AddComponent < FbxPrefab > ( ) ;
150
148
fbxPrefab . SetSourceModel ( fbxFiles [ i ] ) ;
151
- UnityEditor . PrefabUtility . CreatePrefab ( names [ i ] + ".prefab" , fbxFiles [ i ] ) ;
149
+ PrefabUtility . CreatePrefab ( GetRandomPrefabAssetPath ( ) , fbxFiles [ i ] ) ;
152
150
}
153
151
Debug . Log ( "Created prefabs in " + stopwatch . ElapsedMilliseconds ) ;
154
152
155
153
// Export a new hierarchy and update one fbx file.
156
154
// Make sure we're timing just the assetdatabase refresh by
157
155
// creating a file and then copying it, and not the FbxExporter.
158
156
var newHierarchy = CreateHierarchy ( ) ;
159
- FbxExporters . Editor . ModelExporter . ExportObject ( names [ 0 ] + "_new.fbx" , newHierarchy ) ;
157
+ var newHierarchyName = GetRandomFbxFilePath ( ) ;
158
+ FbxExporters . Editor . ModelExporter . ExportObject ( newHierarchyName , newHierarchy ) ;
160
159
try {
161
160
UnityEngine . Debug . unityLogger . logEnabled = false ;
162
161
stopwatch . Reset ( ) ;
163
162
stopwatch . Start ( ) ;
164
- File . Copy ( names [ 0 ] + "_new.fbx" , names [ 0 ] + ".fbx" , overwrite : true ) ;
163
+ File . Copy ( newHierarchyName , names [ 0 ] , overwrite : true ) ;
165
164
AssetDatabase . Refresh ( ) ; // force the update right now.
166
165
} finally {
167
166
UnityEngine . Debug . unityLogger . logEnabled = true ;
168
167
}
169
168
Debug . Log ( "Import (one change) in " + stopwatch . ElapsedMilliseconds ) ;
170
169
Assert . LessOrEqual ( stopwatch . ElapsedMilliseconds , NoUpdateTimeLimit ) ;
171
170
172
- // Try what happens when nothing gets updated.
171
+ // Try what happens when no prefab gets updated.
173
172
try {
174
173
UnityEngine . Debug . unityLogger . logEnabled = false ;
175
174
stopwatch . Reset ( ) ;
176
175
stopwatch . Start ( ) ;
177
- string newHierarchyFbxFile = GetRandomFileNamePath ( extName : ".fbx" ) ;
178
- File . Copy ( names [ 0 ] + ".fbx" , newHierarchyFbxFile ) ;
176
+ string newHierarchyFbxFile = GetRandomFbxFilePath ( ) ;
177
+ File . Copy ( names [ 0 ] , newHierarchyFbxFile ) ;
179
178
AssetDatabase . Refresh ( ) ; // force the update right now.
180
179
} finally {
181
180
UnityEngine . Debug . unityLogger . logEnabled = true ;
0 commit comments