/// <summary> /// Called when [controller disconnected]. /// </summary> /// <param name="controller">The controller.</param> virtual public void OnControllerDisconnected(DpnBasePeripheral controller) { if (controller == null) { return; } controller.EnableInternalObjects(false); _connectedControllers.Remove(controller.name); if (_connectedControllers.Count == 0) { _mainController = null; SendMessageUpwards("OnPeripheralDisconnected", this); } else { if (controller == _mainController) { DpnBasePeripheral mainController = _connectedControllers.Values.First <DpnBasePeripheral>(); mainController.EnablePointer(true); _mainController = mainController; } } }
/// <summary> /// Sets the peripheral. /// </summary> /// <param name="peripheral">The peripheral.</param> public void SetPeripheral(DpnBasePeripheral peripheral) { if (_currentPeripheral) { _currentPeripheral.EnableInternalObjects(false); } _currentPeripheral = peripheral; if (_currentPeripheral) { _currentPeripheral.EnableInternalObjects(true); } }
/// <summary> /// Called when [controller connected]. /// </summary> /// <param name="controller">The controller.</param> virtual public void OnControllerConnected(DpnBasePeripheral controller) { if (controller == null) { return; } controller.EnableModel(true); if (_connectedControllers.Count == 0) { SendMessageUpwards("OnPeripheralConnected", this); controller.EnableInternalObjects(true); _mainController = controller; } _connectedControllers[controller.name] = controller; }
void InitPeripheral() { if (!CameraRigInit) { #if UNITY_5_3_OR_NEWER || UNITY_5 VRsupport = UnityEngine.XR.XRSettings.enabled; #else VRsupport = false; #endif } CameraRigInit = true; if (!Init()) { return; } base.OnEnable(); _UpdateCam(DpnManager.DeviceInfo.fov_y , DpnManager.DeviceInfo.fov_x / (float)DpnManager.DeviceInfo.fov_y); if (DpnManager.DPVRPointer) { Transform Pointer = Instantiate(reticlePointer); Pointer.SetParent(_center_transform, false); Pointer.localPosition = new Vector3(0, 0, 2); Pointer.gameObject.SetActive(true); _nonePointer = Pointer.gameObject; _nonePointer.transform.Find("Ray").gameObject.SetActive(false); } _hmdPeripheral = this; _hmdPeripheral.EnableInternalObjects(false); switch (DpnManager.peripheral) { case DPVRPeripheral.Polaris: { Transform Peripheral = Instantiate(Polaris); Peripheral.parent = this.transform; _defaultPeripheral = Peripheral.GetComponent <DpnMultiControllerPeripheralPolaris>(); _defaultPeripheral.EnableInternalObjects(false); break; } case DPVRPeripheral.Nolo: { Transform Peripheral = Instantiate(Nolo); Peripheral.parent = this.transform; Transform boundary = Instantiate(Boundary); boundary.parent = this.transform; _defaultPeripheral = Peripheral.GetComponent <DpnMultiControllerPeripheralNolo>(); _defaultPeripheral.EnableInternalObjects(false); break; } case DPVRPeripheral.Flip: { Transform Peripheral = Instantiate(Flip); Peripheral.parent = this.transform; Peripheral.localPosition = Vector3.zero; Transform controller_right = Peripheral.Find("controller(right)"); if (controller_right == null) { break; } _defaultPeripheral = controller_right.GetComponent <DpnDaydreamController>(); _defaultPeripheral.EnableInternalObjects(false); DpnDaydreamController.onUnbind += OnPeripheralUnbind; break; } case DPVRPeripheral.None: { _defaultPeripheral = _hmdPeripheral; break; } default: break; } SetPeripheral(_defaultPeripheral); }
void InitPeripheral() { if (!CameraRigInit) { #if UNITY_5_3_OR_NEWER || UNITY_5 VRsupport = UnityEngine.VR.VRSettings.enabled; #else VRsupport = false; #endif } CameraRigInit = true; if (!Init()) { return; } base.OnEnable(); if (_instance != this && _instance != null) { Debug.LogWarning("There is another active DpnCameraRig in a scene, set it unactive"); _instance.gameObject.SetActive(false); } _instance = this; _UpdateCam(DpnManager.DeviceInfo.fov_y , DpnManager.DeviceInfo.fov_x / (float)DpnManager.DeviceInfo.fov_y); if (DpnManager.DPVRPointer) { DpnPointerPhysicsRaycaster raycaster = _center_transform.gameObject.AddComponent <DpnPointerPhysicsRaycaster>(); raycaster.raycastMode = DpnBasePointerRaycaster.RaycastMode.Direct; raycaster.enabled = true; Transform Pointer = Instantiate(reticlePointer); Pointer.SetParent(raycaster.transform); Pointer.transform.localPosition = new Vector3(0.0f, 0.0f, 2.0f); Pointer.gameObject.SetActive(true); _nonePointer = Pointer.gameObject; _noneRaycaster = raycaster; } _hmdPeripheral = this; _hmdPeripheral.EnableInternalObjects(false); switch (DpnManager.peripheral) { case DPVRPeripheral.Polaris: { Transform Peripheral = Instantiate(Polaris); Peripheral.parent = this.transform; _defaultPeripheral = Peripheral.GetComponent <DpnMultiControllerPeripheralPolaris>(); _defaultPeripheral.EnableInternalObjects(false); break; } case DPVRPeripheral.Nolo: { Transform Peripheral = Instantiate(Nolo); Peripheral.parent = this.transform; Transform boundary = Instantiate(Boundary); boundary.parent = this.transform; _defaultPeripheral = Peripheral.GetComponent <DpnMultiControllerPeripheralNolo>(); _defaultPeripheral.EnableInternalObjects(false); break; } case DPVRPeripheral.Flip: { Transform Peripheral = Instantiate(Flip); Peripheral.parent = this.transform; Peripheral.localPosition = Vector3.zero; Transform controller_right = Peripheral.Find("controller(right)"); if (controller_right == null) { break; } _defaultPeripheral = controller_right.GetComponent <DpnDaydreamController>(); _defaultPeripheral.EnableInternalObjects(false); break; } case DPVRPeripheral.None: { _defaultPeripheral = _hmdPeripheral; break; } default: break; } SetPeripheral(_defaultPeripheral); }