AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
TriggerButton.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
8 {
12  public class TriggerButton : MonoBehaviour, IInputHandler
13  {
17  [Tooltip("Indicates whether the button is clickable or not.")]
18  public bool IsEnabled = true;
19 
20  public event Action ButtonPressed;
21 
25  public void Press()
26  {
27  if (IsEnabled)
28  {
29  ButtonPressed.RaiseEvent();
30  }
31  }
32 
34  {
35  // Nothing.
36  }
37 
38  void IInputHandler.OnInputUp(InputEventData eventData)
39  {
40  if (IsEnabled && eventData.PressType == InteractionSourcePressInfo.Select)
41  {
42  ButtonPressed.RaiseEvent();
43  eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.
44  }
45  }
46  }
47 }
Very simple class that implements basic logic for a trigger button.
void OnInputUp(InputEventData eventData)
void Press()
Press the button programmatically.
InteractionSourcePressInfo PressType
Button type that initiated the event.
Interface to implement to react to simple pointer-like input.
Describes an input event that has a source id and a press kind.
void OnInputDown(InputEventData eventData)