public void Start() { SteamVR.enabled = true; gameObject.SetActive(true); steamVrObject = gameObject.GetComponent <SteamVR_TrackedObject>(); if (steamVrObject == null) { return; } if (gameObject.name == "Controller (left)") { steamVrObject.index = SteamVR_TrackedObject.EIndex.Device2; } if (gameObject.name == "Controller (right)") { steamVrObject.index = SteamVR_TrackedObject.EIndex.Device3; } if (gameObject.name == "Camera (eye)") { steamVrObject.index = SteamVR_TrackedObject.EIndex.Hmd; } steamVRTrackedController = gameObject.GetComponent <SteamVR_TrackedController>(); if (steamVRTrackedController != null) { steamVRTrackedController.SetDeviceIndex((int)steamVrObject.index); steamVRTrackedController.controllerStateProvider = this; } SteamVR_Events.DeviceConnected.Send((int)steamVrObject.index, linkedList.Count > 0); }
private void SwitchControllers() { leftHanded = !leftHanded; Transform toggleParent = GameObject.Find("Tablet(Clone)"). transform.Find("Tablet"). Find("FrontSide"). Find("Canvas"). Find("UI_changeHand"); GameObject rightToggle = toggleParent.Find("Toggle_right").gameObject; GameObject leftToggle = toggleParent.Find("Toggle_left").gameObject; if (leftHanded) { rightToggle.GetComponent <Toggle>().isOn = false; leftToggle.GetComponent <Toggle>().isOn = true; } SteamVR_TrackedObject lo = GameObject.Find("Controller (left)").GetComponent <SteamVR_TrackedObject>(); SteamVR_TrackedController lc = GameObject.Find("Controller (left)").GetComponent <SteamVR_TrackedController>(); SteamVR_TrackedObject ro = GameObject.Find("Controller (right)").GetComponent <SteamVR_TrackedObject>(); SteamVR_TrackedController rc = GameObject.Find("Controller (right)").GetComponent <SteamVR_TrackedController>(); int tmp = (int)ro.index; ro.SetDeviceIndex((int)lo.index); rc.SetDeviceIndex((int)lo.index); lo.SetDeviceIndex(tmp); lc.SetDeviceIndex(tmp); // Decalle tablet GameObject tablet = GameObject.Find("Tablet(Clone)").transform.Find("Tablet").gameObject; if (leftHanded) { GameObject leftPoint = GameObject.Find("Tablet(Clone)").transform.Find("LeftPoint").gameObject; tablet.transform.position = leftPoint.transform.position; } else { GameObject rightPoint = GameObject.Find("Tablet(Clone)").transform.Find("RightPoint").gameObject; tablet.transform.position = rightPoint.transform.position; } }
public bool SetPads(bool noCameraTracking) { bool controllerFound = false; uint leftIndex = OpenVR.k_unTrackedDeviceIndexInvalid, rightIndex = OpenVR.k_unTrackedDeviceIndexInvalid; var system = OpenVR.System; if (system != null) { leftIndex = system.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand); rightIndex = system.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand); } int index = 0; if (devices.Count == 0) { return(false); } if (!noCameraTracking) { foreach (SteamVR_Controller.Device d in devices) { if ((d.index != OpenVR.k_unTrackedDeviceIndexInvalid && d.index != leftIndex && d.index != rightIndex && leftIndex != OpenVR.k_unTrackedDeviceIndexInvalid && rightIndex != OpenVR.k_unTrackedDeviceIndexInvalid) || d.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) { controllerIndexZEDHolder = (int)d.index; ZEDControllerSet = true; controllerFound = true; break; } } } else if (noCameraTracking) { ZEDControllerSet = true; controllerFound = true; controllerIndexZEDHolder = -2; } foreach (SteamVR_Controller.Device d in devices) { if (ZEDControllerSet && controllerIndexZEDHolder != (int)d.index && d.valid) { while (index < controllersGameObject.Count && !controllersGameObject[index].activeInHierarchy) { index++; } SteamVR_TrackedController c = controllersGameObject[index].GetComponent <SteamVR_TrackedController>(); if (c == null) { c = controllersGameObject[index].AddComponent <SteamVR_TrackedController>(); } if (controllerObject == null) { controllerObject = controllersGameObject[index]; } c.SetDeviceIndex((int)d.index); controllers.Add(c); padsSet = true; } index++; } return(controllerFound); }