示例#1
0
    // Update is called once per frame
    void Update()
    {
        // Check rotations of each finger depanding on which hardware we use (keyboard/controller vs VRfeeeGlove)
        if (MyGameManager._instance.isKeyboardControls)
        {
            CheckKeyboardGrab();
        }
        else
        {
            CheckVRfreeGloveGrab();
            this.transform.position = objToFollow.transform.position;
        }

        // Check if any of the main four fingers (excludes thumb) is in holding position
        if (isIndexInHoldPosition || isMiddleInHoldPosition || isRingInHoldPosition || isPinkyInHoldPosition)
        {
            isAnyMainFourFingersInHoldPosition = true;
        }
        else
        {
            isAnyMainFourFingersInHoldPosition = false;
        }

        // Set the isGrab bool
        if (isThumbInHoldPosition && isAnyMainFourFingersInHoldPosition)
        {
            isGrab = true;
        }
        else
        {
            isGrab = false;
        }

        // Grab object
        if (isGrab && objToHold != null)
        {
            isHoldingObj = true;

            Rigidbody        objToHoldRb          = objToHold.GetComponent <Rigidbody>();
            PickupController objToHoldPickupCtrlr = objToHold.GetComponent <PickupController>();

            // Remove all force from objToHold else we'll have wonky physics
            objToHoldRb.velocity        = Vector3.zero;
            objToHoldRb.angularVelocity = Vector3.zero;

            if (objToHoldPickupCtrlr != null)
            {
                if (objToHoldPickupCtrlr.canPickedUp)
                {
                    objToHold.transform.position = grabPosition.position;
                }

                objToHoldPickupCtrlr.PickMeUp();
            }
        }
        else if (objToHold != null)
        {
            // Let go
            isHoldingObj        = false;
            canPlayerGrabBuffer = false;
        }
        else
        {
            // Just not holding anything
            isHoldingObj = false;
        }


        // Grab buffer counter (Basically the time between when a player lets go and the object is dropped)
        if (!canPlayerGrabBuffer)
        {
            // Perform drop script for the obj
            if (objToHold != null)
            {
                if (objToHold.gameObject.GetComponent <PickupController>() != null)
                {
                    objToHold.gameObject.GetComponent <PickupController>().DropMe();
                }
                objToHold = null; // Done doing obj-drop specific script
            }

            // Do the counter
            timeUntilCanGrabCounter += Time.deltaTime;

            if (timeUntilCanGrabCounter >= timeUntilCanGrab) // Time up, can grab now
            {
                canPlayerGrabBuffer     = true;              // important
                timeUntilCanGrabCounter = 0;
            }
        }
    }