AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
HeadsetAdjustmentEditor.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using UnityEditor;
6 using UnityEngine;
7 using Object = UnityEngine.Object;
8 
9 namespace HoloToolkit.Unity
10 {
11  [CustomEditor(typeof(HeadsetAdjustment))]
12  public class HeadsetAdjustmentEditor : Editor
13  {
14  private static SceneAsset sceneAsset;
15  private static Object sceneObj;
16  private static HeadsetAdjustment myTarget;
17 
18  private void OnEnable()
19  {
20  myTarget = (HeadsetAdjustment)target;
21  sceneAsset = GetSceneObject(myTarget.NextSceneName);
22  }
23 
24  public override void OnInspectorGUI()
25  {
26  sceneObj = EditorGUILayout.ObjectField(
27  new GUIContent("Next Scene", "The name of the scene to load when the user is ready. If left empty, " +
28  "the next scene is loaded as specified in the 'Scenes in Build')"),
29  sceneAsset,
30  typeof(SceneAsset),
31  true);
32 
33  if (GUI.changed)
34  {
35  if (sceneObj == null)
36  {
37  sceneAsset = null;
38  myTarget.NextSceneName = string.Empty;
39  }
40  else
41  {
42  sceneAsset = GetSceneObject(sceneObj.name);
43  myTarget.NextSceneName = sceneObj.name;
44  }
45  }
46  }
47 
48  private static SceneAsset GetSceneObject(string sceneObjectName)
49  {
50  if (string.IsNullOrEmpty(sceneObjectName))
51  {
52  return null;
53  }
54 
55  foreach (EditorBuildSettingsScene editorScene in EditorBuildSettings.scenes)
56  {
57  if (editorScene.path.IndexOf(sceneObjectName, StringComparison.Ordinal) != -1)
58  {
59  return AssetDatabase.LoadAssetAtPath(editorScene.path, typeof(SceneAsset)) as SceneAsset;
60  }
61  }
62 
63  Debug.LogWarning("Scene [" + sceneObjectName + "] cannot be used. To use this scene add it to the build settings for the project.");
64  return null;
65  }
66  }
67 }