Skip to content

Commit 80cc5c6

Browse files
committed
update model during play mode
delete model right before entering playmode. Model will get replaced with new model during play.
1 parent ce5b98e commit 80cc5c6

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace FbxExporters
55
{
66
namespace Review
77
{
8-
class TurnTable
8+
[UnityEditor.InitializeOnLoad]
9+
public class TurnTable
910
{
1011
const string MenuItemName = "FbxExporters/Turntable Review/Autoload Last Saved Prefab";
1112

@@ -21,6 +22,10 @@ public static void OnMenu ()
2122
LastSavedModel ();
2223
}
2324

25+
static TurnTable(){
26+
SubscribeToEvents();
27+
}
28+
2429
private static System.IO.FileInfo GetLastSavedFile (string directoryPath, string ext = ".fbx")
2530
{
2631
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo (directoryPath);
@@ -206,6 +211,9 @@ private static void SubscribeToEvents ()
206211
// ensure we only subscribe once
207212
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
208213
UnityEditor.EditorApplication.hierarchyWindowChanged += UpdateLastSavedModel;
214+
215+
UnityEditor.EditorApplication.playmodeStateChanged -= OnPlay;
216+
UnityEditor.EditorApplication.playmodeStateChanged += OnPlay;
209217
}
210218

211219
private static void UnsubscribeFromEvents ()
@@ -216,6 +224,7 @@ private static void UnsubscribeFromEvents ()
216224
LastFilePath = null;
217225

218226
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
227+
UnityEditor.EditorApplication.playmodeStateChanged -= OnPlay;
219228
}
220229

221230
private static bool AutoUpdateEnabled ()
@@ -225,11 +234,24 @@ private static bool AutoUpdateEnabled ()
225234

226235
private static void UpdateLastSavedModel ()
227236
{
237+
if (!AutoUpdateEnabled ()) {
238+
UnsubscribeFromEvents ();
239+
return;
240+
}
228241

229-
if (AutoUpdateEnabled ()) {
230-
LoadLastSavedModel ();
231-
} else {
242+
LoadLastSavedModel ();
243+
}
244+
245+
private static void OnPlay()
246+
{
247+
if (!AutoUpdateEnabled ()) {
232248
UnsubscribeFromEvents ();
249+
return;
250+
}
251+
252+
if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && !UnityEditor.EditorApplication.isPlaying) {
253+
UnloadModel (LastModel);
254+
LastModel = null;
233255
}
234256
}
235257
}

0 commit comments

Comments
 (0)