Skip to content

Commit 668367d

Browse files
Fix issue if scene camera clear flags are set to Nothing;
Fix issue where camera settings copy doesn't happen the first time you launch EXR after a domain reload
1 parent aec0f73 commit 668367d

6 files changed

Lines changed: 67 additions & 64 deletions

File tree

Editor/EditingContextManagerEditor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ void Awake()
2121
public override void OnInspectorGUI()
2222
{
2323
GUILayout.Label("Available Contexts");
24-
EditingContextManager.DoGUI(m_ContextNames, ref m_SelectedContextIndex, () => { m_Settings.defaultContextName = m_ContextNames[m_SelectedContextIndex]; });
24+
25+
m_SelectedContextIndex = EditorGUILayout.Popup(string.Empty, m_SelectedContextIndex, m_ContextNames);
26+
if (GUI.changed)
27+
{
28+
m_Settings.defaultContextName = m_ContextNames[m_SelectedContextIndex];
29+
GUIUtility.ExitGUI();
30+
}
2531

2632
EditorGUILayout.Space();
2733

Models/Vive/Materials/ViveController.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Material:
7575
- _SpecularHighlights: 1
7676
- _SrcBlend: 5
7777
- _UVSec: 0
78-
- _ZWrite: 0
78+
- _ZWrite: 1
7979
m_Colors:
8080
- _Color: {r: 1, g: 1, b: 1, a: 1}
8181
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Scripts/Core/Contexts/EditingContextManager.cs

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,32 @@ sealed class EditingContextManager : MonoBehaviour
2222

2323
const string k_LaunchOnExitPlaymode = "EditingContextManager.LaunchOnExitPlaymode";
2424

25+
IEditingContext m_CurrentContext;
26+
2527
internal static EditingContextManager s_Instance;
2628
static InputManager s_InputManager;
2729
static List<IEditingContext> s_AvailableContexts;
2830
static EditingContextManagerSettings s_Settings;
2931
static UnityObject s_DefaultContext;
30-
static IEditingContext s_CurrentContext;
3132

3233
string[] m_ContextNames;
3334
int m_SelectedContextIndex;
3435

36+
Rect m_EditingContextPopupRect = new Rect(0, 0, 150, 20); // Y and X position will be set based on window size
37+
3538
readonly List<IEditingContext> m_PreviousContexts = new List<IEditingContext>();
3639

3740
internal static IEditingContext defaultContext
3841
{
3942
get
4043
{
41-
var context = s_AvailableContexts.Find(c => c.Equals(s_DefaultContext)) ?? s_AvailableContexts.First();
44+
var availableContexts = GetAvailableEditingContexts();
45+
var context = availableContexts.Find(c => c.Equals(s_DefaultContext)) ?? availableContexts.First();
4246

43-
var defaultContextName = s_Settings.defaultContextName;
47+
var defaultContextName = settings.defaultContextName;
4448
if (!string.IsNullOrEmpty(defaultContextName))
4549
{
46-
var foundContext = s_AvailableContexts.Find(c => c.name == defaultContextName);
50+
var foundContext = availableContexts.Find(c => c.name == defaultContextName);
4751
if (foundContext != null)
4852
context = foundContext;
4953
}
@@ -52,20 +56,30 @@ internal static IEditingContext defaultContext
5256
}
5357
set
5458
{
55-
s_Settings.defaultContextName = value.name;
59+
settings.defaultContextName = value.name;
5660
}
5761
}
5862

5963
internal IEditingContext currentContext
6064
{
61-
get { return s_CurrentContext; }
65+
get { return m_CurrentContext; }
66+
}
67+
68+
static EditingContextManagerSettings settings
69+
{
70+
get
71+
{
72+
if (!s_Settings)
73+
s_Settings = LoadUserSettings();
74+
75+
return s_Settings;
76+
}
6277
}
6378

6479
static EditingContextManager()
6580
{
6681
VRView.viewEnabled += OnVRViewEnabled;
6782
VRView.viewDisabled += OnVRViewDisabled;
68-
VRView.cameraSetupStarted += OnCameraSetupStarted;
6983

7084
EditorApplication.update += ReopenOnExitPlaymode;
7185
}
@@ -82,11 +96,6 @@ static void OnVRViewDisabled()
8296
ObjectUtils.Destroy(s_InputManager.gameObject);
8397
}
8498

85-
public static IEditingContext OnCameraSetupStarted()
86-
{
87-
return s_CurrentContext;
88-
}
89-
9099
[MenuItem("Window/EditorXR %e", false)]
91100
internal static void ShowEditorVR()
92101
{
@@ -138,33 +147,31 @@ static void OnPlayModeStateChanged(PlayModeStateChange stateChange)
138147
void Awake()
139148
{
140149
s_DefaultContext = m_DefaultContext;
141-
}
142-
143-
void OnEnable()
144-
{
145-
s_Settings = LoadUserSettings();
146-
147-
ISetEditingContextMethods.getAvailableEditingContexts = GetAvailableEditingContexts;
148-
ISetEditingContextMethods.getPreviousEditingContexts = GetPreviousEditingContexts;
149-
ISetEditingContextMethods.setEditingContext = SetEditingContext;
150-
ISetEditingContextMethods.restorePreviousEditingContext = RestorePreviousContext;
151150

152151
var availableContexts = GetAvailableEditingContexts();
153152
m_ContextNames = availableContexts.Select(c => c.name).ToArray();
154153

155154
if (s_AvailableContexts.Count == 0)
156155
throw new Exception("You can't start EditorXR without at least one context. Try re-importing the package or use version control to restore the default context asset");
157156

158-
SetEditingContext(defaultContext);
159-
160157
if (s_AvailableContexts.Count > 1)
161158
VRView.afterOnGUI += OnVRViewGUI;
159+
}
160+
161+
void OnEnable()
162+
{
163+
ISetEditingContextMethods.getAvailableEditingContexts = GetAvailableEditingContexts;
164+
ISetEditingContextMethods.getPreviousEditingContexts = GetPreviousEditingContexts;
165+
ISetEditingContextMethods.setEditingContext = SetEditingContext;
166+
ISetEditingContextMethods.restorePreviousEditingContext = RestorePreviousContext;
162167

163168
// Force the window to repaint every tick, since we need live updating
164169
// This also allows scripts with [ExecuteInEditMode] to run
165170
EditorApplication.update += EditorApplication.QueuePlayerLoopUpdate;
166171

167172
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
173+
174+
SetEditingContext(defaultContext);
168175
}
169176

170177
void OnDisable()
@@ -175,46 +182,35 @@ void OnDisable()
175182

176183
VRView.afterOnGUI -= OnVRViewGUI;
177184

178-
if (s_CurrentContext != null)
185+
if (m_CurrentContext != null)
179186
{
180-
defaultContext = s_CurrentContext;
181-
s_CurrentContext.Dispose();
187+
defaultContext = m_CurrentContext;
188+
m_CurrentContext.Dispose();
182189
}
183190

184191
s_AvailableContexts = null;
185192

193+
SetEditingContext(null);
194+
186195
ISetEditingContextMethods.getAvailableEditingContexts = null;
187196
ISetEditingContextMethods.getPreviousEditingContexts = null;
188197
ISetEditingContextMethods.setEditingContext = null;
189198
ISetEditingContextMethods.restorePreviousEditingContext = null;
190199

191-
SaveUserSettings(s_Settings);
200+
SaveUserSettings(settings);
192201
}
193202
#endif
194203

195-
void OnVRViewGUI(EditorWindow window)
204+
void OnVRViewGUI(VRView view)
196205
{
197-
var view = (VRView)window;
198-
GUILayout.BeginArea(view.guiRect);
199-
{
200-
GUILayout.FlexibleSpace();
201-
GUILayout.BeginHorizontal();
202-
{
203-
DoGUI(m_ContextNames, ref m_SelectedContextIndex, () => SetEditingContext(s_AvailableContexts[m_SelectedContextIndex]));
204-
GUILayout.FlexibleSpace();
205-
}
206-
GUILayout.EndHorizontal();
207-
}
208-
GUILayout.EndArea();
209-
}
206+
var position = view.position;
207+
m_EditingContextPopupRect.y = position.height - m_EditingContextPopupRect.height;
208+
m_EditingContextPopupRect.x = position.width - m_EditingContextPopupRect.width;
210209

211-
internal static void DoGUI(string[] contextNames, ref int selectedContextIndex, Action callback = null)
212-
{
213-
selectedContextIndex = EditorGUILayout.Popup(string.Empty, selectedContextIndex, contextNames);
210+
m_SelectedContextIndex = EditorGUI.Popup(m_EditingContextPopupRect, string.Empty, m_SelectedContextIndex, m_ContextNames);
214211
if (GUI.changed)
215212
{
216-
if (callback != null)
217-
callback();
213+
SetEditingContext(s_AvailableContexts[m_SelectedContextIndex]);
218214
GUIUtility.ExitGUI();
219215
}
220216
}
@@ -224,16 +220,16 @@ internal void SetEditingContext(IEditingContext context)
224220
if (context == null)
225221
return;
226222

227-
if (s_CurrentContext != null)
223+
if (m_CurrentContext != null)
228224
{
229-
m_PreviousContexts.Insert(0, s_CurrentContext);
225+
m_PreviousContexts.Insert(0, m_CurrentContext);
230226

231-
if (s_CurrentContext.instanceExists)
232-
s_CurrentContext.Dispose();
227+
if (m_CurrentContext.instanceExists)
228+
m_CurrentContext.Dispose();
233229
}
234230

235231
context.Setup();
236-
s_CurrentContext = context;
232+
m_CurrentContext = context;
237233

238234
m_SelectedContextIndex = s_AvailableContexts.IndexOf(context);
239235
}

Scripts/Core/Contexts/EditorVRContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class EditorVRContext : ScriptableObject, IEditingContext
1414
float m_RenderScale = 1f;
1515

1616
[SerializeField]
17-
bool m_CopySceneCameraSettings = true;
17+
bool m_CopyExistingCameraSettings = true;
1818

1919
[SerializeField]
2020
internal List<MonoScript> m_DefaultToolStack;
2121

2222
EditorVR m_Instance;
2323

24-
public bool copySceneCameraSettings { get { return m_CopySceneCameraSettings; } }
24+
public bool copyExistingCameraSettings { get { return m_CopyExistingCameraSettings; } }
2525

2626
public bool instanceExists { get { return m_Instance != null; } }
2727

Scripts/Core/VRView.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static Camera customPreviewCamera
5959
bool m_UseCustomPreviewCamera;
6060

6161
Rect m_ToggleDeviceViewRect = new Rect(0, 0, 0, 20); // Width will be set based on window size
62-
Rect m_PresentationCameraRect = new Rect(0, 0, 0, 20); // Y position and width will be set based on window size
62+
Rect m_PresentationCameraRect = new Rect(0, 0, 160, 20); // Y position and width will be set based on window size
6363

6464
public static Transform cameraRig
6565
{
@@ -116,10 +116,9 @@ public static Vector3 headCenteredOrigin
116116

117117
public static event Action viewEnabled;
118118
public static event Action viewDisabled;
119-
public static event Action<EditorWindow> beforeOnGUI;
120-
public static event Action<EditorWindow> afterOnGUI;
119+
public static event Action<VRView> beforeOnGUI;
120+
public static event Action<VRView> afterOnGUI;
121121
public static event Action<bool> hmdStatusChange;
122-
public static event Func<IEditingContext> cameraSetupStarted;
123122

124123
public Rect guiRect { get; private set; }
125124

@@ -143,9 +142,9 @@ public void OnEnable()
143142
const float nearClipPlane = 0.01f;
144143
const float farClipPlane = 1000f;
145144

146-
var currentEditingContext = cameraSetupStarted != null ? cameraSetupStarted() : null;
147145
s_ExistingSceneMainCamera = Camera.main;
148-
if (currentEditingContext != null && currentEditingContext.copySceneCameraSettings && s_ExistingSceneMainCamera && s_ExistingSceneMainCamera.enabled)
146+
// TODO: Copy camera settings when changing contexts
147+
if (EditingContextManager.defaultContext.copyExistingCameraSettings && s_ExistingSceneMainCamera && s_ExistingSceneMainCamera.enabled)
149148
{
150149
GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags(k_CameraName, HideFlags.HideAndDontSave);
151150
m_Camera = ObjectUtils.CopyComponent(s_ExistingSceneMainCamera, cameraGO);
@@ -157,6 +156,9 @@ public void OnEnable()
157156

158157
m_Camera.nearClipPlane = nearClipPlane;
159158
}
159+
160+
if (m_Camera.clearFlags == CameraClearFlags.Nothing)
161+
m_Camera.clearFlags = CameraClearFlags.SolidColor;
160162
}
161163
else
162164
{
@@ -315,7 +317,6 @@ void OnGUI()
315317

316318
m_ToggleDeviceViewRect.width = width;
317319
m_PresentationCameraRect.y = height - m_PresentationCameraRect.height;
318-
m_PresentationCameraRect.width = width;
319320

320321
if (GUI.Button(m_ToggleDeviceViewRect, "Toggle Device View", EditorStyles.toolbarButton))
321322
m_ShowDeviceView = !m_ShowDeviceView;

Scripts/Interfaces/Entity/IEditingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IEditingContext
1717
/// <summary>
1818
/// Bool denotes that the scene camera's (component) values should be cloned on the XR runtime camera
1919
/// </summary>
20-
bool copySceneCameraSettings { get; }
20+
bool copyExistingCameraSettings { get; }
2121

2222
/// <summary>
2323
/// Bool denotes that the EditorVR instance exists, having already been created in Setup()

0 commit comments

Comments
 (0)