1+ // ***********************************************************************
2+ // Copyright (c) 2017 Unity Technologies. All rights reserved.
3+ //
4+ // Licensed under the ##LICENSENAME##.
5+ // See LICENSE.md file in the project root for full license information.
6+ // ***********************************************************************
17
28using UnityEngine ;
39
@@ -10,8 +16,10 @@ public class TurnTable
1016 {
1117 const string MenuItemName = "FbxExporters/Turntable Review/Autoload Last Saved Prefab" ;
1218
13- const string ScenesPath = "Assets" ;
14- const string SceneName = "FbxExporters_TurnTableReview" ;
19+ const string DefaultScenesPath = "Assets" ;
20+ const string DefaultSceneName = "FbxExporters_TurnTableReview" ;
21+
22+ static string SceneName = "FbxExporters_TurnTableReview" ;
1523
1624 public const string TempSavePath = "_safe_to_delete" ;
1725
@@ -48,7 +56,7 @@ private static System.IO.FileInfo GetLastSavedFile (string directoryPath, string
4856
4957 private static string GetSceneFilePath ( )
5058 {
51- return System . IO . Path . Combine ( ScenesPath , SceneName + ".unity" ) ;
59+ return System . IO . Path . Combine ( DefaultScenesPath , DefaultSceneName + ".unity" ) ;
5260 }
5361
5462 private static string GetLastSavedFilePath ( )
@@ -83,16 +91,20 @@ private static Object LoadModel (string fbxFileName)
8391 if ( unityMainAsset ) {
8492 modelGO = UnityEditor . PrefabUtility . InstantiatePrefab ( unityMainAsset ) as GameObject ;
8593
86- GameObject turntableGO = GameObject . Find ( "TurnTable" ) ;
87- if ( turntableGO != null ) {
88- modelGO . transform . parent = turntableGO . transform ;
89- turntableGO . AddComponent < RotateModel > ( ) ;
94+ var turnTableBase = GameObject . FindObjectOfType < FbxTurnTableBase > ( ) ;
95+ GameObject turntableGO = null ;
96+ if ( turnTableBase != null ) {
97+ turntableGO = turnTableBase . gameObject ;
98+ }
9099
91- UnityEditor . Selection . objects = new GameObject [ ] { turntableGO } ;
92- } else {
93- modelGO . AddComponent < RotateModel > ( ) ;
94- UnityEditor . Selection . objects = new GameObject [ ] { modelGO } ;
100+ if ( turntableGO == null ) {
101+ turntableGO = new GameObject ( "TurnTableBase" ) ;
102+ turntableGO . AddComponent < FbxTurnTableBase > ( ) ;
95103 }
104+
105+ modelGO . transform . parent = turntableGO . transform ;
106+
107+ UnityEditor . Selection . objects = new GameObject [ ] { turntableGO } ;
96108 }
97109
98110 FrameCameraOnModel ( modelGO ) ;
@@ -143,37 +155,47 @@ public static void LastSavedModel ()
143155 System . Collections . Generic . List < UnityEngine . SceneManagement . Scene > scenes
144156 = new System . Collections . Generic . List < UnityEngine . SceneManagement . Scene > ( ) ;
145157
158+ string desiredSceneName = FbxExporters . EditorTools . ExportSettings . GetTurnTableSceneName ( ) ;
159+ if ( string . IsNullOrEmpty ( desiredSceneName ) ) {
160+ desiredSceneName = DefaultSceneName ;
161+ }
162+
146163 for ( int i = 0 ; i < UnityEngine . SceneManagement . SceneManager . sceneCount ; i ++ ) {
147164 UnityEngine . SceneManagement . Scene toAdd = UnityEngine . SceneManagement . SceneManager . GetSceneAt ( i ) ;
148165
149166 // skip Untitled scene.
150167 // The Untitled scene cannot be unloaded, if modified, and we don't want to force the user to save it.
151168 if ( toAdd . name == "" ) continue ;
152169
153- if ( toAdd . name == SceneName )
154- {
170+ if ( toAdd . name == desiredSceneName ) {
155171 scene = toAdd ;
156172 continue ;
157173 }
174+
158175 scenes . Add ( toAdd ) ;
159176 }
160177
161178 // if turntable scene not added to list of scenes
162- if ( ! scene . IsValid ( ) )
179+ if ( ! scene . IsValid ( ) || ! scene . isLoaded )
163180 {
164- // and if for some reason the turntable scene is missing create an empty scene
165- // NOTE: we cannot use NewScene because it will force me to save the modified Untitled scene
166- if ( ! System . IO . File . Exists ( GetSceneFilePath ( ) ) )
167- {
168- var writer = System . IO . File . CreateText ( GetSceneFilePath ( ) ) ;
169- writer . WriteLine ( "%YAML 1.1\n %TAG !u! tag:unity3d.com,2011:" ) ;
170- writer . Close ( ) ;
171- UnityEditor . AssetDatabase . Refresh ( ) ;
181+ string scenePath = FbxExporters . EditorTools . ExportSettings . GetTurnTableScenePath ( ) ;
182+ if ( string . IsNullOrEmpty ( scenePath ) ) {
183+ // and if for some reason the turntable scene is missing create an empty scene
184+ // NOTE: we cannot use NewScene because it will force me to save the modified Untitled scene
185+ if ( ! System . IO . File . Exists ( GetSceneFilePath ( ) ) ) {
186+ var writer = System . IO . File . CreateText ( GetSceneFilePath ( ) ) ;
187+ writer . WriteLine ( "%YAML 1.1\n %TAG !u! tag:unity3d.com,2011:" ) ;
188+ writer . Close ( ) ;
189+ UnityEditor . AssetDatabase . Refresh ( ) ;
190+ }
191+ scenePath = GetSceneFilePath ( ) ;
172192 }
173193
174- scene = UnityEditor . SceneManagement . EditorSceneManager . OpenScene ( GetSceneFilePath ( ) , UnityEditor . SceneManagement . OpenSceneMode . Additive ) ;
194+ scene = UnityEditor . SceneManagement . EditorSceneManager . OpenScene ( scenePath , UnityEditor . SceneManagement . OpenSceneMode . Additive ) ;
175195 }
176196
197+ SceneName = scene . name ;
198+
177199 // save unmodified scenes (but not the untitled or turntable scene)
178200 if ( UnityEditor . SceneManagement . EditorSceneManager . SaveModifiedScenesIfUserWantsTo ( scenes . ToArray ( ) ) )
179201 {
0 commit comments