Skip to content

Commit

Permalink
Merge pull request #452 from Unity-Technologies/staging
Browse files Browse the repository at this point in the history
0.1.1 staging > master
  • Loading branch information
mtschoen-unity authored Dec 12, 2017
2 parents 8b28a2f + 14f239f commit efa8307
Show file tree
Hide file tree
Showing 105 changed files with 6,658 additions and 5,427 deletions.
3 changes: 2 additions & 1 deletion Actions/Delete.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if UNITY_EDITOR
using System;
using UnityEditor.Experimental.EditorVR.Utilities;
using UnityEngine;

namespace UnityEditor.Experimental.EditorVR.Actions
Expand All @@ -19,6 +18,8 @@ public override void ExecuteAction()
this.DeleteSceneObject(go);
}

UnityEditor.Undo.IncrementCurrentGroup();

Selection.activeGameObject = null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Actions/Icons/RedoIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Actions/Icons/UndoIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion Editor/EditingContextManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ void Awake()
public override void OnInspectorGUI()
{
GUILayout.Label("Available Contexts");
EditingContextManager.DoGUI(m_ContextNames, ref m_SelectedContextIndex, () => { m_Settings.defaultContextName = m_ContextNames[m_SelectedContextIndex]; });

m_SelectedContextIndex = EditorGUILayout.Popup(string.Empty, m_SelectedContextIndex, m_ContextNames);
if (GUI.changed)
{
m_Settings.defaultContextName = m_ContextNames[m_SelectedContextIndex];
GUIUtility.ExitGUI();
}

EditorGUILayout.Space();

Expand Down
145 changes: 145 additions & 0 deletions Editor/ProxyFeedbackEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#if UNITY_2017_2_OR_NEWER
using System;
using System.Collections.Generic;
using UnityEditor.Experimental.EditorVR.Modules;
using UnityEditor.Experimental.EditorVR.Proxies;
using UnityEngine;

namespace UnityEditor.Experimental.EditorVR.UI
{
sealed class ProxyFeedbackEditor : EditorWindow
{
readonly Dictionary<Type, SerializedProxyFeedback> m_SerializedFeedback = new Dictionary<Type, SerializedProxyFeedback>();
Vector2 m_Scroll;

[MenuItem("Edit/Project Settings/EditorXR/Proxy Feedback")]
static void Init()
{
GetWindow<ProxyFeedbackEditor>("Proxy Feedback Editor").Show();
}

void OnEnable()
{
Refresh();
}

void OnGUI()
{
if (Event.current.Equals(Event.KeyboardEvent("^w")))
{
Close();
GUIUtility.ExitGUI();
}

if (GUILayout.Button("Reload Data"))
Refresh();

if (GUILayout.Button("Clear Data"))
{
ClearData();
Refresh();
}

if (GUILayout.Button("Save Data"))
{
SaveData();
Refresh();
}

m_Scroll = GUILayout.BeginScrollView(m_Scroll);
var hasFeedback = false;
foreach (var kvp in m_SerializedFeedback)
{
GUILayout.Label(kvp.Key.Name, EditorStyles.boldLabel);
DrawPreferences(kvp.Value);
hasFeedback = true;
}

if (!hasFeedback)
GUILayout.Label("No serialized feedback");

GUILayout.EndScrollView();
}

static void DrawPreferences(SerializedProxyFeedback feedback)
{
GUILayout.Label("Left Hand");
DrawNode(feedback.leftNode);
GUILayout.Label("Right Hand");
DrawNode(feedback.rightNode);
}

static void DrawNode(SerializedProxyNodeFeedback node)
{
var keys = node.keys;
var values = node.values;
for (var i = 0; i < keys.Length; i++)
{
var data = values[i];
data.presentations = EditorGUILayout.IntField(keys[i].ToString(), data.presentations);
}
}

void Refresh()
{
m_SerializedFeedback.Clear();
var preferences = SerializedPreferencesModule.DeserializePreferences(Core.EditorVR.serializedPreferences);
if (preferences == null)
return;

foreach (var kvp in preferences.items)
{
var type = kvp.Key;
if (typeof(TwoHandedProxyBase).IsAssignableFrom(type))
{
var item = kvp.Value;
Type payloadType = null;
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
payloadType = assembly.GetType(item.payloadType);
if (payloadType != null)
break;
}

if (payloadType == null)
continue;

var payload = (SerializedProxyFeedback)JsonUtility.FromJson(item.payload, payloadType);
m_SerializedFeedback[kvp.Key] = payload;
}
}
}

static void ClearData()
{
var preferences = SerializedPreferencesModule.DeserializePreferences(Core.EditorVR.serializedPreferences);
if (preferences == null)
return;

foreach (var kvp in new Dictionary<Type, SerializedPreferencesModule.SerializedPreferenceItem>(preferences.items))
{
var type = kvp.Key;
if (typeof(TwoHandedProxyBase).IsAssignableFrom(type))
preferences.Remove(type);
}

Core.EditorVR.serializedPreferences = JsonUtility.ToJson(preferences);
}

void SaveData()
{
var preferences = SerializedPreferencesModule.DeserializePreferences(Core.EditorVR.serializedPreferences);
if (preferences == null)
return;

var items = preferences.items;
foreach (var kvp in m_SerializedFeedback)
{
items[kvp.Key].payload = JsonUtility.ToJson(kvp.Value);
}

Core.EditorVR.serializedPreferences = JsonUtility.ToJson(preferences);
}
}
}
#endif
12 changes: 12 additions & 0 deletions Editor/ProxyFeedbackEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 69 additions & 13 deletions Menus/MainMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sealed class MainMenu : MonoBehaviour, IMainMenu, IConnectInterfaces, IInstantia
IRequestFeedback
{
const string k_SettingsMenuSectionName = "Settings";
const float k_MaxFlickDuration = 0.3f;

[SerializeField]
ActionMap m_ActionMap;
Expand Down Expand Up @@ -43,6 +44,8 @@ sealed class MainMenu : MonoBehaviour, IMainMenu, IConnectInterfaces, IInstantia
MainMenuUI m_MainMenuUI;
float m_LastRotationInput;
MenuHideFlags m_MenuHideFlags = MenuHideFlags.Hidden;
float m_RotationInputStartValue;
float m_RotationInputStartTime;
readonly Dictionary<Type, MainMenuButton> m_ToolButtons = new Dictionary<Type, MainMenuButton>();
readonly Dictionary<ISettingsMenuProvider, GameObject> m_SettingsMenus = new Dictionary<ISettingsMenuProvider, GameObject>();
readonly Dictionary<ISettingsMenuItemProvider, GameObject> m_SettingsMenuItems = new Dictionary<ISettingsMenuItemProvider, GameObject>();
Expand All @@ -53,7 +56,6 @@ sealed class MainMenu : MonoBehaviour, IMainMenu, IConnectInterfaces, IInstantia
public List<Type> menuWorkspaces { private get; set; }
public Dictionary<KeyValuePair<Type, Transform>, ISettingsMenuProvider> settingsMenuProviders { get; set; }
public Dictionary<KeyValuePair<Type, Transform>, ISettingsMenuItemProvider> settingsMenuItemProviders { get; set; }
public List<ActionMenuData> menuActions { get; set; }
public Transform targetRayOrigin { private get; set; }
public Node node { get; set; }

Expand All @@ -62,6 +64,7 @@ sealed class MainMenu : MonoBehaviour, IMainMenu, IConnectInterfaces, IInstantia
public Transform rayOrigin { private get; set; }

public Bounds localBounds { get { return m_MainMenuUI.localBounds; } }
public int priority { get { return 0; } }

public bool focus { get { return m_MainMenuUI.hovering; } }

Expand Down Expand Up @@ -142,23 +145,53 @@ public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeCon
var mainMenuInput = (MainMenuInput)input;
var rotationInput = -mainMenuInput.rotate.rawValue;

consumeControl(mainMenuInput.rotate);
consumeControl(mainMenuInput.blockY);

const float kFlickDeltaThreshold = 0.5f;
if ((this.GetDeviceType() != DeviceType.Vive && Mathf.Abs(rotationInput) >= kFlickDeltaThreshold
&& Mathf.Abs(m_LastRotationInput) < kFlickDeltaThreshold) || mainMenuInput.flickFace.wasJustReleased)

if (this.GetDeviceType() == DeviceType.Vive)
{
m_MainMenuUI.targetFaceIndex += (int)Mathf.Sign(rotationInput);
this.Pulse(node, m_FaceRotationPulse);
if (!Mathf.Approximately(rotationInput, 0f))
{
var time = Time.time;
if (Mathf.Approximately(m_LastRotationInput, 0f))
{
// Touch began
m_RotationInputStartValue = rotationInput;
m_RotationInputStartTime = time;
}
else
{
// Touch held
var distance = rotationInput - m_RotationInputStartValue;
var lastDistance = m_LastRotationInput - m_RotationInputStartValue;
if (Mathf.Abs(distance) >= kFlickDeltaThreshold
&& Mathf.Abs(lastDistance) < kFlickDeltaThreshold
&& time - m_RotationInputStartTime < k_MaxFlickDuration)
{
m_RotationInputStartValue = rotationInput;
m_RotationInputStartTime = time;
if (!m_MainMenuUI.rotating)
{
FlickMenu(distance);
}
}
}
}
}
else if (Mathf.Abs(rotationInput) >= kFlickDeltaThreshold
&& Mathf.Abs(m_LastRotationInput) < kFlickDeltaThreshold)
{
FlickMenu(rotationInput);
}

if (m_MenuHideFlags == 0)
consumeControl(mainMenuInput.flickFace);

m_LastRotationInput = rotationInput;
}

void FlickMenu(float rotationInput)
{
m_MainMenuUI.targetFaceIndex += (int)Mathf.Sign(rotationInput);
this.Pulse(node, m_FaceRotationPulse);
}

void OnDestroy()
{
if (m_MainMenuUI)
Expand Down Expand Up @@ -299,6 +332,11 @@ void OnButtonHovered(Transform rayOrigin, Type buttonType, string buttonDescript
this.PreviewInToolMenuButton(rayOrigin, buttonType, buttonDescription);
}

void OnToggleHovered(Transform rayOrigin)
{
this.Pulse(this.RequestNodeFromRayOrigin(rayOrigin), m_ButtonHoverPulse);
}

void SendVisibilityPulse()
{
this.Pulse(node, m_MenuHideFlags == 0 ? m_HidePulse : m_ShowPulse);
Expand Down Expand Up @@ -333,12 +371,29 @@ void AddSettingsMenu(ISettingsMenuProvider provider, MainMenuUI.ButtonData butto
{
buttonData.sectionName = k_SettingsMenuSectionName;

CreateFaceButton(buttonData, tooltip, () =>
var button = CreateFaceButton(buttonData, tooltip, () =>
{
var instance = m_MainMenuUI.AddSubmenu(k_SettingsMenuSectionName, provider.settingsMenuPrefab);
m_SettingsMenus[provider] = instance;
provider.settingsMenuInstance = instance;
AddToggleHaptics(instance);
});

button.hovered += OnButtonHovered;
button.clicked += OnButtonClicked;
}

void AddToggleHaptics(GameObject menuInstance)
{
var toggles = menuInstance.GetComponentsInChildren<MainMenuToggle>();
if (toggles != null && toggles.Length > 0)
{
foreach (var toggle in toggles)
{
toggle.hovered += OnToggleHovered;
toggle.clicked += OnButtonClicked;
}
}
}

public void RemoveSettingsMenu(ISettingsMenuProvider provider)
Expand All @@ -359,6 +414,7 @@ public void AddSettingsMenuItem(ISettingsMenuItemProvider provider)
var instance = m_MainMenuUI.CreateCustomButton(provider.settingsMenuItemPrefab, k_SettingsMenuSectionName);
m_SettingsMenuItems[provider] = instance;
provider.settingsMenuItemInstance = instance;
AddToggleHaptics(instance);
}

public void RemoveSettingsMenuItem(ISettingsMenuItemProvider provider)
Expand All @@ -376,7 +432,7 @@ public void RemoveSettingsMenuItem(ISettingsMenuItemProvider provider)

void ShowFeedback()
{
var tooltipText = this.GetDeviceType() == DeviceType.Vive ? "Press to Rotate Menu" : "Rotate Menu";
var tooltipText = this.GetDeviceType() == DeviceType.Vive ? "Swipe to Rotate Menu" : "Rotate Menu";
List<VRInputDevice.VRControl> controls;
if (m_Controls.TryGetValue("FlickFace", out controls))
{
Expand Down
Loading

0 comments on commit efa8307

Please sign in to comment.