@@ -5,7 +5,8 @@ namespace FbxExporters
5
5
{
6
6
namespace Review
7
7
{
8
- class TurnTable
8
+ [ UnityEditor . InitializeOnLoad ]
9
+ public class TurnTable
9
10
{
10
11
const string MenuItemName = "FbxExporters/Turntable Review/Autoload Last Saved Prefab" ;
11
12
@@ -21,6 +22,10 @@ public static void OnMenu ()
21
22
LastSavedModel ( ) ;
22
23
}
23
24
25
+ static TurnTable ( ) {
26
+ SubscribeToEvents ( ) ;
27
+ }
28
+
24
29
private static System . IO . FileInfo GetLastSavedFile ( string directoryPath , string ext = ".fbx" )
25
30
{
26
31
System . IO . DirectoryInfo directoryInfo = new System . IO . DirectoryInfo ( directoryPath ) ;
@@ -206,6 +211,9 @@ private static void SubscribeToEvents ()
206
211
// ensure we only subscribe once
207
212
UnityEditor . EditorApplication . hierarchyWindowChanged -= UpdateLastSavedModel ;
208
213
UnityEditor . EditorApplication . hierarchyWindowChanged += UpdateLastSavedModel ;
214
+
215
+ UnityEditor . EditorApplication . playmodeStateChanged -= OnPlay ;
216
+ UnityEditor . EditorApplication . playmodeStateChanged += OnPlay ;
209
217
}
210
218
211
219
private static void UnsubscribeFromEvents ( )
@@ -216,6 +224,7 @@ private static void UnsubscribeFromEvents ()
216
224
LastFilePath = null ;
217
225
218
226
UnityEditor . EditorApplication . hierarchyWindowChanged -= UpdateLastSavedModel ;
227
+ UnityEditor . EditorApplication . playmodeStateChanged -= OnPlay ;
219
228
}
220
229
221
230
private static bool AutoUpdateEnabled ( )
@@ -225,11 +234,24 @@ private static bool AutoUpdateEnabled ()
225
234
226
235
private static void UpdateLastSavedModel ( )
227
236
{
237
+ if ( ! AutoUpdateEnabled ( ) ) {
238
+ UnsubscribeFromEvents ( ) ;
239
+ return ;
240
+ }
228
241
229
- if ( AutoUpdateEnabled ( ) ) {
230
- LoadLastSavedModel ( ) ;
231
- } else {
242
+ LoadLastSavedModel ( ) ;
243
+ }
244
+
245
+ private static void OnPlay ( )
246
+ {
247
+ if ( ! AutoUpdateEnabled ( ) ) {
232
248
UnsubscribeFromEvents ( ) ;
249
+ return ;
250
+ }
251
+
252
+ if ( UnityEditor . EditorApplication . isPlayingOrWillChangePlaymode && ! UnityEditor . EditorApplication . isPlaying ) {
253
+ UnloadModel ( LastModel ) ;
254
+ LastModel = null ;
233
255
}
234
256
}
235
257
}
0 commit comments