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
+ // ***********************************************************************
1
7
2
8
using UnityEngine ;
3
9
@@ -10,8 +16,10 @@ public class TurnTable
10
16
{
11
17
const string MenuItemName = "FbxExporters/Turntable Review/Autoload Last Saved Prefab" ;
12
18
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" ;
15
23
16
24
public const string TempSavePath = "_safe_to_delete" ;
17
25
@@ -48,7 +56,7 @@ private static System.IO.FileInfo GetLastSavedFile (string directoryPath, string
48
56
49
57
private static string GetSceneFilePath ( )
50
58
{
51
- return System . IO . Path . Combine ( ScenesPath , SceneName + ".unity" ) ;
59
+ return System . IO . Path . Combine ( DefaultScenesPath , DefaultSceneName + ".unity" ) ;
52
60
}
53
61
54
62
private static string GetLastSavedFilePath ( )
@@ -83,16 +91,20 @@ private static Object LoadModel (string fbxFileName)
83
91
if ( unityMainAsset ) {
84
92
modelGO = UnityEditor . PrefabUtility . InstantiatePrefab ( unityMainAsset ) as GameObject ;
85
93
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
+ }
90
99
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 > ( ) ;
95
103
}
104
+
105
+ modelGO . transform . parent = turntableGO . transform ;
106
+
107
+ UnityEditor . Selection . objects = new GameObject [ ] { turntableGO } ;
96
108
}
97
109
98
110
FrameCameraOnModel ( modelGO ) ;
@@ -143,37 +155,47 @@ public static void LastSavedModel ()
143
155
System . Collections . Generic . List < UnityEngine . SceneManagement . Scene > scenes
144
156
= new System . Collections . Generic . List < UnityEngine . SceneManagement . Scene > ( ) ;
145
157
158
+ string desiredSceneName = FbxExporters . EditorTools . ExportSettings . GetTurnTableSceneName ( ) ;
159
+ if ( string . IsNullOrEmpty ( desiredSceneName ) ) {
160
+ desiredSceneName = DefaultSceneName ;
161
+ }
162
+
146
163
for ( int i = 0 ; i < UnityEngine . SceneManagement . SceneManager . sceneCount ; i ++ ) {
147
164
UnityEngine . SceneManagement . Scene toAdd = UnityEngine . SceneManagement . SceneManager . GetSceneAt ( i ) ;
148
165
149
166
// skip Untitled scene.
150
167
// The Untitled scene cannot be unloaded, if modified, and we don't want to force the user to save it.
151
168
if ( toAdd . name == "" ) continue ;
152
169
153
- if ( toAdd . name == SceneName )
154
- {
170
+ if ( toAdd . name == desiredSceneName ) {
155
171
scene = toAdd ;
156
172
continue ;
157
173
}
174
+
158
175
scenes . Add ( toAdd ) ;
159
176
}
160
177
161
178
// if turntable scene not added to list of scenes
162
- if ( ! scene . IsValid ( ) )
179
+ if ( ! scene . IsValid ( ) || ! scene . isLoaded )
163
180
{
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 ( ) ;
172
192
}
173
193
174
- scene = UnityEditor . SceneManagement . EditorSceneManager . OpenScene ( GetSceneFilePath ( ) , UnityEditor . SceneManagement . OpenSceneMode . Additive ) ;
194
+ scene = UnityEditor . SceneManagement . EditorSceneManager . OpenScene ( scenePath , UnityEditor . SceneManagement . OpenSceneMode . Additive ) ;
175
195
}
176
196
197
+ SceneName = scene . name ;
198
+
177
199
// save unmodified scenes (but not the untitled or turntable scene)
178
200
if ( UnityEditor . SceneManagement . EditorSceneManager . SaveModifiedScenesIfUserWantsTo ( scenes . ToArray ( ) ) )
179
201
{
0 commit comments