public VRInteractableObject Pickup(VRControllerInput controller)
 {
     if (clonedObject)
     {
         return(PickupAfterClone(controller));
     }
     else
     {
         return(clonePickup(controller));
     }
 }
Ejemplo n.º 2
0
    public override void ButtonPressDown(EVRButtonId button, VRControllerInput controller)
    {
        //If button is desired "trigger" button
        if (button == buttonToTrigger)
        {
            //Set button's destination position to the "down" position
            currentButtonDestination = buttonDownPos;

            MethodToTrigger();
        }
    }
Ejemplo n.º 3
0
    public override void ButtonPressUp(EVRButtonId button, VRControllerInput controller)
    {
        //If button is desired "fire" button
        if (button == fireButton)
        {
            //Set autofire to false
            autoFire = false;

            //Reset autofire timer
            restTimer = 0;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("escape"))
        {
            Cursor.lockState = mouseLocked ? CursorLockMode.None : CursorLockMode.Locked;
            mouseLocked      = !mouseLocked;
        }

        float mouseVelX = Input.GetAxis("Mouse X");
        float mouseVelY = -Input.GetAxis("Mouse Y");

        transform.rotation = Quaternion.Euler(0, VRControllerInput.GetRightTrackpadRotation(), 0);
        //transform.Rotate(0, mouseVelX, 0);
        //camera.Rotate(mouseVelY, 0, 0);
    }
Ejemplo n.º 5
0
        void Start()
        {
            input = gameObject.GetComponent <VRControllerInput>();

            input.OnGrabPressed.AddListener((_args) => { if (collidingObject != null)
                                                         {
                                                             GrabObject();
                                                         }
                                            });
            input.OnGrabReleased.AddListener((_args) => { if (heldObject != null)
                                                          {
                                                              ReleasedObject();
                                                          }
                                             });
        }
Ejemplo n.º 6
0
    protected void JointedRelease(VRControllerInput controller)
    {
        //Make sure joint isnt null
        if (fixedJoint != null)
        {
            //If object is still jointed to hand (could have been taken by other hand)
            if (fixedJoint.connectedBody == controller.GetComponent <Rigidbody>())
            {
                //Remove joint
                Destroy(fixedJoint);
                fixedJoint = null;
            }

            ThrowObject(controller);
        }
    }
Ejemplo n.º 7
0
    private void OnTriggerStay(Collider collider)
    {
        //If object is an interactable item
        VRControllerInput controller = collider.GetComponent <VRControllerInput>();

        if (_loadPrefabsInResources != null && controller != null && controller.Device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            if (ButtonType == State.next)
            {
                _loadPrefabsInResources.AddNextGameObjectsToShelf();
            }
            else if (ButtonType == State.previous)
            {
                _loadPrefabsInResources.AddPreviousGameObjectsToShelf();
            }
        }
    }
Ejemplo n.º 8
0
    protected void ParentedPickup(VRControllerInput controller)
    {
        //Make object kinematic
        //(Not effected by physics, but still able to effect other objects with physics)
        rigidBody.isKinematic = true;

        //Parent object to hand
        transform.SetParent(controller.gameObject.transform);

        //If there is an interaction point, snap object to that point
        if (InteractionPoint != null)
        {
            //Set the position of the object to the inverse of the interaction point's local position.
            transform.localPosition = -InteractionPoint.localPosition;

            //Set the local rotation of the object to the inverse of the rotation of the interaction point.
            //When you're setting your interaction point the blue arrow (Z) should be pointing in the direction you want your hand to be pointing
            //and the green arrow (Y) should be pointing "up".
            transform.localRotation = Quaternion.Inverse(InteractionPoint.localRotation);
        }
    }
Ejemplo n.º 9
0
    protected void JointedPickup(VRControllerInput controller)
    {
        //Check if it already has a joint (held by other hand)
        if (fixedJoint == null)
        {
            //Add joint to object
            fixedJoint = gameObject.AddComponent <FixedJoint>();

            //You don't have to set a break force, but if you don't,
            //when you drag your object behind immovable things, they'll just weirdly be
            //stuck behind them until you let go.
            //By setting a break force, you "drop" the item under too much strain.
            if (useBreakForce)
            {
                fixedJoint.breakForce = 500;
            }
        }

        //Attach to controller
        fixedJoint.connectedBody = controller.GetComponent <Rigidbody>();
    }
Ejemplo n.º 10
0
    protected void ParentedRelease(VRControllerInput controller)
    {
        //Make sure the hand is still the parent.
        //Could have been transferred to anothr hand.
        if (transform.parent == controller.gameObject.transform)
        {
            //Return previous kinematic state
            rigidBody.isKinematic = originalKinematicState;

            //Set object's parent to its original parent
            if (originalParent != controller.gameObject.transform)
            {
                //Ensure original parent recorded wasn't somehow the controller (failsafe)
                transform.SetParent(originalParent);
            }
            else
            {
                transform.SetParent(null);
            }

            ThrowObject(controller);
        }
    }
Ejemplo n.º 11
0
    public override void ButtonPressDown(EVRButtonId button, VRControllerInput controller)
    {
        //As it is, there is no check for whether the shooter is actually in your hand before you fire.
        //You would have to write in the ability to check if the current object is being held.

        //If button is desired "fire" button
        if (button == fireButton)
        {
            //Shoot
            ShootBullet();

            //Haptic pulse
            controller.device.TriggerHapticPulse(2000);

            //Trigger audio
            gunAudioSource.Play();

            //Turn on autofire, if gun is set to automatic
            if (defaultGunType == GunTypes.Automatic)
            {
                autoFire = true;
            }
        }
    }
Ejemplo n.º 12
0
    public override void RayStay(RaycastHit hit, VRControllerInput controller = null)
    {
        //Get position of the raycast hit, relative to the Canvas
        Vector2 position = canvasRect.InverseTransformPoint(hit.point);

        //If there is a controller script, which meands that a controller is triggering
        if (controller)
        {
            //Get a controller index of either 0 or 1, 0 if the controller is leftmost, 1 otherwise
            int controllerIndex = controller.device.index == leftControllerIndex ? 0 : 1;

            //Make sure that enough objects on the canvas are assigned
            if (controllerIndex < handIndicatorRects.Length)
            {
                //Move canvas object that matches the hands
                handIndicatorRects[controllerIndex].anchoredPosition = position;
            }
        }
        else
        {
            //Move head canvas object to match position
            headIndicatorRect.anchoredPosition = position;
        }
    }
    private VRInteractableObject clonePickup(VRControllerInput controller)
    {
        GameObject           newObject             = Instantiate(this.gameObject, this.transform.position, this.transform.rotation);
        VRInteractableObject newInteractableObject = newObject.GetComponent(typeof(VRInteractableObject)) as VRInteractableObject;

        newInteractableObject.transform.localScale = gameObject.transform.lossyScale;
        if (this.name != "HumanScale")
        {
            newObject.gameObject.name = this.name + "_" + index++;
        }
        else
        {
            newObject.gameObject.name = this.name;
        }
        newInteractableObject.GetComponent <Rigidbody>().isKinematic = true;
        newInteractableObject.GetComponent <Rigidbody>().useGravity  = true;
        newInteractableObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
        newInteractableObject.originalParent           = originalParent;
        newInteractableObject.originalKinematicState   = originalKinematicState;
        newInteractableObject.originalConstraintsState = originalConstraintsState;
        newInteractableObject.transform.SetParent(controller.gameObject.transform);
        newInteractableObject.clonedObject = true;
        return(newInteractableObject);
    }
Ejemplo n.º 14
0
 /// <summary>
 /// Called when controller passes into trigger
 /// </summary>
 /// <param name="controller"></param>
 public virtual void TriggerEnter(VRControllerInput controller)
 {
     //Empty. Overriden meothod only.
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Called when either the head or a controller leaves the object
 /// </summary>
 /// <param name="controller">Leave null if ray is coming from head</param>
 public virtual void RayExit(VRControllerInput controller = null)
 {
     //Empty. Overriden meothod only.
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Called every frame the head or a controller is pointed at an object
 /// </summary>
 /// <param name="controller">Leave null if ray is coming from head</param>
 public virtual void RayStay(RaycastHit hit, VRControllerInput controller = null)
 {
     //Empty. Overriden meothod only.
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Called when button is released after an object has been "grabbed".
 /// </summary>
 /// <param name="controller"></param>
 public virtual void ButtonPressUp(EVRButtonId button, VRControllerInput controller)
 {
     //Empty. Overriden meothod only.
 }
Ejemplo n.º 18
0
 protected void ThrowObject(VRControllerInput controller)
 {
     //Set object's velocity and angular velocity to that of controller
     rigidBody.velocity        = controller.device.velocity;
     rigidBody.angularVelocity = controller.device.angularVelocity;
 }
Ejemplo n.º 19
0
 public override void RayExit(VRControllerInput controller = null)
 {
     //Apply object's original color
     objectMaterial.color = originalColor;
 }
Ejemplo n.º 20
0
 void Awake()
 {
     //If attached to head, will return null (expected behavior)
     //I'm using this method to differentiate between head and hands
     controllerInput = GetComponent <VRControllerInput>();
 }