Пример #1
0
    private void SnapObjectToGrabToController(GameObject obj)
    {
        //Pause collisions (if allowed on object) for a moment whilst sorting out position to prevent clipping issues
        obj.GetComponent <VRTK_InteractableObject>().PauseCollisions(0.2f);

        VRTK_InteractableObject.GrabSnapType grabType = obj.GetComponent <VRTK_InteractableObject>().grabSnapType;

        if (grabType == VRTK_InteractableObject.GrabSnapType.Rotation_Snap)
        {
            // Identity Controller Rotation
            this.transform.eulerAngles = new Vector3(0f, 270f, 0f);
            obj.transform.eulerAngles  = obj.GetComponent <VRTK_InteractableObject>().snapToRotation;
        }

        if (grabType != VRTK_InteractableObject.GrabSnapType.Precision_Snap)
        {
            obj.transform.position = controllerAttachPoint.transform.position + obj.GetComponent <VRTK_InteractableObject>().snapToPosition;
        }

        if (obj.GetComponent <VRTK_InteractableObject>().grabAttachMechanic == VRTK_InteractableObject.GrabAttachType.Child_Of_Controller)
        {
            SetControllerAsParent(obj);
        }
        else
        {
            CreateJoint(obj);
        }
    }
Пример #2
0
        private void SnapObjectToGrabToController(GameObject obj)
        {
            //Pause collisions (if allowed on object) for a moment whilst sorting out position to prevent clipping issues
            var objectScript = obj.GetComponent <VRTK_InteractableObject>();

            objectScript.PauseCollisions();

            VRTK_InteractableObject.GrabSnapType grabType = objectScript.grabSnapType;

            if (grabType == VRTK_InteractableObject.GrabSnapType.Rotation_Snap)
            {
                // Identity Controller Rotation
                this.transform.eulerAngles = new Vector3(0f, 270f, 0f);
                obj.transform.eulerAngles  = objectScript.snapToRotation;
            }

            if (grabType != VRTK_InteractableObject.GrabSnapType.Precision_Snap)
            {
                obj.transform.position = GetAttachPoint().transform.position + objectScript.snapToPosition;
            }

            if (grabType == VRTK_InteractableObject.GrabSnapType.Handle_Snap && objectScript.snapHandle != null)
            {
                // Identity Controller Rotation
                this.transform.eulerAngles = new Vector3(0f, 270f, 0f);
                obj.transform.eulerAngles  = objectScript.snapHandle.transform.localEulerAngles;

                Vector3 snapHandleDelta = objectScript.snapHandle.transform.position - obj.transform.position;
                obj.transform.position = GetAttachPoint().transform.position - snapHandleDelta;
            }

            if (objectScript.grabAttachMechanic == VRTK_InteractableObject.GrabAttachType.Child_Of_Controller)
            {
                obj.transform.parent = this.transform;
            }
            else
            {
                CreateJoint(obj);
            }
        }