Skip to content

Commit

Permalink
Fix for incorrect order number of interactables being recorded
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Jan 11, 2024
1 parent 8569c22 commit 3e71a2a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Runtime/Interaction/Logic/HPUIGestureLogicUnified.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public void OnSelectEntering(IHPUIInteractable interactable)
return;
}

activeInteractablesCount += 1;

if (interactorGestureState == HPUIGesture.None)
{
interactorGestureState = HPUIGesture.Tap;
Expand All @@ -68,6 +66,7 @@ public void OnSelectEntering(IHPUIInteractable interactable)

HPUIInteractionState state = new HPUIInteractionState(Time.time, interactable.ComputeInteractorPostion(interactor), inValidWindow);
activeInteractables.Add(interactable, state);
activeInteractablesCount += 1;

// If a new higher priority targets is encountered within tap time window, we hand over control to that.
if (interactable.zOrder < lowestTargetZIndex && inValidWindow)
Expand All @@ -86,9 +85,10 @@ public void OnSelectEntering(IHPUIInteractable interactable)

private void ComputeCurrectTrackingInteractable()
{
// Any target that is active should be ok for this.
// Any target that is active should be ok for this?
IHPUIInteractable interactableToTrack = activeInteractables
.Where(kvp => kvp.Value.active)
.OrderBy(kvp => kvp.Value.startTime)
.First().Key;

if (interactableToTrack != currentTrackingInteractable)
Expand Down Expand Up @@ -124,9 +124,7 @@ public void OnSelectExiting(IHPUIInteractable interactable)
return;
}

activeInteractablesCount -= 1;

if (activeInteractablesCount == 0)
if (activeInteractablesCount == 1)
{
HPUIInteractionState state;
if (activePriorityInteractable != null)
Expand Down Expand Up @@ -169,6 +167,7 @@ public void OnSelectExiting(IHPUIInteractable interactable)
if (activeInteractables.ContainsKey(interactable))
{
activeInteractables[interactable].active = false;
activeInteractablesCount -= 1;
ComputeCurrectTrackingInteractable();
}
}
Expand Down Expand Up @@ -259,6 +258,7 @@ public void Update()
throw new NotImplementedException();
}

previousPosition = currentPosition;
}

/// <summary>
Expand Down
52 changes: 52 additions & 0 deletions Tests/HPUIGestureLogicUnifiedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,58 @@ public IEnumerator HPUIGestureLogicUnifiedTest_SimpleGesture()
Assert.Greater(gesturesCount, 0);
}

[UnityTest]
public IEnumerator HPUIGestureLogicUnifiedTest_TapThenGesture()
{
Reset();
TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback);
IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold);
// First tap
logic.OnSelectEntering(i1);
logic.Update();
yield return new WaitForSeconds(TapTimeThreshold /2);
logic.Update();
logic.OnSelectExiting(i1);
Assert.AreEqual(tapsCount, 1);
Assert.AreEqual(gesturesCount, 0);

// Gesture
Reset();
logic.OnSelectEntering(i1);
logic.Update();
yield return new WaitForSeconds(TapTimeThreshold * 2);
logic.Update();
logic.OnSelectExiting(i1);
Assert.AreEqual(tapsCount, 0);
Assert.Greater(gesturesCount, 0);
}

[UnityTest]
public IEnumerator HPUIGestureLogicUnifiedTest_GestureThenTap()
{
Reset();
TestHPUIInteractable i1 = new TestHPUIInteractable(0, true, true, OnTapCallback, OnGestureCallback);
IHPUIGestureLogic logic = new HPUIGestureLogicUnified(new HPUIInteractor(), TapTimeThreshold, TapDistanceThreshold);
// Gesture
logic.OnSelectEntering(i1);
logic.Update();
yield return new WaitForSeconds(TapTimeThreshold * 2);
logic.Update();
logic.OnSelectExiting(i1);
Assert.AreEqual(tapsCount, 0);
Assert.Greater(gesturesCount, 0);

// tap
Reset();
logic.OnSelectEntering(i1);
logic.Update();
yield return new WaitForSeconds(TapTimeThreshold / 2);
logic.Update();
logic.OnSelectExiting(i1);
Assert.AreEqual(tapsCount, 1);
Assert.AreEqual(gesturesCount, 0);
}

[Test]
public void HPUIGestureLogicUnifiedTest_TwoItem_tap_time()
{
Expand Down

0 comments on commit 3e71a2a

Please sign in to comment.