Esempio n. 1
0
        private IEnumerator AttachToolsToHands(Transform[] toolObjects, bool isRightHand)
        {
            HandsManager handsManagerObj = null;

            while ((handsManagerObj = HandsManager.Instance) == null || !handsManagerObj.IsInitialized())
            {
                yield return(null);
            }

            // create set of tools per hand to be safe
            HashSet <Transform> toolObjectSet = new HashSet <Transform>();

            foreach (Transform toolTransform in toolObjects)
            {
                toolObjectSet.Add(toolTransform.transform);
            }

            foreach (Transform toolObject in toolObjectSet)
            {
                OVRSkeleton handSkeletonToAttachTo =
                    isRightHand ? handsManagerObj.RightHandSkeleton : handsManagerObj.LeftHandSkeleton;
                while (handSkeletonToAttachTo == null || handSkeletonToAttachTo.Bones == null)
                {
                    yield return(null);
                }

                AttachToolToHandTransform(toolObject, isRightHand);
            }
        }
        private IEnumerator AttachTriggerLogic()
        {
            while (!HandsManager.Instance || !HandsManager.Instance.IsInitialized())
            {
                yield return(null);
            }

            OVRSkeleton handSkeleton = IsRightHandedTool ? HandsManager.Instance.RightHandSkeleton : HandsManager.Instance.LeftHandSkeleton;

            OVRSkeleton.BoneId boneToTestCollisions = OVRSkeleton.BoneId.Hand_Pinky3;
            switch (_fingerToFollow)
            {
            case OVRPlugin.HandFinger.Thumb:
                boneToTestCollisions = OVRSkeleton.BoneId.Hand_Index3;
                break;

            case OVRPlugin.HandFinger.Index:
                boneToTestCollisions = OVRSkeleton.BoneId.Hand_Index3;
                break;

            case OVRPlugin.HandFinger.Middle:
                boneToTestCollisions = OVRSkeleton.BoneId.Hand_Middle3;
                break;

            case OVRPlugin.HandFinger.Ring:
                boneToTestCollisions = OVRSkeleton.BoneId.Hand_Ring3;
                break;

            default:
                boneToTestCollisions = OVRSkeleton.BoneId.Hand_Pinky3;
                break;
            }

            List <BoneCapsuleTriggerLogic> boneCapsuleTriggerLogic = new List <BoneCapsuleTriggerLogic>();
            List <OVRBoneCapsule>          boneCapsules            = HandsManager.GetCapsulesPerBone(handSkeleton, boneToTestCollisions);

            foreach (var ovrCapsuleInfo in boneCapsules)
            {
                var boneCapsuleTrigger = ovrCapsuleInfo.CapsuleRigidbody.gameObject.AddComponent <BoneCapsuleTriggerLogic>();
                ovrCapsuleInfo.CapsuleCollider.isTrigger = true;
                boneCapsuleTrigger.ToolTags = ToolTags;
                boneCapsuleTriggerLogic.Add(boneCapsuleTrigger);
            }

            _boneCapsuleTriggerLogic = boneCapsuleTriggerLogic.ToArray();
            // finger tip should have only one capsule
            if (boneCapsules.Count > 0)
            {
                _capsuleToTrack = boneCapsules[0];
            }

            _isInitialized = true;
        }