From b2a14f77638fdf2d924a413542f3d36f99c36b43 Mon Sep 17 00:00:00 2001 From: Javier Meza Date: Fri, 30 Sep 2016 12:46:27 -0500 Subject: [PATCH] Toggle Behaviour --- .gitignore | 3 +++ Assets/Scripts/RadialMenu/MenuOpener.cs | 14 ++++++++++++-- Assets/Scripts/RadialMenu/RadialButton.cs | 8 +++++--- Assets/Scripts/RadialMenu/RadialMenu.cs | 4 +++- Assets/Scripts/RadialMenu/RadialMenuSpawner.cs | 14 +++++++------- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index dad481d..c9dfebd 100644 --- a/.gitignore +++ b/.gitignore @@ -129,3 +129,6 @@ captures/ ### Android Patch ### gen-external-apklibs + +### MacVIM ### +*.swp diff --git a/Assets/Scripts/RadialMenu/MenuOpener.cs b/Assets/Scripts/RadialMenu/MenuOpener.cs index c97d3ac..3956cc0 100644 --- a/Assets/Scripts/RadialMenu/MenuOpener.cs +++ b/Assets/Scripts/RadialMenu/MenuOpener.cs @@ -13,8 +13,10 @@ public struct RadialMenuOption { public class MenuOpener : MonoBehaviour, IGvrGazeResponder { public RadialMenuSpawner Spawner; - public RadialMenuOption[] options; + public bool UseToggleBehaviour; + + private bool shown = false; public void OnGazeEnter() { } @@ -23,6 +25,14 @@ public void OnGazeExit() { } public void OnGazeTrigger() { - Spawner.SpawnMenu (options); + if(!shown) { + Spawner.SpawnMenu(options, UseToggleBehaviour); + } else { + Spawner.CloseMenu(); + } + + if(UseToggleBehaviour) { + shown = !shown; + } } } diff --git a/Assets/Scripts/RadialMenu/RadialButton.cs b/Assets/Scripts/RadialMenu/RadialButton.cs index abec4b3..b2c0f6e 100644 --- a/Assets/Scripts/RadialMenu/RadialButton.cs +++ b/Assets/Scripts/RadialMenu/RadialButton.cs @@ -8,10 +8,10 @@ public class RadialButton : MonoBehaviour, IGvrGazeResponder { public Image Circle; public Image Icon; - public string Title; public RadialMenu Menu; public Text Label; public UnityEvent OnClick; + public bool UseToggleBehaviour; private Color defaultColor; @@ -29,8 +29,10 @@ public void OnGazeExit() { public void OnGazeTrigger() { Menu.Selected = this; - - Menu.Close(); + + if(!UseToggleBehaviour) { + Menu.Close(); + } } void Start () { diff --git a/Assets/Scripts/RadialMenu/RadialMenu.cs b/Assets/Scripts/RadialMenu/RadialMenu.cs index 2f13a20..17709ff 100644 --- a/Assets/Scripts/RadialMenu/RadialMenu.cs +++ b/Assets/Scripts/RadialMenu/RadialMenu.cs @@ -5,6 +5,7 @@ public class RadialMenu : MonoBehaviour { public RadialButton ButtonPrefab; public RadialButton Selected; + public bool UseToggleBehaviour; // Use this for initialization public void SpawnButtons (RadialMenuOption[] options) { @@ -21,10 +22,11 @@ public void SpawnButtons (RadialMenuOption[] options) { button.transform.localPosition = position; button.Icon.sprite = options [i].icon; - button.Title = options [i].title; + button.Label.text = options [i].title; button.Circle.color = options [i].color; button.Menu = this; button.OnClick = options [i].onClick; + button.UseToggleBehaviour = UseToggleBehaviour; } } diff --git a/Assets/Scripts/RadialMenu/RadialMenuSpawner.cs b/Assets/Scripts/RadialMenu/RadialMenuSpawner.cs index 2763109..b497145 100644 --- a/Assets/Scripts/RadialMenu/RadialMenuSpawner.cs +++ b/Assets/Scripts/RadialMenu/RadialMenuSpawner.cs @@ -3,21 +3,21 @@ public class RadialMenuSpawner : MonoBehaviour { - public static RadialMenuSpawner Instance = null; public RadialMenu MenuPrefab; - public void SpawnMenu (RadialMenuOption[] options) { - RadialMenu menu = (RadialMenu) Instantiate (MenuPrefab); + private RadialMenu menu; + + public void SpawnMenu (RadialMenuOption[] options, bool useToggleBehaviour) { + menu = (RadialMenu) Instantiate (MenuPrefab); menu.transform.SetParent (transform); menu.transform.position = transform.position; menu.transform.localScale = Vector3.one; + menu.UseToggleBehaviour = useToggleBehaviour; menu.SpawnButtons (options); } - void Awake () { - if (Instance == null) { - Instance = this; - } + public void CloseMenu () { + menu.Close(); } }