コード例 #1
0
 public void UpdatePose()
 {
     if (IsInitialized)
     {
         for (int ci = 0; ci < _capsules.Length; ++ci)
         {
             CapsuleInfo capsuleInfo = _capsules[ci];
             var         go          = capsuleInfo.CapsuleRigidBBody.gameObject;
             Transform   bone        = _handSkeleton.Bones[(int)capsuleInfo.BoneIndex];
             if (_hand.IsTracked)
             {
                 if (go.activeSelf)
                 {
                     var rigidBody = capsuleInfo.CapsuleRigidBBody;
                     rigidBody.MovePosition(bone.position);
                     rigidBody.MoveRotation(bone.rotation);
                 }
                 else
                 {
                     go.SetActive(true);
                     var rigidBody = capsuleInfo.CapsuleRigidBBody;
                     rigidBody.position = bone.position;
                     rigidBody.rotation = bone.rotation;
                 }
             }
             else
             {
                 go.SetActive(false);
             }
         }
     }
 }
コード例 #2
0
        private IEnumerator AttachTriggerLogic()
        {
            while (!Hands.Instance.IsInitialized())
            {
                yield return(null);
            }

            Hand        properHand  = IsRightHandedTool ? Hands.Instance.RightHand : Hands.Instance.LeftHand;
            HandPhysics handPhysics = properHand.Physics;

            while (!handPhysics.IsInitialized)
            {
                yield return(null);
            }

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

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

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

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

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

            List <BoneCapsuleTriggerLogic> boneCapsuleTriggerLogic = new List <BoneCapsuleTriggerLogic>();
            List <CapsuleInfo>             boneCapsules            = handPhysics.GetCapsulesPerBone(boneToTestCollisions);

            foreach (var ovrCapsuleInfo in boneCapsules)
            {
                var boneCapsuleTrigger = ovrCapsuleInfo.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;
        }