Ejemplo n.º 1
0
    public override string GetDeviceName(NVRHand hand)
    {
        var renderModel = hand.GetComponentInChildren <SteamVR_RenderModel>();

        if (renderModel != null)
        {
            return(hand.GetComponentInChildren <SteamVR_RenderModel>().renderModelName);
        }
        else
        {
            return("Custom");
        }
    }
Ejemplo n.º 2
0
    private IEnumerator DoInitSteamVRModels(NVRHand hand)
    {
        Debug.Log("Waiting for models to load... ");

        // Check to see if models have already been loaded for the controllers.
        // This is the case if a custom model was provided, or if we're loading a new
        // scene after the SteamVR models were loaded in a previous scene.
        if (hand.CustomModel == null)
        {
            var handModel = hand.GetComponentInChildren <SteamVR_RenderModel>();
            if (handModel.renderModelName != null)
            {
                Debug.Log("Hand already initialized");
            }
            else
            {
                modelsToInitialize.Add(handModel);
                do
                {
                    Debug.Log("Waiting for hand model...");
                    yield return(null); //wait for steamvr render model to be initialized
                } while (modelsToInitialize.Contains(handModel));
                Debug.Log("Initialized " + handModel.renderModelName);
            }
        }

        Debug.Log("RenderModels initialized!");

        // configure colliders
        InitColliders(hand);

        hand.DoInitialize();
    }
Ejemplo n.º 3
0
    private IEnumerator DoLongHapticPulse(NVRHand hand, float seconds)
    {
        float startTime  = Time.time;
        float endTime    = startTime + seconds;
        var   controller = SteamVR_Controller.Input((int)hand.GetComponentInChildren <SteamVR_TrackedObject>().index);

        while (Time.time < endTime)
        {
            controller.TriggerHapticPulse(100);
            yield return(null);
        }
    }
Ejemplo n.º 4
0
    public override Vector3 GetVelocity(NVRHand hand)
    {
        var controller = SteamVR_Controller.Input((int)hand.GetComponentInChildren <SteamVR_TrackedObject>().index);

        if (controller != null)
        {
            return(controller.velocity);
        }
        else
        {
            return(Vector3.zero);
        }
    }
Ejemplo n.º 5
0
    public override void TriggerHapticPulse(NVRHand hand, ushort durationMicroSec = 500)
    {
        var controller = SteamVR_Controller.Input((int)hand.GetComponentInChildren <SteamVR_TrackedObject>().index);

        if (controller != null)
        {
            if (durationMicroSec < 3000)
            {
                controller.TriggerHapticPulse(durationMicroSec);
            }
            else
            {
                Debug.LogWarning("you're trying to pulse for over 3000 microseconds, you probably don't want to do that. if you do, use longhapticpulse(float seconds)");
            }
        }
    }
Ejemplo n.º 6
0
    private void InitColliders(NVRHand hand)
    {
        Collider[] DeviceColliders;
        if (hand.CustomModel == null)
        {
            string controllerModel          = GetDeviceName(hand);
            SteamVR_RenderModel renderModel = hand.GetComponentInChildren <SteamVR_RenderModel>();

            switch (controllerModel)
            {
            case "vr_controller_05_wireless_b":
                Transform dk1Trackhat = renderModel.transform.Find("trackhat");
                if (dk1Trackhat == null)
                {
                    // Dk1 controller model has trackhat
                }
                else
                {
                    dk1Trackhat.gameObject.SetActive(true);
                }

                SphereCollider dk1TrackhatCollider = dk1Trackhat.gameObject.GetComponent <SphereCollider>();
                if (dk1TrackhatCollider == null)
                {
                    dk1TrackhatCollider           = dk1Trackhat.gameObject.AddComponent <SphereCollider>();
                    dk1TrackhatCollider.isTrigger = true;
                }

                DeviceColliders = new Collider[] { dk1TrackhatCollider };
                hand.SetColliders(DeviceColliders);
                break;

            case "vr_controller_vive_1_5":
                Transform dk2Trackhat = renderModel.transform.Find("trackhat");
                if (dk2Trackhat == null)
                {
                    dk2Trackhat = new GameObject("trackhat").transform;
                    dk2Trackhat.gameObject.layer = this.gameObject.layer;
                    dk2Trackhat.parent           = renderModel.transform;
                    dk2Trackhat.localPosition    = new Vector3(0, -0.033f, 0.014f);
                    dk2Trackhat.localScale       = Vector3.one * 0.1f;
                    dk2Trackhat.localEulerAngles = new Vector3(325, 0, 0);
                    dk2Trackhat.gameObject.SetActive(true);
                }
                else
                {
                    dk2Trackhat.gameObject.SetActive(true);
                }

                Collider dk2TrackhatCollider = dk2Trackhat.gameObject.GetComponent <SphereCollider>();
                if (dk2TrackhatCollider == null)
                {
                    dk2TrackhatCollider           = dk2Trackhat.gameObject.AddComponent <SphereCollider>();
                    dk2TrackhatCollider.isTrigger = true;
                }

                DeviceColliders = new Collider[] { dk2TrackhatCollider };
                hand.SetColliders(DeviceColliders);
                break;

            case "Custom":
                Debug.Log("Custom colliders should be handled by NVRHand");
                break;

            default:
                Debug.LogError("Error. Unsupported device type: " + controllerModel);
                break;
            }
        }
    }