Skip to content

Commit

Permalink
All HPUI events reports position
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Jan 10, 2024
1 parent 7bce98b commit f448a65
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
13 changes: 10 additions & 3 deletions Runtime/Interaction/HPUIEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ public class HPUIInteractionEventArgs: BaseInteractionEventArgs
set => base.interactableObject = value;
}

public virtual void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable)
/// <summary>
/// The position of the interaction on the plane of the
/// interactable relative to its position.
/// </summary>
public virtual Vector2 Position { get; private set; }

public virtual void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable, Vector2 position)
{
interactorObject = interactor;
interactableObject = interactable;
Position = position;
}
}

Expand Down Expand Up @@ -78,15 +85,15 @@ public class HPUIGestureEventArgs: HPUIInteractionEventArgs
public float CumilativeDistance { get; private set; }
public Vector2 DeltaDirection { get; private set; }

public override void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable)
public override void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable, Vector2 position)
{
throw new InvalidOperationException("Call overloaded method!");
}

public void SetParams(IHPUIInteractor interactor, IHPUIInteractable interactable, HPUIGestureState state, float timeDelta, float startTime,
Vector2 startPosition, Vector2 cumilativeDirection, float cumilativeDistance, Vector2 deltaDirection)
{
base.SetParams(interactor, interactable);
base.SetParams(interactor, interactable, startPosition + cumilativeDirection);
State = state;
TimeDelta = timeDelta;
StartTime = startTime;
Expand Down
14 changes: 7 additions & 7 deletions Runtime/Interaction/Logic/HPUIGestureLogicDistributed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void OnSelectExiting(IHPUIInteractable interactable)
case HPUIGesture.Tap:
using (hpuiTapEventArgsPool.Get(out HPUITapEventArgs tapEventArgs))
{
tapEventArgs.SetParams(interactor, interactable);
tapEventArgs.SetParams(interactor, interactable, state.startPosition + state.cumilativeDirection);
interactable.OnTap(tapEventArgs);
interactor.OnTap(tapEventArgs);
}
Expand All @@ -73,8 +73,8 @@ public void OnSelectExiting(IHPUIInteractable interactable)
using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs))
{
gestureEventArgs.SetParams(interactor, interactable,
HPUIGestureState.Stopped, Time.time - state.startTime, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
HPUIGestureState.Stopped, Time.time - state.startTime, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
interactable.OnGesture(gestureEventArgs);
interactor.OnGesture(gestureEventArgs);

Expand Down Expand Up @@ -112,8 +112,8 @@ public void Update()
using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs))
{
gestureEventArgs.SetParams(interactor, hpuiInteractable,
HPUIGestureState.Started, timeDelta, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
HPUIGestureState.Started, timeDelta, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
hpuiInteractable.OnGesture(gestureEventArgs);
interactor.OnGesture(gestureEventArgs);
}
Expand All @@ -123,8 +123,8 @@ public void Update()
using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs))
{
gestureEventArgs.SetParams(interactor, hpuiInteractable,
HPUIGestureState.Updated, timeDelta, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
HPUIGestureState.Updated, timeDelta, state.startTime, state.startPosition,
state.cumilativeDirection, state.cumilativeDistance, state.delta);
hpuiInteractable.OnGesture(gestureEventArgs);
interactor.OnGesture(gestureEventArgs);
}
Expand Down
29 changes: 15 additions & 14 deletions Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,29 +128,30 @@ public void OnSelectExiting(IHPUIInteractable interactable)

if (activeInteractablesCount == 0)
{
HPUIInteractionState state;
if (activePriorityInteractable != null)
{
state = activeInteractables[activePriorityInteractable];
}
else
{
state = HPUIInteractionState.empty;
}

switch (interactorGestureState)
{
case HPUIGesture.Tap:
using (hpuiTapEventArgsPool.Get(out HPUITapEventArgs tapEventArgs))
{
ComputeActivePriorityInteractable();
tapEventArgs.SetParams(interactor, activePriorityInteractable);
tapEventArgs.SetParams(interactor, activePriorityInteractable, state.startPosition + cumilativeDirection);
activePriorityInteractable?.OnTap(tapEventArgs);
interactor.OnTap(tapEventArgs);
}
break;
case HPUIGesture.Gesture:
using (hpuiGestureEventArgsPool.Get(out HPUIGestureEventArgs gestureEventArgs))
{
HPUIInteractionState state;
if (activePriorityInteractable != null)
{
state = activeInteractables[activePriorityInteractable];
}
else
{
state = HPUIInteractionState.empty;
}
gestureEventArgs.SetParams(interactor, activePriorityInteractable,
HPUIGestureState.Stopped, timeDelta, state.startTime, state.startPosition,
cumilativeDirection, cumilativeDistance, delta);
Expand Down Expand Up @@ -227,8 +228,8 @@ public void Update()
state = HPUIInteractionState.empty;
}
gestureEventArgs.SetParams(interactor, activePriorityInteractable,
HPUIGestureState.Started, timeDelta, state.startTime, state.startPosition,
cumilativeDirection, cumilativeDistance, delta);
HPUIGestureState.Started, timeDelta, state.startTime, state.startPosition,
cumilativeDirection, cumilativeDistance, delta);
activePriorityInteractable?.OnGesture(gestureEventArgs);
interactor.OnGesture(gestureEventArgs);
}
Expand All @@ -247,8 +248,8 @@ public void Update()
state = HPUIInteractionState.empty;
}
gestureEventArgs.SetParams(interactor, activePriorityInteractable,
HPUIGestureState.Updated, timeDelta, state.startTime, state.startPosition,
cumilativeDirection, cumilativeDistance, delta);
HPUIGestureState.Updated, timeDelta, state.startTime, state.startPosition,
cumilativeDirection, cumilativeDistance, delta);
activePriorityInteractable?.OnGesture(gestureEventArgs);
interactor.OnGesture(gestureEventArgs);
}
Expand Down

0 comments on commit f448a65

Please sign in to comment.