Skip to content

Commit

Permalink
Merge branch 'toggle-menu'
Browse files Browse the repository at this point in the history
  • Loading branch information
jemsz95 committed Sep 30, 2016
2 parents c9201c7 + b2a14f7 commit 2733e82
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,5 @@ captures/
### Android Patch ###
gen-external-apklibs


### MacVIM ###
*.swp
14 changes: 12 additions & 2 deletions Assets/Scripts/RadialMenu/MenuOpener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand All @@ -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;
}
}
}
7 changes: 5 additions & 2 deletions Assets/Scripts/RadialMenu/RadialButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class RadialButton : MonoBehaviour, IGvrGazeResponder {
public RadialMenu Menu;
public Text Label;
public UnityEvent OnClick;
public bool UseToggleBehaviour;

private Color defaultColor;

Expand All @@ -28,8 +29,10 @@ public void OnGazeExit() {

public void OnGazeTrigger() {
Menu.Selected = this;

Menu.Close();

if(!UseToggleBehaviour) {
Menu.Close();
}
}

void Start () {
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/RadialMenu/RadialMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -25,6 +26,7 @@ public void SpawnButtons (RadialMenuOption[] options) {
button.Circle.color = options [i].color;
button.Menu = this;
button.OnClick = options [i].onClick;
button.UseToggleBehaviour = UseToggleBehaviour;
}
}

Expand Down
14 changes: 7 additions & 7 deletions Assets/Scripts/RadialMenu/RadialMenuSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 2733e82

Please sign in to comment.