Skip to content

Commit 5da6531

Browse files
authored
Merge pull request #92 from Unity-Technologies/UNI-22026-project-settings-turntable-scene
Uni 22026 set desired turntable scene from project settings
2 parents 5f18134 + c3f7601 commit 5da6531

File tree

4 files changed

+78
-34
lines changed

4 files changed

+78
-34
lines changed

Assets/FbxExporters/Editor/EditorRotate.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
namespace FbxExporters.Review
1515
{
16-
[CustomEditor (typeof(RotateModel))]
16+
[CustomEditor (typeof(FbxTurnTableBase))]
1717
public class EditorRotate : UnityEditor.Editor
1818
{
19-
RotateModel model;
19+
FbxTurnTableBase model;
2020

2121
public void OnEnable ()
2222
{
23-
model = (RotateModel)target;
23+
model = (FbxTurnTableBase)target;
2424
EditorApplication.update += Update;
2525
}
2626

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public override void OnInspectorGUI() {
6868
}
6969
}
7070
}
71+
GUILayout.EndHorizontal ();
72+
GUILayout.BeginHorizontal ();
73+
74+
GUILayout.Label (new GUIContent (
75+
"Turn Table Scene:",
76+
"Scene to use for reviewing models. If none, a scene will be created on review."));
77+
78+
exportSettings.turntableScene = EditorGUILayout.ObjectField (
79+
exportSettings.turntableScene, typeof(SceneAsset), false
80+
);
7181

7282
GUILayout.EndHorizontal ();
7383
GUILayout.FlexibleSpace ();
@@ -92,6 +102,9 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
92102
public bool mayaCompatibleNames;
93103
public bool centerObjects;
94104

105+
[SerializeField]
106+
public UnityEngine.Object turntableScene;
107+
95108
/// <summary>
96109
/// The path where Convert To Model will save the new fbx and prefab.
97110
///
@@ -112,6 +125,21 @@ protected override void LoadDefaults()
112125
mayaCompatibleNames = true;
113126
centerObjects = true;
114127
convertToModelSavePath = kDefaultSavePath;
128+
turntableScene = null;
129+
}
130+
131+
public static string GetTurnTableSceneName(){
132+
if (instance.turntableScene) {
133+
return instance.turntableScene.name;
134+
}
135+
return null;
136+
}
137+
138+
public static string GetTurnTableScenePath(){
139+
if (instance.turntableScene) {
140+
return AssetDatabase.GetAssetPath (instance.turntableScene);
141+
}
142+
return null;
115143
}
116144

117145
/// <summary>

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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

28
using 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
{

Assets/FbxExporters/RotateModel.cs renamed to Assets/FbxExporters/FbxTurnTableBase.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace FbxExporters.Review
1313
{
14-
public class RotateModel : MonoBehaviour
14+
public class FbxTurnTableBase : MonoBehaviour
1515
{
1616

1717
[Tooltip ("Rotation speed in degrees/second")]
@@ -22,11 +22,6 @@ public class RotateModel : MonoBehaviour
2222
private float timeOfLastUpdate = float.MaxValue;
2323
#endif
2424

25-
public float GetSpeed()
26-
{
27-
return speed;
28-
}
29-
3025
public void Rotate()
3126
{
3227
float deltaTime = 0;
@@ -42,8 +37,7 @@ public void Rotate()
4237
transform.Rotate (Vector3.up, speed * deltaTime, Space.World);
4338
}
4439

45-
void Update ()
46-
{
40+
void Update () {
4741
Rotate ();
4842
}
4943
}

0 commit comments

Comments
 (0)