/// <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; } } }
void EnablePointer(string name) { if (_controllers == null) { return; } if (_mainController && _mainController.name == name) { return; } DpnBasePeripheral mainController = null; for (int i = 0; i < _controllers.Length; ++i) { DpnBasePeripheral controller = _controllers[i]; if (controller && controller.name == name) { mainController = controller; } else { controller.EnablePointer(false); } } _mainController = mainController; if (_mainController != null) { _mainController.EnablePointer(true); } }
public static DpnPeripheral OpenPeripheral(string deviceId, DpnBasePeripheral basePeripheral) { if (deviceId == null) { return(null); } if (s_Peripherals.ContainsKey(deviceId)) { if (s_Peripherals[deviceId].list.Contains(basePeripheral)) { return(basePeripheral.peripheral); } else { basePeripheral.peripheral = s_Peripherals[deviceId].peripheral; s_Peripherals[deviceId].list.Add(basePeripheral); return(basePeripheral.peripheral); } } DpnPeripheral temp = DpnPeripheral.OpenPeripheralDevice(deviceId); if (temp == null) { return(null); } basePeripheral.peripheral = temp; s_Peripherals.Add(deviceId, new PeripheralList(temp)); s_Peripherals[deviceId].list.Add(basePeripheral); return(basePeripheral.peripheral); }
void OnUnbind(DpnBasePeripheral peripheral) { if (peripheral != this) { return; } _isValid = false; }
void OnPeripheralConnected(DpnBasePeripheral peripheral) { // if paired succeed, the flip controller will be connected, // and it will send the message on the connection by DpnDaydreamController // when app start, if the flip controller is paired, it will send the message also. if (!_paired) { OnPairSucceed(); } }
void OnPeripheralDisconnected(DpnBasePeripheral peripheral) { if (DpnCameraRig.followSystem) { SetPeripheralFollowSystem(); } else { SetPeripheral(_hmdPeripheral); } }
public override void OnControllerConnected(DpnBasePeripheral controller) { base.OnControllerConnected(controller); if (_connectedControllers.Count == 1 && gameObject.transform && gameObject.transform.parent) { Transform transform = gameObject.transform.parent.Find("DpnBoundary(Clone)"); if (transform) { transform.gameObject.SetActive(true); } } }
void Start() { if (_controllers == null) { return; } for (int i = 0; i < _controllers.Length; ++i) { DpnBasePeripheral controller = _controllers[i]; controller.EnableModel(true); EnablePointer(controller.name); } }
/// <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); } }
public static void ClosePeripheral(DpnBasePeripheral basePeripheral) { if (!s_Peripherals[basePeripheral.peripheral._deviceId].list.Contains(basePeripheral)) { return; } s_Peripherals[basePeripheral.peripheral._deviceId].list.Remove(basePeripheral); if (s_Peripherals[basePeripheral.peripheral._deviceId].list.Count == 0) { DpnPeripheral.ClosePeripheralDevice(basePeripheral.peripheral); s_Peripherals.Remove(basePeripheral.peripheral._deviceId); } basePeripheral.peripheral = null; return; }
/// <summary> /// Called when [enable]. /// </summary> public void OnEnable() { if (_controllers == null) { return; } for (int i = 0; i < _controllers.Length; ++i) { string name = _controllerNames[i]; DpnBasePeripheral controller = GetController(name); if (controller) { _controllers[i] = controller; _connectedControllers[name] = controller; } } }
/// <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; }
public void Awake() { _controllerNames = s_controllerNames; _controllers = new DpnBasePeripheral[2]; }
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 OnPeripheralUnbind(DpnBasePeripheral peripheral) { SetInterctiveType(0); SetPeripheral(_hmdPeripheral); }
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); }