//------------------------------------------------- IEnumerator Start() { // save off player instance playerInstance = Player.instance; if (!playerInstance) { Debug.LogError("No player instance found in Hand Start()"); } // allocate array for colliders overlappingColliders = new Collider[ColliderArraySize]; // 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; } //Debug.Log( "Hand - initializing connection routine" ); // 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; } //Debug.Log( "Hand - checking controllers..." ); // 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) { //Debug.Log( string.Format( "...Left/right hand relationship not yet established: leftIndex={0}, 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.ETrackedDeviceClass.Controller) { //Debug.Log( string.Format( "Hand - device {0} is not a controller", i ) ); continue; } var device = SteamVR_Controller.Input(i); if (!device.valid) { //Debug.Log( string.Format( "Hand - device {0} is not valid", i ) ); continue; } if ((otherHand != null) && (otherHand.controller != null)) { // Other hand is using this index, so we cannot use it. if (i == (int)otherHand.controller.index) { //Debug.Log( string.Format( "Hand - device {0} is owned by the other hand", i ) ); continue; } } InitController(i); } } } }