Version: 1.0.2 Target Device: Youbiquo Leonardo XR
Base SDK: Snapdragon Spaces 1.0.4
Questa guida descrive come configurare il layer di interazione per applicazioni LeonardoXR usando i pacchetti standard Unity:
| Pacchetto | Versione | Fonte |
|---|---|---|
| XR Interaction Toolkit | 3.3.0 | Unity Registry |
| XR Hands | 1.7.2 | Unity Registry |
| AR Foundation | 6.2.1 | Unity Registry |
| Snapdragon Spaces SDK | 1.0.4 | Tarball (Qualcomm) |
| LeonardoXR SDK | 1.0.2 | Tarball (Youbiquo) |
| UniTask | 2.5.10 | Unity Registry |
Nota: Tutte le dipendenze devono essere installate secondo la procedura descritta in Getting Started prima di procedere con la configurazione dell’interazione.
Il pacchetto è installato tramite Window > Package Manager > Unity Registry > XR Interaction Toolkit > Install (versione 3.3.0).
Se durante l’installazione compare il prompt “Enable the new input system?”, clicca Yes. Se compare il prompt “XR Interaction Layer Mask Update Required”, clicca I Made a Backup, Go Ahead! (per nuovi progetti) oppure No Thanks se non era già presente una versione precedente di XRIT.
Gli Starter Assets includono:
Dopo l’import, un asset XRI Default Input Actions viene aggiunto in Assets/Samples/XR Interaction Toolkit/[versione]/Starter Assets/. Questo asset è già configurato per i profili controller standard (incluso il Companion Controller via Microsoft MMRC Profile) e per le mani.
Per associare l’asset al sistema:
La gerarchia minima per una scena interattiva su LeonardoXR è:
AR Session
XR Origin (Action-based)
└── Camera Offset
├── Main Camera (tagged "MainCamera")
├── LeftHand Controller
│ ├── XR Ray Interactor (sinistra)
│ └── XR Direct Interactor (sinistra)
└── RightHand Controller
├── XR Ray Interactor (destra)
└── XR Direct Interactor (destra)
Crea la struttura base selezionando GameObject > XR > XR Origin (Action-based) nel menu principale.
Attenzione: Disabilita il componente AR Camera Background — non è supportato su LeonardoXR e viene disabilitato automaticamente a runtime. Disabilita anche AR Camera Manager se non recuperi frame RGB dalla camera.
Aggiungi il componente Input Action Manager all’XR Origin (o a un GameObject persistente). Nel campo Action Assets, assegna:
XRI Default Input Actions (dagli Starter Assets importati).Snapdragon Spaces Input Actions (da Samples/Snapdragon Spaces/[versione]/Core Samples/Shared Assets/Input Actions).Il Companion Controller di Leonardo XR usa il Microsoft Mixed Reality Motion Controller Profile per inviare input di puntamento e pulsanti dall’app companion sullo smartphone.
Nota: Non aggiungere il Hand Interaction Profile insieme al Companion Controller — ha la precedenza e interferisce con il puntamento del controller.
Samples/Snapdragon Spaces/[versione]/Core Samples/Shared Assets/Prefabs/Interaction.0.005.Installato tramite Window > Package Manager > Unity Registry > XR Hands > Install (versione 1.7.2).
Attenzione: Il Hand Tracking Subsystem deve essere abilitato in All Features — non solo nella sezione Snapdragon Spaces — per funzionare correttamente su LeonardoXR.
Nota: Non aggiungere Hand Interaction Profile se stai usando il Companion Controller — i due profili sono in conflitto. Vedi la sezione “Combinare Controller e Hand Tracking” più in basso.
Il pacchetto XR Hands si integra con XR Interaction Toolkit tramite i componenti XR Hand Tracking Events e XR Hand Skeleton Driver. Questi componenti vengono configurati automaticamente sugli XR Origin Controller se si usano i prefab degli Starter Assets del Hand Interaction Demo.
Struttura raccomandata con XR Hands:
XR Origin (Action-based)
└── Camera Offset
├── Left Hand
│ ├── XR Hand Skeleton Driver
│ ├── XR Hand Mesh Renderer (opzionale)
│ └── XR Direct Interactor
└── Right Hand
├── XR Hand Skeleton Driver
├── XR Hand Mesh Renderer (opzionale)
└── XR Ray Interactor (per puntamento a distanza)
using UnityEngine.XR.Hands;
XRHandSubsystem handSubsystem = XRHandSubsystemUtility.GetSubsystem();
if (handSubsystem != null)
{
XRHand leftHand = handSubsystem.leftHand;
if (leftHand.isTracked)
{
if (leftHand.GetJoint(XRHandJointID.IndexTip).TryGetPose(out Pose indexTipPose))
{
// indexTipPose.position = posizione della punta dell'indice sinistro
}
}
}
Usa il sistema Gestures di XR Hands per rilevare pose statiche o dinamiche delle mani:
using UnityEngine.XR.Hands;
// Sulla scena: aggiungi XRHandGestures component all'XR Origin
// Poi sottoscrivi gli eventi:
[SerializeField] XRHandGestures gestures;
void OnEnable()
{
gestures.gesturePerformed += OnGesturePerformed;
}
void OnGesturePerformed(XRHandGesture gesture, Handedness handedness)
{
Debug.Log($"Gesture: {gesture.gestureName} eseguita con {handedness}");
}
Per rendere un oggetto selezionabile da ray o direct interactor:
// Esempio: reazione al select con XR Simple Interactable
using UnityEngine.XR.Interaction.Toolkit;
public class MyButton : MonoBehaviour
{
[SerializeField] XRSimpleInteractable interactable;
void OnEnable()
{
interactable.selectEntered.AddListener(OnSelected);
}
void OnSelected(SelectEnterEventArgs args)
{
Debug.Log("Selezionato da: " + args.interactorObject);
}
}
XRIT 3.x usa le Interaction Layer Masks per filtrare quali interactor possono interagire con quali interactable. Configura i layer dall’inspector o tramite:
interactable.interactionLayers = InteractionLayerMask.GetMask("Default", "UI");
Per UI 3D interattive su LeonardoXR:
| Parametro | Valore Consigliato |
|---|---|
| Render Mode | World Space |
| Dynamic Pixels Per Unit | 1 |
| Reference Pixels Per Unit | 100 |
| Scale | 0.001 (per un canvas di ~1m = 1000 unità pixel) |
Su LeonardoXR non è possibile usare simultaneamente il Companion Controller (con raycast) e il Hand Tracking completo (con raycast da entrambe le mani) a causa dei conflitti tra profili OpenXR.
UniTask 2.5.10 è incluso come dipendenza per gestire operazioni asincrone ad alte performance (caricamento asset, attesa di subsystem, ecc.) senza allocazioni GC.
Installato tramite Window > Package Manager > Unity Registry > UniTask > Install (versione 2.5.10), oppure come git URL.
using Cysharp.Threading.Tasks;
public class HandSubsystemWaiter : MonoBehaviour
{
async UniTaskVoid Start()
{
// Attendi che il subsystem XR Hands sia pronto
await UniTask.WaitUntil(() =>
XRHandSubsystemUtility.GetSubsystem()?.running ?? false);
Debug.Log("XR Hands subsystem pronto.");
}
}
UniTask è usato internamente dall’LeonardoXR SDK per operazioni asincrone. Si raccomanda di usarlo anche nel codice dell’applicazione per coerenza con il lifecycle dell’SDK.
| Profilo | Uso |
|---|---|
| Microsoft Mixed Reality Motion Controller Profile | Companion Controller (smartphone come controller) |
| Hand Interaction Profile | Hand tracking con poke/pinch interactor |
Ricorda: I due profili non possono coesistere con raycast attivo su entrambi. Scegli una delle opzioni descritte nella sezione “Combinare Controller e Hand Tracking”.