diff --git a/Runtime/Interaction/HPUIBaseInteractable.cs b/Runtime/Interaction/HPUIBaseInteractable.cs index 2e14153..566ce4c 100644 --- a/Runtime/Interaction/HPUIBaseInteractable.cs +++ b/Runtime/Interaction/HPUIBaseInteractable.cs @@ -144,10 +144,10 @@ public bool HandlesGesture(HPUIGesture state) { switch (state) { case HPUIGesture.Tap: { - return TapEvent.GetPersistentEventCount() > 0; + return TapEvent.GetAllEventsCount() > 0; } case HPUIGesture.Gesture: { - return GestureEvent.GetPersistentEventCount() > 0; + return GestureEvent.GetAllEventsCount() > 0; } default: throw new InvalidOperationException($"Gesture state {state} is not handled by {typeof(HPUIBaseInteractable)}"); diff --git a/Runtime/Interaction/HPUIEvents.cs b/Runtime/Interaction/HPUIEvents.cs index b46b64e..326026d 100644 --- a/Runtime/Interaction/HPUIEvents.cs +++ b/Runtime/Interaction/HPUIEvents.cs @@ -8,8 +8,8 @@ namespace ubco.ovilab.HPUI.Interaction public enum HPUIGesture { None, - Tap, Gesture, - Custom // TODO: Custom gestures? + Tap, Gesture + // TODO: Custom gestures? } public enum HPUIGestureState @@ -18,8 +18,39 @@ public enum HPUIGestureState } #region events classes - public class HPUIInteractionEvent: UnityEvent - {} + public class HPUIInteractionEvent: UnityEvent where T: HPUIInteractionEventArgs + { + protected int eventsCount = 0; + + /// + /// Get total number of listeners. + /// + public int GetAllEventsCount() + { + return eventsCount + GetPersistentEventCount(); + } + + /// + public new void AddListener(UnityAction call) + { + base.AddListener(call); + eventsCount++; + } + + /// + public new void RemoveListener(UnityAction call) + { + base.RemoveListener(call); + eventsCount--; + RemoveAllListeners(); + } + + /// + public new void RemoveAllListeners() + { + eventsCount = 0; + } + } /// /// Event data associated with an gesture interaction on HPUI @@ -59,7 +90,7 @@ public virtual void SetParams(IHPUIInteractor interactor, IHPUIInteractable inte } [Serializable] - public class HPUITapEvent: UnityEvent + public class HPUITapEvent: HPUIInteractionEvent {} /// @@ -69,7 +100,7 @@ public class HPUITapEventArgs: HPUIInteractionEventArgs {} [Serializable] - public class HPUIGestureEvent: UnityEvent + public class HPUIGestureEvent: HPUIInteractionEvent {} /// diff --git a/Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs b/Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs index 258c8da..7182933 100644 --- a/Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs +++ b/Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs @@ -129,9 +129,8 @@ public void Update() interactor.OnGesture(gestureEventArgs); } break; - case HPUIGesture.Custom: - // TODO: custom gestures - throw new NotImplementedException(); + default: + throw new InvalidOperationException("Unknown gesture."); } state.previousPosition = currentPosition; diff --git a/Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs b/Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs index fc03973..31ed195 100644 --- a/Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs +++ b/Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs @@ -253,9 +253,8 @@ public void Update() interactor.OnGesture(gestureEventArgs); } break; - case HPUIGesture.Custom: - // TODO: custom gestures - throw new NotImplementedException(); + default: + throw new InvalidOperationException("Unknown gesture."); } previousPosition = currentPosition;