forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneSettingsWindow.cs
More file actions
225 lines (188 loc) · 10 KB
/
SceneSettingsWindow.cs
File metadata and controls
225 lines (188 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using HoloToolkit.Unity.InputModule;
using HoloToolkit.Unity.SpatialMapping;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using Cursor = HoloToolkit.Unity.InputModule.Cursor;
namespace HoloToolkit.Unity
{
/// <summary>
/// Renders the UI and handles update logic for MixedRealityToolkit/Configure/Apply Mixed Reality Scene Settings.
/// </summary>
public class SceneSettingsWindow : AutoConfigureWindow<SceneSettingsWindow.SceneSetting>
{
/// <summary>
/// Can be found in the meta file of the camera prefab. We use the GUID in case people move the toolkit folders & assets around in their own projects.
/// <remarks>Currently points to the MixedRealityCameraParent.prefab</remarks>
/// </summary>
private const string CameraPrefabGUID = "d29bc40b7f3df26479d6a0aac211c355";
/// <summary>
/// Can be found in the meta file of the input system prefab. We use the GUID in case people move the toolkit folders & assets around in their own projects.
/// <remarks>Currently points to InputManager.prefab</remarks>
/// </summary>
private const string InputSystemPrefabGUID = "3eddd1c29199313478dd3f912bfab2ab";
/// <summary>
/// Can be found in the meta file of the default cursor prefab. We use the GUID in case people move the toolkit folders & assets around in their own projects.
/// <remarks>Currently points to DefaultCursor.prefab</remarks>
/// </summary>
private const string DefaultCursorPrefabGUID = "a611e772ef8ddf64d8106a9cbb70f31c";
/// <summary>
/// Can be found in the meta file of the spatial mapping prefab. We use the GUID in case people move the toolkit folders & assets around in their own projects.
/// <remarks>Currently points to SpatialMapping.prefab</remarks>
/// </summary>
private const string SpatialMappingPrefabGUID = "2ed75ffdf9031c94e8bce4b3d17b9928";
#region Nested Types
public enum SceneSetting
{
AddMixedRealityCamera,
CameraToOrigin,
AddInputSystem,
AddDefaultCursor,
UpdateCanvases,
AddSpatialMapping
}
#endregion // Nested Types
#region Overrides / Event Handlers
protected override void ApplySettings()
{
if (Values[SceneSetting.AddMixedRealityCamera])
{
if (CameraCache.Main != null)
{
DestroyImmediate(CameraCache.Main.gameObject.GetParentRoot());
}
PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath(CameraPrefabGUID)));
}
if (Values[SceneSetting.CameraToOrigin])
{
var mainCamera = CameraCache.Refresh(Camera.main);
if (mainCamera == null)
{
Debug.LogWarning("Could not find a valid \"MainCamera\"! Unable to update camera position.");
}
else
{
mainCamera.transform.position = Vector3.zero;
}
}
if (Values[SceneSetting.AddInputSystem])
{
var inputManager = FindObjectOfType<InputManager>();
if (inputManager != null)
{
DestroyImmediate(inputManager.gameObject);
}
var eventSystems = FindObjectsOfType<EventSystem>();
foreach (var eventSystem in eventSystems)
{
DestroyImmediate(eventSystem.gameObject);
}
var inputModules = FindObjectsOfType<StandaloneInputModule>();
foreach (var inputModule in inputModules)
{
DestroyImmediate(inputModule.gameObject);
}
PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath(InputSystemPrefabGUID)));
Values[SceneSetting.UpdateCanvases] = true;
}
if (Values[SceneSetting.UpdateCanvases])
{
var focusManager = FindObjectOfType<FocusManager>();
if (focusManager != null)
{
FocusManager.Instance.UpdateCanvasEventSystems();
}
var sceneCanvases = Resources.FindObjectsOfTypeAll<Canvas>();
foreach (Canvas canvas in sceneCanvases)
{
var helper = canvas.EnsureComponent<CanvasHelper>();
helper.Canvas = canvas;
}
}
if (Values[SceneSetting.AddDefaultCursor])
{
var cursors = FindObjectsOfType<Cursor>();
foreach (var cursor in cursors)
{
DestroyImmediate(cursor.gameObject.GetParentRoot());
}
PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath(DefaultCursorPrefabGUID)));
FindObjectOfType<InputManager>().GetComponent<SimpleSinglePointerSelector>().Cursor = FindObjectOfType<Cursor>();
}
if (Values[SceneSetting.AddSpatialMapping])
{
var spatialMappingManagers = FindObjectsOfType<SpatialMappingManager>();
if (spatialMappingManagers.Length > 0)
{
Debug.LogWarning("There's already a SpatialMappingManager in the scene. Did not add the SpatialMapping prefab.");
}
else
{
PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath(SpatialMappingPrefabGUID)));
}
}
EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
Close();
}
protected override void LoadSettings()
{
for (int i = 0; i <= (int)SceneSetting.UpdateCanvases; i++)
{
Values[(SceneSetting)i] = true;
}
Values[SceneSetting.AddSpatialMapping] = false;
}
protected override void OnGuiChanged()
{
}
protected override void LoadStrings()
{
Names[SceneSetting.AddMixedRealityCamera] = "Add the Mixed Reality Camera Prefab";
Descriptions[SceneSetting.AddMixedRealityCamera] =
"Recommended\n\n" +
"Adds the Mixed Reality Camera Prefab to the scene.\n\n" +
"The prefab comes preset with all the components and options for automatically handling Occluded and Transparent Mixed Reality Applications.";
Names[SceneSetting.CameraToOrigin] = "Move Camera to Origin";
Descriptions[SceneSetting.CameraToOrigin] =
"Recommended\n\n" +
"Moves the main camera to the world origin of the scene (0, 0, 0).\n\n" +
"<color=#ffff00ff><b>Note:</b></color> When a Mixed Reality application starts, the users head is the center of the world. By not having your Main Camera centered at " +
"the world origin (0, 0, 0) will result in GameObjects not appearing where they are expected. This option should remain checked unless you have alternative methods " +
"that explicitly deal with any apparent offset.";
Names[SceneSetting.AddInputSystem] = "Add the Input Manager Prefab";
Descriptions[SceneSetting.AddInputSystem] =
"Recommended\n\n" +
"Adds the Input Manager Prefab to the scene.\n\n" +
"The prefab comes preset with all the components and options for automatically handling input for Mixed Reality Applications.\n\n" +
"<color=#ff0000ff><b>Warning!</b></color> This will remove and replace any currently existing Input Managers or Event Systems in your scene.";
Names[SceneSetting.AddDefaultCursor] = "Add the Default Cursor Prefab";
Descriptions[SceneSetting.AddDefaultCursor] =
"Recommended\n\n" +
"Adds the Default Cursor Prefab to the scene.\n\n" +
"The prefab comes preset with all the components and options for automatically handling cursor animations for Mixed Reality Applications.\n\n" +
"<color=#ff0000ff><b>Warning!</b></color> This will remove and replace any currently existing Cursors in your scene.";
Names[SceneSetting.UpdateCanvases] = "Update World Space Canvases";
Descriptions[SceneSetting.UpdateCanvases] =
"Recommended\n\n" +
"Updates all the World Space Canvases in the scene to use the Focus Managers UIRaycastCamera as its default event camera.\n\n" +
"<color=#ffff00ff><b>Note:</b></color> This also adds a CanvasHelper script to the canvas to aid in the scene transitions and instances where the camera does not " +
"initially exist in the same scene as the canvas.";
Names[SceneSetting.AddSpatialMapping] = "Add the Spatial Mapping Prefab";
Descriptions[SceneSetting.AddSpatialMapping] =
"Adds the Spatial Mapping Prefab to the scene.\n\n" +
"The prefab comes preset with the components and options for bringing spatial mapping into your HoloLens application.\n\n" +
"<color=#ff0000ff><b>Warning!</b></color> This will remove and replace any currently existing Spatial Mapping Managers in your scene.";
}
protected override void OnEnable()
{
base.OnEnable();
minSize = new Vector2(350, 250);
maxSize = minSize;
}
#endregion // Overrides / Event Handlers
}
}