Skip to content

Commit 34a49c8

Browse files
committed
use AssetPostProcessor instead of update function
1 parent 331e5c7 commit 34a49c8

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace FbxExporters
1212
namespace Review
1313
{
1414
[UnityEditor.InitializeOnLoad]
15-
public class TurnTable
15+
public class TurnTable : UnityEditor.AssetPostprocessor
1616
{
1717
const string DefaultScenesPath = "Assets";
1818
const string DefaultSceneName = "FbxExporters_TurnTableReview";
@@ -24,17 +24,22 @@ public class TurnTable
2424
static string LastFilePath = null;
2525
static Object LastModel = null;
2626

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)
3330
{
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+
}
3843
}
3944
}
4045

@@ -112,7 +117,6 @@ private static Object LoadModel (string fbxFileName)
112117
turntableGO = new GameObject ("TurnTableBase");
113118
turntableGO.AddComponent<FbxTurnTableBase> ();
114119
}
115-
116120
modelGO.transform.parent = turntableGO.transform;
117121
}
118122

@@ -169,12 +173,17 @@ private static void LoadLastSavedModel ()
169173
Debug.LogWarning (string.Format ("failed to load model : {0}", fbxFileName));
170174
}
171175
}
176+
177+
// focus onto model
172178
if (LastModel != null) {
173179
var model = LastModel as GameObject;
174180
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+
}
178187
}
179188
}
180189
}

0 commit comments

Comments
 (0)