Flip VRView texture as workaround for 2019.x;

Refactor project settings windows to be SettingsProviders
This commit is contained in:
Matt Schoen 2019-08-27 19:43:39 -07:00
Родитель 950ca3b4c9
Коммит 72d17e02be
12 изменённых файлов: 152 добавлений и 153 удалений

Просмотреть файл

@ -1,53 +0,0 @@
using System;
using UnityEngine;
namespace UnityEditor.Experimental.EditorVR.Core
{
[CustomEditor(typeof(EditingContextManagerSettings))]
sealed class EditingContextManagerEditor : Editor
{
string[] m_ContextNames;
int m_SelectedContextIndex;
EditingContextManagerSettings m_Settings;
void Awake()
{
m_ContextNames = EditingContextManager.GetEditingContextNames();
m_Settings = (EditingContextManagerSettings)target;
m_SelectedContextIndex = Array.IndexOf(m_ContextNames, m_Settings.defaultContextName);
}
public override void OnInspectorGUI()
{
GUILayout.Label("Available Contexts");
m_SelectedContextIndex = EditorGUILayout.Popup(string.Empty, m_SelectedContextIndex, m_ContextNames);
if (GUI.changed)
{
m_Settings.defaultContextName = m_ContextNames[m_SelectedContextIndex];
GUIUtility.ExitGUI();
}
EditorGUILayout.Space();
GUILayout.BeginHorizontal();
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("Save"))
{
EditingContextManager.SaveProjectSettings(m_Settings);
Selection.activeObject = null;
}
if (GUILayout.Button("Reset"))
{
EditingContextManager.ResetProjectSettings();
Selection.activeGameObject = null;
}
}
GUILayout.EndHorizontal();
}
}
}

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2a2d11b7a2dd9414baae977a15811abb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,18 @@
namespace UnityEditor.Experimental.EditorVR.UI
{
class EditorXRSettingsProvider : SettingsProvider
{
protected const string k_Path = "Project/EditorXR";
protected EditorXRSettingsProvider(string path, SettingsScope scope = SettingsScope.Project)
: base(path, scope) { }
[SettingsProvider]
public static SettingsProvider CreateEditorXRSettingsProvider()
{
var provider = new EditorXRSettingsProvider(k_Path);
return provider;
}
}
}

Просмотреть файл

@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: d3a9ecd7de8ff2c4fa4a85c66a8feda8
timeCreated: 1486770624
licenseType: Pro
guid: a9fd38642b90e3d4bb931dd513ab2b65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

Просмотреть файл

@ -1,13 +1,15 @@
#if UNITY_2018_3_OR_NEWER
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEditor.Experimental.EditorVR.Core;
using UnityEditor.Experimental.EditorVR.Modules;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.Experimental.EditorVR.UI
{
sealed class HapticPulseEditor : EditorWindow
class HapticPulsesSettingsProvider : EditorXRSettingsProvider
{
const string HapticPulsesPath = k_Path + "/Haptic Pulses";
class Pulse
{
public HapticPulse pulse;
@ -21,19 +23,37 @@ namespace UnityEditor.Experimental.EditorVR.UI
Vector2 m_Scroll;
float m_Multiplier = 1;
[MenuItem("Edit/Project Settings/EditorXR/Haptic Pulses")]
static void Init()
protected HapticPulsesSettingsProvider(string path, SettingsScope scope = SettingsScope.Project)
: base(path, scope) { }
[SettingsProvider]
public static SettingsProvider CreateHapticPulsesSettingsProvider()
{
GetWindow<HapticPulseEditor>("Haptic Pulse Editor").Show();
var provider = new HapticPulsesSettingsProvider(HapticPulsesPath);
return provider;
}
void OnEnable()
public override void OnActivate(string searchContext, VisualElement rootElement)
{
base.OnActivate(searchContext, rootElement);
Reset();
Undo.undoRedoPerformed += OnUndoRedo;
}
public override void OnDeactivate()
{
base.OnDeactivate();
Undo.undoRedoPerformed -= OnUndoRedo;
}
void OnUndoRedo()
{
Reset();
Repaint();
}
void Reset()
{
m_HapticPulses.Clear();
@ -55,18 +75,9 @@ namespace UnityEditor.Experimental.EditorVR.UI
}
}
void OnDisable()
public override void OnGUI(string searchContext)
{
Undo.undoRedoPerformed -= OnUndoRedo;
}
void OnGUI()
{
if (Event.current.Equals(Event.KeyboardEvent("^w")))
{
Close();
GUIUtility.ExitGUI();
}
base.OnGUI(searchContext);
const float nameColumnWidth = 250f;
const float floatFieldColumnWidth = 60f;
@ -121,18 +132,5 @@ namespace UnityEditor.Experimental.EditorVR.UI
GUILayout.EndScrollView();
}
void OnUndoRedo()
{
Reset();
Repaint();
}
void OnProjectChange()
{
Reset();
Repaint();
}
}
}
#endif

Просмотреть файл

@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: f18b2d6392976ca4ebf2ce08eba4236b
timeCreated: 1486770624
licenseType: Pro
guid: e8380a2a71d37754d813c441e0886528
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

Просмотреть файл

@ -1,35 +1,38 @@
#if UNITY_2018_3_OR_NEWER
using System;
using System;
using System.Collections.Generic;
using UnityEditor.Experimental.EditorVR.Modules;
using UnityEditor.Experimental.EditorVR.Proxies;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.Experimental.EditorVR.UI
{
sealed class ProxyFeedbackEditor : EditorWindow
class ProxyFeedbackSettingsProvider : EditorXRSettingsProvider
{
const string ProxyFeedbackPath = k_Path + "/Proxy Feedback";
readonly Dictionary<Type, SerializedProxyFeedback> m_SerializedFeedback = new Dictionary<Type, SerializedProxyFeedback>();
Vector2 m_Scroll;
[MenuItem("Edit/Project Settings/EditorXR/Proxy Feedback")]
static void Init()
protected ProxyFeedbackSettingsProvider(string path, SettingsScope scope = SettingsScope.Project)
: base(path, scope) { }
[SettingsProvider]
public static SettingsProvider CreateHapticPulsesSettingsProvider()
{
GetWindow<ProxyFeedbackEditor>("Proxy Feedback Editor").Show();
var provider = new ProxyFeedbackSettingsProvider(ProxyFeedbackPath);
return provider;
}
void OnEnable()
public override void OnActivate(string searchContext, VisualElement rootElement)
{
base.OnActivate(searchContext, rootElement);
Refresh();
}
void OnGUI()
public override void OnGUI(string searchContext)
{
if (Event.current.Equals(Event.KeyboardEvent("^w")))
{
Close();
GUIUtility.ExitGUI();
}
base.OnGUI(searchContext);
if (GUILayout.Button("Reload Data"))
Refresh();
@ -134,4 +137,3 @@ namespace UnityEditor.Experimental.EditorVR.UI
}
}
}
#endif

Просмотреть файл

@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: 7b1746cbbdd0f714f8e74b6ab77a2d67
timeCreated: 1486770624
licenseType: Pro
guid: 0be2e8e64bf0dee42b6c2b4dc5270cfa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

Просмотреть файл

@ -4,28 +4,33 @@ using System.Reflection;
using Unity.Labs.EditorXR.Interfaces;
using Unity.Labs.Utils;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.Experimental.EditorVR.UI
{
sealed class TooltipsEditor : EditorWindow
class TooltipsSettingsProvider : EditorXRSettingsProvider
{
const string HapticPulsesPath = k_Path + "/Tooltips";
readonly Dictionary<Type, ITooltip> m_TooltipAttributes = new Dictionary<Type, ITooltip>();
readonly List<Type> m_TooltipClasses = new List<Type>();
readonly Dictionary<ITooltip, GameObject> m_TooltipsInPrefabs = new Dictionary<ITooltip, GameObject>();
Vector2 m_Scroll;
GUIStyle m_ButtonStyle;
[MenuItem("Edit/Project Settings/EditorXR/Tooltips")]
static void Init()
protected TooltipsSettingsProvider(string path, SettingsScope scope = SettingsScope.Project)
: base(path, scope) { }
[SettingsProvider]
public static SettingsProvider CreateHapticPulsesSettingsProvider()
{
GetWindow<TooltipsEditor>("Tooltip Editor").Show();
var provider = new TooltipsSettingsProvider(HapticPulsesPath);
return provider;
}
void OnEnable()
public override void OnActivate(string searchContext, VisualElement rootElement)
{
m_ButtonStyle = new GUIStyle(EditorStyles.miniButton);
m_ButtonStyle.alignment = TextAnchor.MiddleLeft;
base.OnActivate(searchContext, rootElement);
m_TooltipsInPrefabs.Clear();
foreach (var path in AssetDatabase.GetAllAssetPaths())
@ -67,15 +72,12 @@ namespace UnityEditor.Experimental.EditorVR.UI
}
}
void OnGUI()
public override void OnGUI(string searchContext)
{
if (Event.current.Equals(Event.KeyboardEvent("^w")))
{
Close();
GUIUtility.ExitGUI();
}
base.OnGUI(searchContext);
const float columnWidth = 250f;
const float buttonWidth = 40;
EditorGUIUtility.labelWidth = columnWidth;
m_Scroll = GUILayout.BeginScrollView(m_Scroll);
@ -89,7 +91,9 @@ namespace UnityEditor.Experimental.EditorVR.UI
var mb = (MonoBehaviour)tooltip;
var label = string.Format("{0}/{1}", prefab.name, mb.name);
if (GUILayout.Button(label, m_ButtonStyle, GUILayout.Width(columnWidth)))
GUILayout.Label(label, GUILayout.Width(columnWidth));
if (GUILayout.Button("Ping", GUILayout.Width(buttonWidth)))
EditorGUIUtility.PingObject(prefab);
try

Просмотреть файл

@ -1,8 +1,7 @@
fileFormatVersion: 2
guid: 29b662520f19dc94792648a80927ebaa
timeCreated: 1486770624
licenseType: Pro
guid: 2409bf09e1b27ce4086583c6ec4e3f1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

Просмотреть файл

@ -146,46 +146,62 @@ namespace UnityEditor.Experimental.EditorVR.Core
return PlayerSettings.GetVirtualRealitySupported(BuildTargetGroup.Standalone);
}
[MenuItem("Edit/Project Settings/EditorXR/Default Editing Context")]
static void EditProjectSettings()
{
var settings = LoadProjectSettings();
settings.name = "Default Editing Context";
Selection.activeObject = settings;
}
#if UNITY_2018_3_OR_NEWER
[SettingsProvider]
static SettingsProvider CreateSettingsProvider()
{
var provider = new SettingsProvider("Project/EditorXR", SettingsScope.Project)
var contextNames = GetEditingContextNames();
if (string.IsNullOrEmpty(settings.defaultContextName))
settings.defaultContextName = defaultContext.name;
var selectedIndex = Array.IndexOf(contextNames, settings.defaultContextName);
var provider = new SettingsProvider("Project/EditorXR/Context Manager", SettingsScope.Project)
{
label = "EditorXR",
label = "Context Manager",
guiHandler = (searchContext) =>
{
EditorGUILayout.LabelField("Context Manager", EditorStyles.boldLabel);
EditorGUILayout.LabelField("Global Settings", EditorStyles.boldLabel);
using (new EditorGUILayout.HorizontalScope())
{
using (var changed = new EditorGUI.ChangeCheckScope())
{
selectedIndex = EditorGUILayout.Popup("Default Context", selectedIndex, contextNames);
if (changed.changed)
{
settings.defaultContextName = contextNames[selectedIndex];
SaveProjectSettings(settings);
GUIUtility.ExitGUI();
}
}
const float resetButtonWidth = 40f;
if (GUILayout.Button("Reset", EditorStyles.miniButton, GUILayout.Width(resetButtonWidth)))
{
ResetProjectSettings();
selectedIndex = 0;
}
}
// Auto open an EditorXR context
const string title = "Auto open";
const string tooltip = "Automatically open an EditorXR context when the HMD is being worn";
using (var change = new EditorGUI.ChangeCheckScope())
{
const string title = "Auto open";
const string tooltip = "Automatically open an EditorXR context when the HMD is being worn";
autoOpen = EditorGUILayout.Toggle(new GUIContent(title, tooltip), autoOpen);
using (var change = new EditorGUI.ChangeCheckScope())
if (change.changed)
OnAutoOpenStateChanged();
if (s_EnableXRFailed)
{
autoOpen = EditorGUILayout.Toggle(new GUIContent(title, tooltip), autoOpen);
if (change.changed)
OnAutoOpenStateChanged();
if (s_EnableXRFailed)
const float retryButtonWidth = 70f;
EditorGUILayout.HelpBox("Failed to initialize XR session. Check that your device and platform software are working properly.", MessageType.Warning);
if (GUILayout.Button("Retry", GUILayout.Width(retryButtonWidth)))
{
const float retryButtonWidth = 70f;
EditorGUILayout.HelpBox("Failed to initialize XR session. Check that your device and platform software are working properly.", MessageType.Warning);
if (GUILayout.Button("Retry", GUILayout.Width(retryButtonWidth)))
{
s_EnableXRFailed = false;
OnAutoOpenStateChanged();
}
s_EnableXRFailed = false;
OnAutoOpenStateChanged();
}
}
}

Просмотреть файл

@ -452,7 +452,17 @@ namespace UnityEditor.Experimental.EditorVR.Core
if (e.type == EventType.Repaint)
{
var renderTexture = customPreviewCamera && customPreviewCamera.targetTexture ? customPreviewCamera.targetTexture : m_TargetTexture;
GUI.DrawTexture(guiRect, renderTexture, ScaleMode.StretchToFill, false);
// TODO: Investigate texture flip issue in 2019.x
#if UNITY_2019_1_OR_NEWER
if (customPreviewCamera == null)
{
rect.y = height;
rect.height = -height;
}
#endif
GUI.DrawTexture(rect, renderTexture, ScaleMode.StretchToFill, false);
}
}