From 2fa381e2cb95abf4efd71d579973582ad1140e73 Mon Sep 17 00:00:00 2001 From: Ahmed Shariff Date: Mon, 8 Jan 2024 00:23:25 -0800 Subject: [PATCH] Add z order for HPUI Interactables --- Editor/HPUIBaseInteractableEditor.cs | 4 ++++ Runtime/Interaction/HPUIBaseInteractable.cs | 7 +++++++ Runtime/Interaction/HPUIInteractor.cs | 9 ++++----- Runtime/Interaction/IHPUIInteractable.cs | 5 +++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Editor/HPUIBaseInteractableEditor.cs b/Editor/HPUIBaseInteractableEditor.cs index 624c19d..5fc0029 100644 --- a/Editor/HPUIBaseInteractableEditor.cs +++ b/Editor/HPUIBaseInteractableEditor.cs @@ -54,5 +54,9 @@ protected override List GetDerivedSerializedPropertyNames() props.AddRange(EventPropertyNames); return props; } + + /// + protected override void DrawSelectionConfiguration() + {} } } diff --git a/Runtime/Interaction/HPUIBaseInteractable.cs b/Runtime/Interaction/HPUIBaseInteractable.cs index 97db364..78cf505 100644 --- a/Runtime/Interaction/HPUIBaseInteractable.cs +++ b/Runtime/Interaction/HPUIBaseInteractable.cs @@ -24,6 +24,12 @@ public Handedness Handedness public Collider boundsCollider; + [SerializeField] + private int _zOrder; + + /// + public int zOrder { get => _zOrder; set => _zOrder = value; } + [SerializeField] private HPUITapEvent tapEvent = new HPUITapEvent(); @@ -48,6 +54,7 @@ protected override void Awake() { base.Awake(); getDistanceOverride = GetDistanceOverride; + selectMode = InteractableSelectMode.Single; } /// diff --git a/Runtime/Interaction/HPUIInteractor.cs b/Runtime/Interaction/HPUIInteractor.cs index 0771c44..d3c9ac4 100644 --- a/Runtime/Interaction/HPUIInteractor.cs +++ b/Runtime/Interaction/HPUIInteractor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; using UnityEngine.Pool; using UnityEngine.XR.Hands; @@ -87,12 +88,10 @@ public override void GetValidTargets(List targets) List recievedTargets = ListPool.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.Release(recievedTargets); } diff --git a/Runtime/Interaction/IHPUIInteractable.cs b/Runtime/Interaction/IHPUIInteractable.cs index b8499a9..f227b21 100644 --- a/Runtime/Interaction/IHPUIInteractable.cs +++ b/Runtime/Interaction/IHPUIInteractable.cs @@ -5,6 +5,11 @@ namespace ubco.ovilab.HPUI.Interaction { public interface IHPUIInteractable : IXRInteractable, IXRSelectInteractable { + /// + /// Lower z order will get higher priority. + /// + int zOrder { get; set; } + /// /// Get the projection of the interactors position on the xz plane of this interactable, normalized. /// the returned Vector2 - (x, z) on the xz-plane.