Beispiel #1
0
        // Initialises the object to get parented to the designated finger on the designated hand.
        // Sets the callbacks for when the object enters, stays or exits collision.
        public void Initialise(BKI_FingerCollisionManager m, Transform parentOb, BKI_SteamVR_Behaviour_Skeleton h, Action <Collider> onColEnterCallback, Action <Collider> onColStayCallback, Action <Collider> onColExitCallback, float offset, Action <Collider> reg, Action <Collider> unreg)
        {
            manager                 = m;
            collidedObjects         = new List <GameObject>();
            transform.parent        = parentOb;
            transform.localPosition = new Vector3(0, offset, 0);
            hand               = h;
            onColEnter         = onColEnterCallback;
            onColStay          = onColStayCallback;
            onColExit          = onColExitCallback;
            registerCallback   = reg;
            unregisterCallback = unreg;

            // Makes sure the collider is set to isTrigger.
            GetComponent <Collider>().isTrigger = true;
        }
        // Returns current value.
        public bool IsHandGripping(BKI_Hand hand)
        {
            BKI_HandValues vals = (hand == BKI_Hand.left) ? leftHandValues : rightHandValues;
            BKI_SteamVR_Behaviour_Skeleton skel = (hand == BKI_Hand.left) ? leftHandSkeleton : rightHandSkeleton;

            bool canDoLoop = skel.IsFingerFrozen(BKI_Finger.thumb) && (skel.IsFingerFrozen(BKI_Finger.index) || skel.IsFingerFrozen(BKI_Finger.middle) || skel.IsFingerFrozen(BKI_Finger.ring) || skel.IsFingerFrozen(BKI_Finger.pinky));

            if (canDoLoop)
            {
                for (int i = 1; i < 5; i++)
                {
                    if (!(skel.IsFingerFrozen((BKI_Finger)i) && !(vals.GetFingerValue((BKI_Finger)i) < 0.1f)))
                    {
                        continue;
                    }
                    if (
                        (colliderManager.GetRegisteredPickupable(hand, BKI_Finger.thumb) != null &&
                         (colliderManager.GetRegisteredPickupable(hand, (BKI_Finger)i)) != null) &&
                        colliderManager.GetRegisteredPickupable(hand, BKI_Finger.thumb).GetPickupable() == colliderManager.GetRegisteredPickupable(hand, (BKI_Finger)i).GetPickupable())
                    {
                        if (hand == BKI_Hand.right)
                        {
                            rhGrippedObject = colliderManager.GetRegisteredPickupable(hand, BKI_Finger.thumb);
                        }
                        else
                        {
                            lhGrippedObject = colliderManager.GetRegisteredPickupable(hand, BKI_Finger.thumb);
                        }
                        return(true);
                    }
                }
            }
            else
            {
                if (hand == BKI_Hand.right)
                {
                    rhGrippedObject = null;
                }
                else
                {
                    lhGrippedObject = null;
                }
                return(false);
            }
            return(false);
        }
        private void Start()
        {
            leftHandSkeleton  = BKI_FingerCurler.BKI_Curler_Instance.LeftHandSkeleton;
            rightHandSkeleton = BKI_FingerCurler.BKI_Curler_Instance.RightHandSkeleton;

            if (leftHandSkeleton == null || rightHandSkeleton == null)
            {
                Debug.LogError("Controllers unassigned. Quitting initialisation.");
                return;
            }

            fingerFrozenLeftHand       = new bool[5];
            fingerFrozenRightHand      = new bool[5];
            fingerFrozenValueLeftHand  = new float[5];
            fingerFrozenValueRightHand = new float[5];

            SetupFingerTriggers();
            SetupPalmColliders();
            registeredPickupableRight = new BKI_PickupableObject[5];
            registeredPickupableLeft  = new BKI_PickupableObject[5];
        }
 // Ctor.
 public BKI_HandValues(BKI_SteamVR_Behaviour_Skeleton skel, Vector2[] magicNums)
 {
     skeleton          = skel;
     magicNumbers      = magicNums;
     proximalRotations = new float[5];
 }