Skip to content

Commit cb49d03

Browse files
Merge pull request #392 from Unity-Technologies/improvements/stella/submenu-haptics
sub / settings menu haptics update
2 parents 3417cb7 + 31c4ed9 commit cb49d03

17 files changed

Lines changed: 956 additions & 497 deletions

Menus/MainMenu/MainMenu.cs

Lines changed: 418 additions & 395 deletions
Large diffs are not rendered by default.

Menus/MainMenu/Prefabs/MenuActionButton.prefab

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,11 @@ MonoBehaviour:
319319
m_Script: {fileID: 11500000, guid: d6fdf9e0896ac3f4e94809a2cb14ceb8, type: 3}
320320
m_Name:
321321
m_EditorClassIdentifier:
322+
m_ClickPulse: {fileID: 11400000, guid: f66cb0a158f54124aa4158bbad3ed702, type: 2}
323+
m_HoverPulse: {fileID: 11400000, guid: dd561ccb8162d1040adba0a7ea60eadc, type: 2}
324+
m_Description: {fileID: 114846824440974548}
325+
m_Title: {fileID: 114097649684237516}
322326
m_Button: {fileID: 114000011038114608}
323-
m_ButtonDescription: {fileID: 114846824440974548}
324-
m_ButtonTitle: {fileID: 114097649684237516}
325327
--- !u!114 &114000012975115684
326328
MonoBehaviour:
327329
m_ObjectHideFlags: 1
@@ -727,7 +729,7 @@ RectTransform:
727729
m_LocalEulerAnglesHint: {x: 0, y: 0, z: -90}
728730
m_AnchorMin: {x: 0.20215935, y: -1.0582141}
729731
m_AnchorMax: {x: 0.4918094, y: 2.0516362}
730-
m_AnchoredPosition: {x: 0, y: 0.0000038146973}
732+
m_AnchoredPosition: {x: 0, y: 0}
731733
m_SizeDelta: {x: 0, y: 0}
732734
m_Pivot: {x: 0.5, y: 0.5}
733735
--- !u!224 &224000011878397100
@@ -763,7 +765,7 @@ RectTransform:
763765
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
764766
m_AnchorMin: {x: 0, y: 0}
765767
m_AnchorMax: {x: 1, y: 1}
766-
m_AnchoredPosition: {x: 2.6, y: -0.0024712086}
768+
m_AnchoredPosition: {x: 0, y: 0}
767769
m_SizeDelta: {x: 5.3, y: 0}
768770
m_Pivot: {x: 0.5, y: 0.5}
769771
--- !u!224 &224000013226195212
@@ -801,7 +803,7 @@ RectTransform:
801803
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
802804
m_AnchorMin: {x: 0.00008987377, y: 0.006534843}
803805
m_AnchorMax: {x: 0.9659295, y: 1}
804-
m_AnchoredPosition: {x: 4.737492, y: 0}
806+
m_AnchoredPosition: {x: 0, y: 0}
805807
m_SizeDelta: {x: 9.475, y: 0}
806808
m_Pivot: {x: 0.5, y: 0.5}
807809
--- !u!224 &224000013707443896

Menus/MainMenu/Prefabs/MenuButton.prefab

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ MonoBehaviour:
127127
m_Script: {fileID: 11500000, guid: d6fdf9e0896ac3f4e94809a2cb14ceb8, type: 3}
128128
m_Name:
129129
m_EditorClassIdentifier:
130+
m_ClickPulse: {fileID: 11400000, guid: f66cb0a158f54124aa4158bbad3ed702, type: 2}
131+
m_HoverPulse: {fileID: 11400000, guid: dd561ccb8162d1040adba0a7ea60eadc, type: 2}
132+
m_Description: {fileID: 114538117545747488}
133+
m_Title: {fileID: 114736413251300290}
130134
m_Button: {fileID: 114000011038114608}
131-
m_ButtonDescription: {fileID: 114538117545747488}
132-
m_ButtonTitle: {fileID: 114736413251300290}
133135
--- !u!114 &114000013676702038
134136
MonoBehaviour:
135137
m_ObjectHideFlags: 1

Menus/MainMenu/Scripts/MainMenuButton.cs

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,69 @@
66
using UnityEngine.EventSystems;
77
using UnityEngine.UI;
88

9-
#if INCLUDE_TEXT_MESH_PRO
10-
using TMPro;
11-
#endif
12-
139
[assembly: OptionalDependency("TMPro.TextMeshProUGUI", "INCLUDE_TEXT_MESH_PRO")]
1410

1511
namespace UnityEditor.Experimental.EditorVR.Menus
1612
{
17-
sealed class MainMenuButton : MonoBehaviour, ITooltip, IRayEnterHandler, IRayExitHandler, IPointerClickHandler
13+
sealed class MainMenuButton : MainMenuSelectable, ITooltip, IRayEnterHandler, IRayExitHandler, IPointerClickHandler
1814
{
1915
[SerializeField]
2016
Button m_Button;
2117

22-
#if INCLUDE_TEXT_MESH_PRO
23-
[SerializeField]
24-
TextMeshProUGUI m_ButtonDescription;
25-
#endif
26-
27-
#if INCLUDE_TEXT_MESH_PRO
28-
[SerializeField]
29-
TextMeshProUGUI m_ButtonTitle;
30-
#endif
31-
32-
Color m_OriginalColor;
18+
CanvasGroup m_CanvasGroup;
3319

3420
public Button button { get { return m_Button; } }
3521

3622
public string tooltipText { get { return tooltip != null ? tooltip.tooltipText : null; } }
3723

3824
public ITooltip tooltip { private get; set; }
3925

40-
public Type toolType { get; set; }
41-
42-
public bool selected
43-
{
44-
set
45-
{
46-
if (value)
47-
{
48-
m_Button.transition = Selectable.Transition.None;
49-
m_Button.targetGraphic.color = m_Button.colors.highlightedColor;
50-
}
51-
else
52-
{
53-
m_Button.transition = Selectable.Transition.ColorTint;
54-
m_Button.targetGraphic.color = m_OriginalColor;
55-
}
56-
}
57-
}
58-
5926
public event Action<Transform, Type, string> hovered;
6027
public event Action<Transform> clicked;
6128

62-
void Awake()
29+
new void Awake()
6330
{
31+
m_Selectable = m_Button;
6432
m_OriginalColor = m_Button.targetGraphic.color;
6533
}
6634

67-
public void SetData(string name, string description)
35+
void Start()
6836
{
69-
#if INCLUDE_TEXT_MESH_PRO
70-
m_ButtonTitle.text = name;
71-
m_ButtonDescription.text = description;
72-
#endif
37+
m_CanvasGroup = m_Button.GetComponentInParent<CanvasGroup>();
7338
}
7439

7540
public void OnRayEnter(RayEventData eventData)
7641
{
42+
if (m_CanvasGroup && !m_CanvasGroup.interactable)
43+
return;
44+
7745
#if INCLUDE_TEXT_MESH_PRO
78-
if (hovered != null)
79-
hovered(eventData.rayOrigin, toolType, m_ButtonDescription.text);
46+
if (button.interactable && hovered != null)
47+
{
48+
var descriptionText = string.Empty;
49+
// We can't use ?? because it breaks on destroyed references
50+
if (m_Description)
51+
descriptionText = m_Description.text;
52+
hovered(eventData.rayOrigin, toolType, descriptionText);
53+
}
8054
#endif
8155
}
8256

8357
public void OnRayExit(RayEventData eventData)
8458
{
85-
if (hovered != null)
59+
if (m_CanvasGroup && !m_CanvasGroup.interactable)
60+
return;
61+
62+
if (button.interactable && hovered != null)
8663
hovered(eventData.rayOrigin, null, null);
8764
}
8865

8966
public void OnPointerClick(PointerEventData eventData)
9067
{
91-
if (clicked != null)
68+
if (m_CanvasGroup && !m_CanvasGroup.interactable)
69+
return;
70+
71+
if (button.interactable && clicked != null)
9272
clicked(null); // Pass null to perform the selection haptic pulse on both nodes
9373
}
9474
}

Menus/MainMenu/Scripts/MainMenuFace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void AddSubmenu(Transform submenu)
181181
visible = false;
182182
}
183183

184-
public void RemoveSubmenu()
184+
public void RemoveSubmenu(Transform rayOrigin)
185185
{
186186
var target = m_Submenus.Pop();
187187
target.SetActive(false);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#if UNITY_EDITOR
2+
using System;
3+
using UnityEditor.Experimental.EditorVR;
4+
using UnityEngine;
5+
using UnityEngine.UI;
6+
using UnityEditor.Experimental.EditorVR.Core;
7+
8+
#if INCLUDE_TEXT_MESH_PRO
9+
using TMPro;
10+
#endif
11+
12+
[assembly: OptionalDependency("TMPro.TextMeshProUGUI", "INCLUDE_TEXT_MESH_PRO")]
13+
14+
namespace UnityEditor.Experimental.EditorVR.Menus
15+
{
16+
abstract class MainMenuSelectable : MonoBehaviour
17+
{
18+
protected Selectable m_Selectable;
19+
20+
#if INCLUDE_TEXT_MESH_PRO
21+
[SerializeField]
22+
protected TextMeshProUGUI m_Description;
23+
24+
[SerializeField]
25+
protected TextMeshProUGUI m_Title;
26+
#endif
27+
28+
protected Color m_OriginalColor;
29+
30+
public Type toolType { get; set; }
31+
32+
public bool selected
33+
{
34+
set
35+
{
36+
if (value)
37+
{
38+
m_Selectable.transition = Selectable.Transition.None;
39+
m_Selectable.targetGraphic.color = m_Selectable.colors.highlightedColor;
40+
}
41+
else
42+
{
43+
m_Selectable.transition = Selectable.Transition.ColorTint;
44+
m_Selectable.targetGraphic.color = m_OriginalColor;
45+
}
46+
}
47+
}
48+
49+
protected void Awake()
50+
{
51+
m_OriginalColor = m_Selectable.targetGraphic.color;
52+
}
53+
54+
public void SetData(string name, string description)
55+
{
56+
#if INCLUDE_TEXT_MESH_PRO
57+
m_Title.text = name;
58+
if (m_Description != null)
59+
m_Description.text = description;
60+
#endif
61+
}
62+
}
63+
}
64+
#endif
65+

Menus/MainMenu/Scripts/MainMenuSelectable.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#if UNITY_EDITOR
2+
using System;
3+
using UnityEditor.Experimental.EditorVR;
4+
using UnityEditor.Experimental.EditorVR.Modules;
5+
using UnityEngine;
6+
using UnityEngine.EventSystems;
7+
using UnityEngine.UI;
8+
9+
[assembly: OptionalDependency("TMPro.TextMeshProUGUI", "INCLUDE_TEXT_MESH_PRO")]
10+
11+
namespace UnityEditor.Experimental.EditorVR.Menus
12+
{
13+
sealed class MainMenuToggle : MainMenuSelectable, IRayEnterHandler, IRayExitHandler, IPointerClickHandler
14+
{
15+
[SerializeField]
16+
Toggle m_Toggle;
17+
18+
CanvasGroup m_CanvasGroup;
19+
20+
public Toggle toggle { get { return m_Toggle; } }
21+
22+
public event Action<Transform> hovered;
23+
public event Action<Transform> clicked;
24+
25+
new void Awake()
26+
{
27+
m_Selectable = m_Toggle;
28+
m_OriginalColor = m_Toggle.targetGraphic.color;
29+
}
30+
31+
void Start()
32+
{
33+
m_CanvasGroup = m_Toggle.GetComponentInParent<CanvasGroup>();
34+
}
35+
36+
public void OnRayEnter(RayEventData eventData)
37+
{
38+
if (m_CanvasGroup && !m_CanvasGroup.interactable)
39+
return;
40+
41+
if (m_Toggle.interactable && hovered != null)
42+
hovered(eventData.rayOrigin);
43+
}
44+
45+
public void OnRayExit(RayEventData eventData)
46+
{
47+
if (m_CanvasGroup && !m_CanvasGroup.interactable)
48+
return;
49+
50+
if (m_Toggle.interactable && hovered != null)
51+
hovered(eventData.rayOrigin);
52+
}
53+
54+
public void OnPointerClick(PointerEventData eventData)
55+
{
56+
if (m_CanvasGroup && !m_CanvasGroup.interactable)
57+
return;
58+
59+
if (m_Toggle.interactable && clicked != null)
60+
clicked(null); // Pass null to perform the selection haptic pulse on both nodes
61+
}
62+
}
63+
}
64+
#endif

Menus/MainMenu/Scripts/MainMenuToggle.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Scripts/Modules/SnappingModule/HapticPulses.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)