VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVRUI_ClickDragWheel.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5 using UnityEngine.Events;
6 
7 using AVR;
8 using AVR.Core;
9 
10 namespace AVR.UI.Utils {
11  [RequireComponent(typeof(LineRenderer))]
12  public class AVRUI_ClickDragWheel : MonoBehaviour
13  {
14  public GameObject entryPrefab;
15  public bool test = false;
16  public float radius = 100.0f;
17  public float select_radius = 50.0f;
18  public Color overlayColor;
19 
21 
24 
25  [System.Serializable]
26  public class ClickDragWheelEntry {
27  public string name;
28  public Color color;
29  public UnityEvent OnSelectEvent;
30  [HideInInspector] public float min_angle;
31  [HideInInspector] public float max_angle;
33  }
34 
35  private LineRenderer lr;
37 
38  void Awake() {
39  lr = GetComponent<LineRenderer>();
40  RectTransform rect = GetComponent<RectTransform>();
41  rect.sizeDelta = new Vector2(radius * 2.0f, radius * 2.0f);
42 
43  float delta_angle = 360.0f / fields.Length;
44 
45  for (int i = 0; i < fields.Length; i++)
46  {
47  GameObject go = Instantiate(entryPrefab, this.transform);
48  ClickDragWheelEntry entry = fields[i];
49 
50  entry.prefabObject = go.GetComponent<AVRUI_ClickDragWheelEntryPrefab>();
51  entry.min_angle = i * delta_angle;
52  entry.max_angle = (i + 1) * delta_angle;
53  entry.prefabObject.initalize(entry, select_radius+(radius-select_radius)*0.5f);
54  }
55 
56  GameObject overlay = Instantiate(entryPrefab, this.transform);
58  tmp.color = overlayColor;
59  tmp.min_angle=0.0f;
60  tmp.max_angle=360.0f;
61  tmp.name = "";
62  overlay.GetComponent<AVRUI_ClickDragWheelEntryPrefab>().initalize(tmp,0.0f);
63  overlay.transform.localScale=new Vector3(select_radius/radius, select_radius/radius, 1.0f);
64  }
65 
66  void Start() {
67  }
68 
69  void Update() {
70  Vector2 selec = radius * VRInput.Instance.inputManager.getEventStatus(selectionAxis);
71 
72  lr.SetPositions(new Vector3[] {Vector3.zero, new Vector3(selec.x, selec.y)});
73 
74  float angle = Vector2.SignedAngle(selec, Vector2.up)+180.0f;
75 
76  selectedEntry = null;
77  foreach(ClickDragWheelEntry entry in fields) {
78  if(selec.magnitude > select_radius && angle>entry.min_angle && angle<entry.max_angle) {
79  entry.prefabObject.markSelected(true);
80  selectedEntry = entry;
81  }
82  else {
83  entry.prefabObject.markSelected(false);
84  }
85  }
86 
87  if (selectedEntry!=null && VRInput.Instance.inputManager.getEventStatus(selectionEvent))
88  {
89  selectedEntry.OnSelectEvent.Invoke();
90  Cancel();
91  }
93  Cancel();
94  }
95  }
96 
97  public void Cancel() {
98  gameObject.SetActive(false);
99  }
100  }
101 }
BoolEvent
Boolean-returning events of a controller.
string name
AVR_ControllerInputManager inputManager
Definition: VRInput.cs:23
Color color
Manages inputs of a controller such as button presses and track-pad inputs.
static VRInput Instance
Singleton instance of this class. There should only be one VRInput component.
Definition: VRInput.cs:19
AVR_ControllerInputManager.BoolEvent selectionEvent
float min_angle
AVRUI_ClickDragWheelEntryPrefab prefabObject
bool getEventStatus(BoolEvent type)
Returns the status of a given BoolEvent
UnityEvent OnSelectEvent
float max_angle
AVR_ControllerInputManager.Vec2Event selectionAxis
Vec2Event
2D vector returning events of a controller.
This class overrides the base Input with Input from our VR components, thus enabling UI Interaction w...
Definition: VRInput.cs:14