コード例 #1
0
    void Update()
    {
        var device = SteamVR_Controller.Input(index);

        /*
         * foreach (var buttonId in buttonIds)
         * {
         *  if (SteamVR_Controller.Input(index).GetPressDown(buttonId))
         *  {
         *
         *  }
         *  if (SteamVR_Controller.Input(index).GetPressUp(buttonId))
         *  {
         *
         *  }
         *  if (SteamVR_Controller.Input(index).GetPress(buttonId))
         *  {
         *
         *  }
         * }
         */

        foreach (var buttonId in axisIds)
        {
            if (SteamVR_Controller.Input(index).GetTouchDown(buttonId))
            {
                //Debug.Log(buttonId + " touch down");
            }
            if (SteamVR_Controller.Input(index).GetTouchUp(buttonId))
            {
                if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                {
                    DropItem(device);
                }
            }
            if (SteamVR_Controller.Input(index).GetTouch(buttonId))
            {
                var axis = SteamVR_Controller.Input(index).GetAxis(buttonId);

                if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                {
                    if (itemInHand == null && axis.x >= grabThreshold && GetComponentInChildren <GrabTrigger>().things.Count > 0)
                    {
                        var thing = GetComponentInChildren <GrabTrigger>().things[0];
                        var item  = thing as ObtainableItem;

                        if (item != null)
                        {
                            itemInHand = item;
                            itemInHand.Dispatch(ObtainableItemEventType.OnPickUp, this);
                        }
                        else
                        {
                            Actium.Dispatch("ViveHandInteractsWith_" + thing.name, this);
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
    void DropItem(SteamVR_Controller.Device device)
    {
        if (itemInHand != null)
        {
            itemInHand.Dispatch(ObtainableItemEventType.OnDropOff, this);
            itemInHand.owner = null;

            itemInHand.GetComponent <Rigidbody>().velocity = device.velocity * 1.4f;

            itemInHand = null;
        }
    }
コード例 #3
0
    void Update()
    {
        var device = SteamVR_Controller.Input(index);

        /*
        foreach (var buttonId in buttonIds)
        {
            if (SteamVR_Controller.Input(index).GetPressDown(buttonId))
            {

            }
            if (SteamVR_Controller.Input(index).GetPressUp(buttonId))
            {

            }
            if (SteamVR_Controller.Input(index).GetPress(buttonId))
            {

            }
        }
        */

        foreach (var buttonId in axisIds)
        {
            if (SteamVR_Controller.Input(index).GetTouchDown(buttonId))
            {
                //Debug.Log(buttonId + " touch down");
            }
            if (SteamVR_Controller.Input(index).GetTouchUp(buttonId))
            {
                if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                {
                    DropItem(device);
                }
            }
            if (SteamVR_Controller.Input(index).GetTouch(buttonId))
            {
                var axis = SteamVR_Controller.Input(index).GetAxis(buttonId);

                if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                {
                    if (itemInHand == null && axis.x >= grabThreshold && GetComponentInChildren<GrabTrigger>().things.Count > 0)
                    {
                        var thing = GetComponentInChildren<GrabTrigger>().things[0];
                        var item = thing as ObtainableItem;

                        if (item != null)
                        {
                            itemInHand = item;
                            itemInHand.Dispatch(ObtainableItemEventType.OnPickUp, this);
                        }
                        else
                        {
                            Actium.Dispatch("ViveHandInteractsWith_" + thing.name, this);
                        }
                    }
                }
            }
        }
    }
コード例 #4
0
    void Update()
    {
        foreach (var index in controllerIndices)
        {
            //var controllerState = SteamVR_Controller.Input((int)index).GetState();
            //var t = transform;
            //var baseTransform = new SteamVR_Utils.RigidTransform(t);

            var device = SteamVR_Controller.Input(index);

            // TODO: why it does return the position and rotation with a quite noticeable delay to a real position?

            /*
             *          transform.position = device.transform.pos;
             *          transform.rotation = device.transform.rot;
             */

            foreach (var buttonId in buttonIds)
            {
                if (SteamVR_Controller.Input(index).GetPressDown(buttonId))
                {
                    if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                    {
                        //Debug.Log("GRAB");
                    }
                }
                if (SteamVR_Controller.Input(index).GetPressUp(buttonId))
                {
                    /*
                     * Debug.Log(buttonId + " press up");
                     * if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                     * {
                     *      SteamVR_Controller.Input(index).TriggerHapticPulse();
                     *      PrintControllerStatus(index);
                     * }
                     */
                }
                if (SteamVR_Controller.Input(index).GetPress(buttonId))
                {
                    //Debug.Log(buttonId);
                }
            }

            foreach (var buttonId in axisIds)
            {
                if (SteamVR_Controller.Input(index).GetTouchDown(buttonId))
                {
                    //Debug.Log(buttonId + " touch down");
                }
                if (SteamVR_Controller.Input(index).GetTouchUp(buttonId))
                {
                    DropItem(device);
                }
                if (SteamVR_Controller.Input(index).GetTouch(buttonId))
                {
                    var axis = SteamVR_Controller.Input(index).GetAxis(buttonId);

                    if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                    {
                        if (axis.x >= grabThreshold && GetComponentInChildren <GrabTrigger>().things.Count > 0)
                        {
                            var thing = GetComponentInChildren <GrabTrigger>().things[0];

                            if (thing != null && thing.GetComponent <ObtainableItem>() != null && thing.GetComponent <ObtainableItem>().IsObtainable)
                            {
                                itemInHand = thing.GetComponent <ObtainableItem>();
                                itemInHand.Dispatch(ObtainableItemEventType.OnPickUp, this);
                            }
                        }
                        else
                        {
                            DropItem(device);
                        }
                    }
                }
            }
        }
    }
コード例 #5
0
    void Update()
    {
        foreach (var index in controllerIndices)
        {
            //var controllerState = SteamVR_Controller.Input((int)index).GetState();
            //var t = transform;
            //var baseTransform = new SteamVR_Utils.RigidTransform(t);

            var device = SteamVR_Controller.Input(index);

            // TODO: why it does return the position and rotation with a quite noticeable delay to a real position?
            /*
            transform.position = device.transform.pos;
            transform.rotation = device.transform.rot;
            */

            foreach (var buttonId in buttonIds)
            {
                if (SteamVR_Controller.Input(index).GetPressDown(buttonId))
                {
                    if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                    {
                        //Debug.Log("GRAB");
                    }
                }
                if (SteamVR_Controller.Input(index).GetPressUp(buttonId))
                {
                    /*
                    Debug.Log(buttonId + " press up");
                    if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                    {
                        SteamVR_Controller.Input(index).TriggerHapticPulse();
                        PrintControllerStatus(index);
                    }
                    */
                }
                if (SteamVR_Controller.Input(index).GetPress(buttonId))
                {
                    //Debug.Log(buttonId);
                }
            }

            foreach (var buttonId in axisIds)
            {
                if (SteamVR_Controller.Input(index).GetTouchDown(buttonId))
                {
                    //Debug.Log(buttonId + " touch down");
                }
                if (SteamVR_Controller.Input(index).GetTouchUp(buttonId))
                {
                    DropItem(device);
                }
                if (SteamVR_Controller.Input(index).GetTouch(buttonId))
                {
                    var axis = SteamVR_Controller.Input(index).GetAxis(buttonId);

                    if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                    {
                        if (axis.x >= grabThreshold && GetComponentInChildren<GrabTrigger>().things.Count > 0)
                        {
                            var thing = GetComponentInChildren<GrabTrigger>().things[0];

                            if (thing != null && thing.GetComponent<ObtainableItem>() != null && thing.GetComponent<ObtainableItem>().IsObtainable)
                            {
                                itemInHand = thing.GetComponent<ObtainableItem>();
                                itemInHand.Dispatch(ObtainableItemEventType.OnPickUp, this);
                            }

                        }
                        else
                        {
                            DropItem(device);
                        }
                    }
                }
            }
        }
    }