Skip to content

Commit

Permalink
FIx non-persistent events not being counted
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Jan 17, 2024
1 parent 25f42c0 commit a2fa64b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Runtime/Interaction/HPUIBaseInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}");
Expand Down
43 changes: 37 additions & 6 deletions Runtime/Interaction/HPUIEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,8 +18,39 @@ public enum HPUIGestureState
}

#region events classes
public class HPUIInteractionEvent: UnityEvent<HPUIInteractionEventArgs>
{}
public class HPUIInteractionEvent<T>: UnityEvent<T> where T: HPUIInteractionEventArgs
{
protected int eventsCount = 0;

/// <summary>
/// Get total number of listeners.
/// </summary>
public int GetAllEventsCount()
{
return eventsCount + GetPersistentEventCount();
}

/// <inheritdoc />
public new void AddListener(UnityAction<T> call)
{
base.AddListener(call);
eventsCount++;
}

/// <inheritdoc />
public new void RemoveListener(UnityAction<T> call)
{
base.RemoveListener(call);
eventsCount--;
RemoveAllListeners();
}

/// <inheritdoc />
public new void RemoveAllListeners()
{
eventsCount = 0;
}
}

/// <summary>
/// Event data associated with an gesture interaction on HPUI
Expand Down Expand Up @@ -59,7 +90,7 @@ public virtual void SetParams(IHPUIInteractor interactor, IHPUIInteractable inte
}

[Serializable]
public class HPUITapEvent: UnityEvent<HPUITapEventArgs>
public class HPUITapEvent: HPUIInteractionEvent<HPUITapEventArgs>
{}

/// <summary>
Expand All @@ -69,7 +100,7 @@ public class HPUITapEventArgs: HPUIInteractionEventArgs
{}

[Serializable]
public class HPUIGestureEvent: UnityEvent<HPUIGestureEventArgs>
public class HPUIGestureEvent: HPUIInteractionEvent<HPUIGestureEventArgs>
{}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a2fa64b

Please sign in to comment.