Improved hand tracking option selection

This commit is contained in:
Pascal Serrarens 2025-08-18 11:13:38 +02:00
parent 998219ff07
commit e27a8dea2d
2 changed files with 31 additions and 0 deletions

View File

@ -74,11 +74,15 @@ namespace Passer.Humanoid {
#if UNITY_ANDROID && hOCHAND
if (tracker.oculusHandTracking)
handSkeleton = OculusHandSkeleton.Get(unityXR.transform, handTarget.isLeft);
else
#endif
#if hVIVEHAND
if (tracker.viveHandTracking)
handSkeleton = ViveHandSkeleton.Get(unityXR.transform, handTarget.isLeft);
else
#endif
handSkeleton = UnityXRHandSkeleton.Get(unityXR.transform, handTarget.isLeft);
}
#endregion Init

View File

@ -20,6 +20,33 @@ namespace Passer.Tracking {
protected XRNode xrNode;
#region Manage
public static UnityXRHandSkeleton Find(Transform trackerTransform, bool isLeft) {
UnityXRHandSkeleton[] handSkeletons = trackerTransform.GetComponentsInChildren<UnityXRHandSkeleton>();
foreach (UnityXRHandSkeleton handSkeleton in handSkeletons) {
if (handSkeleton.isLeft == isLeft)
return handSkeleton;
}
return null;
}
public static UnityXRHandSkeleton Get(Transform trackerTransform, bool isLeft) {
UnityXRHandSkeleton handSkeleton = Find(trackerTransform, isLeft);
if (handSkeleton == null) {
GameObject skeletonObj = new GameObject(isLeft ? "Left Hand Skeleton" : "Right Hand Skeleton");
skeletonObj.transform.parent = trackerTransform;
skeletonObj.transform.localPosition = Vector3.zero;
skeletonObj.transform.localRotation = Quaternion.identity;
handSkeleton = skeletonObj.AddComponent<UnityXRHandSkeleton>();
handSkeleton.isLeft = isLeft;
}
return handSkeleton;
}
#endregion
#region Init
protected override void Start() {