// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using Microsoft.MixedReality.Toolkit.Utilities.Editor; using UnityEngine.Events; namespace Microsoft.MixedReality.Toolkit.UI { /// /// A basic touch event receiver for detecting Physical Touch state changes in the Interactable /// When the physical touch states change, these events are triggered. /// public class InteractableOnTouchReceiver : ReceiverBase { /// /// Invoked when touch has left the object /// [InspectorField(Type = InspectorField.FieldTypes.Event, Label = "On Touch End", Tooltip = "Touch has left the object")] public UnityEvent OnTouchEnd = new UnityEvent(); /// /// Invoked when touch begins /// public UnityEvent OnTouchStart => uEvent; private bool hadTouch; /// /// Receiver for raising touch begin and end events /// public InteractableOnTouchReceiver(UnityEvent ev) : base(ev, "OnTouch") { } /// /// Receiver for raising touch begin and end events /// public InteractableOnTouchReceiver() : this(new UnityEvent()) { } /// public override void OnUpdate(InteractableStates state, Interactable source) { bool hadTouch = state.GetState(InteractableStates.InteractableStateEnum.PhysicalTouch).Value > 0; if (this.hadTouch != hadTouch) { if (hadTouch) { uEvent.Invoke(); } else { OnTouchEnd.Invoke(); } } this.hadTouch = hadTouch; } } }