Skip to content

Commit 9838f03

Browse files
committed
rotate in editor instead of entering playmode
1 parent 3df3fb8 commit 9838f03

File tree

3 files changed

+70
-35
lines changed

3 files changed

+70
-35
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
// ***********************************************************************
7+
8+
9+
using System.Collections;
10+
using System.Collections.Generic;
11+
using UnityEngine;
12+
using UnityEditor;
13+
14+
namespace FbxExporters.Review
15+
{
16+
[CustomEditor (typeof(RotateModel))]
17+
public class EditorRotate : UnityEditor.Editor
18+
{
19+
RotateModel model;
20+
21+
public void OnEnable ()
22+
{
23+
model = (RotateModel)target;
24+
EditorApplication.update += Update;
25+
}
26+
27+
public void OnDisable ()
28+
{
29+
EditorApplication.update -= Update;
30+
}
31+
32+
void Update ()
33+
{
34+
// don't do anything in play mode
35+
if (model == null || EditorApplication.isPlaying) {
36+
return;
37+
}
38+
model.transform.Rotate (Vector3.up, model.GetSpeed() * Time.deltaTime, Space.World);
39+
}
40+
}
41+
}

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ public static void OnMenu ()
2424
LastSavedModel ();
2525
}
2626

27-
static TurnTable(){
28-
SubscribeToEvents();
29-
}
30-
3127
private static System.IO.FileInfo GetLastSavedFile (string directoryPath, string ext = ".fbx")
3228
{
3329
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo (directoryPath);
@@ -91,8 +87,11 @@ private static Object LoadModel (string fbxFileName)
9187
if (turntableGO != null) {
9288
modelGO.transform.parent = turntableGO.transform;
9389
turntableGO.AddComponent<RotateModel> ();
90+
91+
UnityEditor.Selection.objects = new GameObject[]{ turntableGO };
9492
} else {
9593
modelGO.AddComponent<RotateModel> ();
94+
UnityEditor.Selection.objects = new GameObject[]{ modelGO };
9695
}
9796
}
9897

@@ -219,11 +218,10 @@ public static void LastSavedModel ()
219218
lightComp.shadows = LightShadows.Soft;
220219
}
221220

222-
// maximize game window and start playing
221+
// maximize game window
223222
var gameWindow = GetMainGameView();
224223
if (gameWindow) {
225224
gameWindow.maximized = true;
226-
UnityEditor.EditorApplication.isPlaying = true;
227225
} else {
228226
Debug.LogWarning ("Failed to access Game Window, please restart Unity to try again.");
229227
}
@@ -248,9 +246,6 @@ private static void SubscribeToEvents ()
248246
// ensure we only subscribe once
249247
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
250248
UnityEditor.EditorApplication.hierarchyWindowChanged += UpdateLastSavedModel;
251-
252-
UnityEditor.EditorApplication.playmodeStateChanged -= OnPlay;
253-
UnityEditor.EditorApplication.playmodeStateChanged += OnPlay;
254249
}
255250

256251
private static void UnsubscribeFromEvents ()
@@ -261,7 +256,6 @@ private static void UnsubscribeFromEvents ()
261256
LastFilePath = null;
262257

263258
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
264-
UnityEditor.EditorApplication.playmodeStateChanged -= OnPlay;
265259
}
266260

267261
private static bool AutoUpdateEnabled ()
@@ -278,23 +272,6 @@ private static void UpdateLastSavedModel ()
278272

279273
LoadLastSavedModel ();
280274
}
281-
282-
private static void OnPlay()
283-
{
284-
if (!AutoUpdateEnabled ()) {
285-
UnsubscribeFromEvents ();
286-
return;
287-
}
288-
289-
// Right before we enter playmode, unload the last saved model if there is one.
290-
// Unsubscribe from hierarchy window changed event so that unloading the model doesn't
291-
// trigger a new one to be added right before playing.
292-
if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && !UnityEditor.EditorApplication.isPlaying) {
293-
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
294-
UnloadModel (LastModel);
295-
LastModel = null;
296-
}
297-
}
298275
}
299276
}
300277
}

Assets/FbxExporters/RotateModel.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
using System.Collections;
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+
// ***********************************************************************
7+
8+
using System.Collections;
29
using System.Collections.Generic;
310
using UnityEngine;
411

5-
public class RotateModel : MonoBehaviour {
12+
namespace FbxExporters.Review
13+
{
14+
public class RotateModel : MonoBehaviour
15+
{
16+
17+
[Tooltip ("Rotation speed in degrees/second")]
18+
[SerializeField]
19+
private float speed = 10f;
20+
21+
public float GetSpeed()
22+
{
23+
return speed;
24+
}
625

7-
[Tooltip("Rotation speed in degrees/second")]
8-
[SerializeField]
9-
private float speed = 10f;
10-
11-
void Update () {
12-
transform.Rotate (Vector3.up, speed * Time.deltaTime, Space.World);
26+
void Update ()
27+
{
28+
transform.Rotate (Vector3.up, speed * Time.deltaTime, Space.World);
29+
}
1330
}
1431
}

0 commit comments

Comments
 (0)