AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
PopupMenu.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 System;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.InputModule.Tests
8 {
9  public class PopupMenu : MonoBehaviour
10  {
11  [SerializeField]
12  private TestButton cancelButton = null;
13 
14  [SerializeField]
15  private Animator rootAnimator = null;
16 
17  [SerializeField]
18  private bool isModal = false;
19 
20  [SerializeField]
21  private bool closeOnNonTargetedTap = false;
22 
26  private Action activatedCallback;
27 
31  private Action cancelledCallback;
32 
36  private Action deactivatedCallback;
37 
38  private int dehydrateButtonId;
39 
40  public PopupState CurrentPopupState = PopupState.Closed;
41 
42  public enum PopupState { Open, Closed }
43 
44  private void Awake()
45  {
46  gameObject.SetActive(false);
47 
48  if (dehydrateButtonId == 0)
49  {
50  dehydrateButtonId = Animator.StringToHash("Dehydrate");
51  }
52  }
53 
54  private void OnEnable()
55  {
56  if (cancelButton != null)
57  {
58  cancelButton.Activated += OnCancelPressed;
59  }
60  }
61 
62  private void OnDisable()
63  {
64  if (cancelButton != null)
65  {
66  cancelButton.Activated -= OnCancelPressed;
67  }
68  }
69 
70  public void Show(Action _activatedCallback = null, Action _cancelledCallback = null, Action _deactivatedCallback = null)
71  {
72  activatedCallback = _activatedCallback;
73  cancelledCallback = _cancelledCallback;
74  deactivatedCallback = _deactivatedCallback;
75 
76  gameObject.SetActive(true);
77  CurrentPopupState = PopupState.Open;
78 
79  if (isModal)
80  {
81  InputManager.Instance.PushModalInputHandler(cancelButton.gameObject);
82  }
83 
84  if (closeOnNonTargetedTap)
85  {
86  InputManager.Instance.PushFallbackInputHandler(cancelButton.gameObject);
87  }
88 
89  // The visual was activated via an interaction outside of the menu. Let anyone who cares know.
90  if (activatedCallback != null)
91  {
92  activatedCallback();
93  }
94  }
95 
99  public void Dismiss()
100  {
101  if (deactivatedCallback != null)
102  {
103  deactivatedCallback();
104  }
105 
106  if (isModal)
107  {
108  InputManager.Instance.PopModalInputHandler();
109  }
110 
111  if (closeOnNonTargetedTap)
112  {
113  InputManager.Instance.PopFallbackInputHandler();
114  }
115 
116  CurrentPopupState = PopupState.Closed;
117 
118  activatedCallback = null;
119  cancelledCallback = null;
120  deactivatedCallback = null;
121 
122  if (cancelButton)
123  {
124  cancelButton.Selected = false;
125  }
126 
127  // Deactivates the game object
128  if (rootAnimator != null && rootAnimator.isInitialized)
129  {
130  rootAnimator.SetTrigger(dehydrateButtonId);
131  }
132  else
133  {
134  gameObject.SetActive(false);
135  }
136  }
137 
138  private void OnCancelPressed(TestButton source)
139  {
140  if (cancelButton.Focused || closeOnNonTargetedTap)
141  {
142  if (cancelledCallback != null)
143  {
144  cancelledCallback();
145  }
146 
147  Dismiss();
148  }
149  }
150  }
151 }
void Show(Action _activatedCallback=null, Action _cancelledCallback=null, Action _deactivatedCallback=null)
Definition: PopupMenu.cs:70
Input Manager is responsible for managing input sources and dispatching relevant events to the approp...
Definition: InputManager.cs:19
static T Instance
Returns the Singleton instance of the classes type. If no instance is found, then we search for an in...
Definition: Singleton.cs:26
Test button that can be added to any object to make it gaze interactable and receive pressed and rele...
Definition: TestButton.cs:13
void Dismiss()
Dismiss the details pane.
Definition: PopupMenu.cs:99