Skip to content

Commit

Permalink
Add z order for HPUI Interactables
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Jan 8, 2024
1 parent 26a2b13 commit 61f23c1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Editor/HPUIBaseInteractableEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ protected override List<string> GetDerivedSerializedPropertyNames()
props.AddRange(EventPropertyNames);
return props;
}

/// <inheritdoc />
protected override void DrawSelectionConfiguration()
{}
}
}
7 changes: 7 additions & 0 deletions Runtime/Interaction/HPUIBaseInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public Handedness Handedness

public Collider boundsCollider;

[SerializeField]
private int _zOrder;

/// <inheritdoc />
public int zOrder { get => _zOrder; set => _zOrder = value; }

[SerializeField]
private HPUITapEvent tapEvent = new HPUITapEvent();

Expand All @@ -48,6 +54,7 @@ protected override void Awake()
{
base.Awake();
getDistanceOverride = GetDistanceOverride;
selectMode = InteractableSelectMode.Single;
}

/// <inheritdoc />
Expand Down
18 changes: 12 additions & 6 deletions Runtime/Interaction/HPUIInteractor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Pool;
using UnityEngine.XR.Hands;
Expand All @@ -14,7 +15,7 @@ namespace ubco.ovilab.HPUI.Interaction
[DisallowMultipleComponent]
public class HPUIInteractor: XRPokeInteractor, IHPUIInteractor
{
public Handedness handedness;
public new Handedness handedness;

// TODO move these to an asset?
[SerializeField]
Expand Down Expand Up @@ -87,16 +88,21 @@ public override void GetValidTargets(List<IXRInteractable> targets)
List<IXRInteractable> recievedTargets = ListPool<IXRInteractable>.Get();
recievedTargets.AddRange(targets);

foreach(IXRInteractable target in recievedTargets)
targets.Clear();
foreach(IXRInteractable target in recievedTargets.Select(t => t as IHPUIInteractable).Where(ht => ht != null).OrderBy(ht => ht.zOrder))
{
if (!(target is HPUIBaseInteractable hpuiTarget) || hpuiTarget.Handedness != handedness)
{
targets.Remove(target);
}
targets.Add(target);
}
ListPool<IXRInteractable>.Release(recievedTargets);
}

/// <inheritdoc />
public override bool CanSelect(IXRSelectInteractable interactable)
{
return ProcessSelectFilters(interactable);
}


#region IHPUIInteractor interface
/// <inheritdoc />
public void OnTap(HPUITapEventArgs args)
Expand Down
5 changes: 5 additions & 0 deletions Runtime/Interaction/IHPUIInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace ubco.ovilab.HPUI.Interaction
{
public interface IHPUIInteractable : IXRInteractable, IXRSelectInteractable
{
/// <summary>
/// Lower z order will get higher priority.
/// </summary>
int zOrder { get; set; }

/// <summary>
/// Get the projection of the interactors position on the xz plane of this interactable, normalized.
/// the returned Vector2 - (x, z) on the xz-plane.
Expand Down

0 comments on commit 61f23c1

Please sign in to comment.