AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
InteractiveToggle.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine.Events;
6 
7 #if UNITY_WSA || UNITY_STANDALONE_WIN
8 using UnityEngine.Windows.Speech;
9 #endif
10 
11 namespace HoloToolkit.Examples.InteractiveElements
12 {
21  {
22 
26  public bool AllowSelection = true;
27 
28  public bool Selection
29  {
30  get { return AllowSelection; }
31  set
32  {
33  AllowSelection = value;
34  if (AllowSelection == false)
35  {
36  HasGaze = false;
37  }
38  }
39  }
40 
44  public bool AllowDeselect = true;
45 
49  public bool HasSelection = false;
50  public void SetSelection(bool selection)
51  {
52  HasSelection = selection;
53  }
54 
59  public bool PassiveMode = false;
60 
64 
65  public UnityEvent OnSelection;
66  public UnityEvent OnDeselection;
67 
71  protected override void Start()
72  {
73  IsSelected = HasSelection;
74 
75  base.Start();
76  }
77 
78  public void SetAllowSelect(bool allowSelect)
79  {
80  AllowSelection = allowSelect;
81  }
82 
83  public override void OnInputClicked(InputClickedEventData eventData)
84  {
85  if (PassiveMode || !IsEnabled)
86  {
87  return;
88  }
89 
90  base.OnInputClicked(eventData);
91 
92  ToggleLogic();
93  }
94 
95  public virtual void ToggleLogic()
96  {
97  if (AllowSelection)
98  {
99  if (AllowDeselect && IsSelected)
100  {
101  IsSelected = false;
102  if (!PassiveMode)
103  {
104  OnDeselection.Invoke();
105  }
106 
107  }
108  else if (!IsSelected)
109  {
110  IsSelected = true;
111  if (!PassiveMode)
112  {
113  OnSelection.Invoke();
114  }
115 
116  if (!AllowDeselect)
117  {
118  HasGaze = false;
119  }
120  }
121  }
122 
123  HasSelection = IsSelected;
124  }
125 
126  public void SetState(bool isSelected)
127  {
128  IsSelected = !isSelected;
129  ToggleLogic();
130  }
131 
132  public override void OnFocusEnter()
133  {
134  if (((AllowDeselect && IsSelected) || !IsSelected ) &&!PassiveMode)
135  {
136  base.OnFocusEnter();
137  }
138  }
139 
140  public override void OnFocusExit()
141  {
142  if (((AllowDeselect && IsSelected) || !IsSelected) && !PassiveMode)
143  {
144  base.OnFocusExit();
145  }
146  }
147 
148  public override void OnHold()
149  {
150  if (((AllowDeselect && IsSelected) || !IsSelected) && !PassiveMode)
151  {
152  base.OnHold();
153  }
154  }
155 
156  public override void OnInputDown(InputEventData eventData)
157  {
158  if (((AllowDeselect && IsSelected) || !IsSelected) && !PassiveMode)
159  {
160  base.OnInputDown(eventData);
161  }
162  }
163 
164  public override void OnInputUp(InputEventData eventData)
165  {
166 
167  if (((AllowDeselect && IsSelected) || !IsSelected) && !PassiveMode)
168  {
169  base.OnInputUp(eventData);
170  }
171  else
172  {
173  HasGaze = false;
174  HasDown = false;
175  UpdateEffects();
176  }
177  }
178 
182  protected override void Update()
183  {
184  if (!UserInitiatedEvent && IsSelected != HasSelection)
185  {
186  IsSelected = HasSelection;
187  }
188 
189  base.Update();
190 
191  }
192 
193 #if UNITY_WSA || UNITY_STANDALONE_WIN
194  protected override void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
195  {
196  base.KeywordRecognizer_OnPhraseRecognized(args);
197 
198  // Check to make sure the recognized keyword matches, then invoke the corresponding method.
199  if ((!KeywordRequiresGaze || HasGaze) && mKeywordDictionary != null)
200  {
201  int index;
202 
203  if (mKeywordDictionary.TryGetValue(args.text, out index))
204  {
205  HasSelection = index == 1;
206  }
207  }
208  }
209 #endif
210  }
211 }
override void OnHold()
The hold timer has finished
override void OnInputUp(InputEventData eventData)
All tab, hold, and gesture events are completed
override void OnInputDown(InputEventData eventData)
The user is initiating a tap or hold
override void Start()
Set default visual states on Start
override void OnFocusEnter()
The gameObject received gaze
override void OnFocusExit()
The gameObject no longer has gaze
InteractiveToggle expands Interactive to expose selection or toggle states.
Describes an input event that involves a tap.
override void Update()
Run timers and check for updates
Describes an input event that has a source id and a press kind.
Interactive exposes basic button type events to the Unity Editor and receives messages from the Gestu...
Definition: Interactive.cs:22
override void OnInputClicked(InputClickedEventData eventData)
An OnTap event occurred