@@ -12,7 +12,7 @@ namespace FbxExporters
12
12
namespace Review
13
13
{
14
14
[ UnityEditor . InitializeOnLoad ]
15
- public class TurnTable
15
+ public class TurnTable : UnityEditor . AssetPostprocessor
16
16
{
17
17
const string DefaultScenesPath = "Assets" ;
18
18
const string DefaultSceneName = "FbxExporters_TurnTableReview" ;
@@ -24,17 +24,22 @@ public class TurnTable
24
24
static string LastFilePath = null ;
25
25
static Object LastModel = null ;
26
26
27
- static TurnTable ( ) {
28
- UnityEditor . EditorApplication . update -= OnEditorUpdate ;
29
- UnityEditor . EditorApplication . update += OnEditorUpdate ;
30
- }
31
-
32
- private static void OnEditorUpdate ( )
27
+ static void OnPostprocessAllAssets (
28
+ string [ ] importedAssets , string [ ] deletedAssets ,
29
+ string [ ] movedAssets , string [ ] movedFromAssetPaths )
33
30
{
34
- string instructionFile = FbxExporters . Editor . Integrations . GetFullMayaInstructionPath ( ) ;
35
- if ( System . IO . File . Exists ( instructionFile ) ) {
36
- LastSavedModel ( ) ;
37
- System . IO . File . Delete ( instructionFile ) ;
31
+ // check if a turntable model was potentially imported
32
+ var tempSavePath = "Assets/" + TempSavePath ;
33
+ foreach ( var assetPath in importedAssets ) {
34
+ if ( assetPath . StartsWith ( tempSavePath ) && assetPath . EndsWith ( ".fbx" ) ) {
35
+ // if the instruction file exists, then run the turntable and delete the file
36
+ string instructionFile = FbxExporters . Editor . Integrations . GetFullMayaInstructionPath ( ) ;
37
+ if ( System . IO . File . Exists ( instructionFile ) ) {
38
+ LastSavedModel ( ) ;
39
+ System . IO . File . Delete ( instructionFile ) ;
40
+ break ;
41
+ }
42
+ }
38
43
}
39
44
}
40
45
@@ -112,7 +117,6 @@ private static Object LoadModel (string fbxFileName)
112
117
turntableGO = new GameObject ( "TurnTableBase" ) ;
113
118
turntableGO . AddComponent < FbxTurnTableBase > ( ) ;
114
119
}
115
-
116
120
modelGO . transform . parent = turntableGO . transform ;
117
121
}
118
122
@@ -169,12 +173,17 @@ private static void LoadLastSavedModel ()
169
173
Debug . LogWarning ( string . Format ( "failed to load model : {0}" , fbxFileName ) ) ;
170
174
}
171
175
}
176
+
177
+ // focus onto model
172
178
if ( LastModel != null ) {
173
179
var model = LastModel as GameObject ;
174
180
if ( model != null ) {
175
- var turntable = model . transform . parent . gameObject ;
176
- UnityEditor . Selection . objects = new GameObject [ ] { turntable } ;
177
- FrameCameraOnModel ( turntable ) ;
181
+ var turntable = model . transform . parent ;
182
+ if ( turntable != null ) {
183
+ var turntableGO = turntable . gameObject ;
184
+ UnityEditor . Selection . objects = new GameObject [ ] { turntableGO } ;
185
+ FrameCameraOnModel ( turntableGO ) ;
186
+ }
178
187
}
179
188
}
180
189
}
0 commit comments