InitController() private method

private InitController ( int index ) : void
index int
return void
Beispiel #1
0
    IEnumerator Start()
    {
        // We are a "no SteamVR fallback hand" if we have this camera set
        // we'll use the right mouse to look around and left mouse to interact
        // - don't need to find the device
        if (noSteamVRFallbackCamera)
        {
            yield break;
        }

        // Acquire the correct device index for the hand we want to be
        // Also for the other hand if we get there first
        while (true)
        {
            // Don't need to run this every frame
            yield return(new WaitForSeconds(1.0f));

            // We have a controller now, break out of the loop!
            if (controller != null)
            {
                break;
            }

            // Initialize both hands simultaneously
            if (startingHandType == HandType.Left || startingHandType == HandType.Right)
            {
                // Left/right relationship.
                // Wait until we have a clear unique left-right relationship to initialize.
                int leftIndex  = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
                int rightIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
                if (leftIndex == -1 || rightIndex == -1 || leftIndex == rightIndex)
                {
                    continue;
                }

                int myIndex    = (startingHandType == HandType.Right) ? rightIndex : leftIndex;
                int otherIndex = (startingHandType == HandType.Right) ? leftIndex : rightIndex;

                InitController(myIndex);
                if (otherHand)
                {
                    otherHand.InitController(otherIndex);
                }
            }
            else
            {
                // No left/right relationship. Just wait for a connection

                var vr = SteamVR.instance;
                for (int i = 0; i < Valve.VR.OpenVR.k_unMaxTrackedDeviceCount; i++)
                {
                    if (vr.hmd.GetTrackedDeviceClass(( uint )i) != Valve.VR.TrackedDeviceClass.Controller)
                    {
                        continue;
                    }

                    var device = SteamVR_Controller.Input(i);
                    if (!device.connected)
                    {
                        continue;
                    }

                    if ((otherHand != null) && (otherHand.controller != null))
                    {
                        // Other hand is using this index, so we cannot use it.
                        if (i == ( int )otherHand.controller.index)
                        {
                            continue;
                        }
                    }

                    InitController(i);
                }
            }
        }
    }