// Use this for initialization void Start() { #if UNITY_EDITOR if (Application.isPlaying) { return; } #endif // should get current system focus device type systemEventType = WaveVR_Utils.WVR_GetFocusedController(); PrintDebugLog("Start() Focus controller: " + systemEventType); }
private void SetEmitter(GameObject gobj) { WaveVR_Beam _beam = gobj.GetComponent <WaveVR_Beam> (); WaveVR_ControllerPointer _pointer = gobj.GetComponent <WaveVR_ControllerPointer> (); if (_beam == null && _pointer == null) { return; } WaveVR_Controller.EDeviceType _focus_dev = WaveVR_Controller.EDeviceType.Head; #if UNITY_EDITOR if (Application.isEditor) { _focus_dev = this.Type; } else #endif { WVR_DeviceType _focus_dt = WaveVR_Utils.WVR_GetFocusedController(); if (_focus_dt == WVR_DeviceType.WVR_DeviceType_Controller_Right) { _focus_dev = WaveVR_Controller.EDeviceType.Dominant; } if (_focus_dt == WVR_DeviceType.WVR_DeviceType_Controller_Left) { _focus_dev = WaveVR_Controller.EDeviceType.NonDominant; } } if (_focus_dev == WaveVR_Controller.EDeviceType.Head) { return; } if (_focus_dev != this.Type) { if (_beam != null) { PrintDebugLog("SetEmitter() focus type: " + _focus_dev + " hide beam."); _beam.ShowBeam = false; } if (_pointer != null) { PrintDebugLog("SetEmitter() focus type: " + _focus_dev + " hide pointer."); _pointer.ShowPointer = false; } } }
void OnApplicationPause(bool pauseStatus) { #if UNITY_EDITOR if (Application.isPlaying) { return; } #endif if (!pauseStatus) // resume { systemEventType = WaveVR_Utils.WVR_GetFocusedController(); PrintDebugLog("Application resume, Focus controller: " + systemEventType); isFocusCapturedBySystemLastFrame = false; this.toSetActiveOfEmitter = true; } }
// Update is called once per frame void Update() { #if UNITY_EDITOR if (Application.isPlaying) { return; } #endif if (Interop.WVR_IsInputFocusCapturedBySystem()) { if (!isFocusCapturedBySystemLastFrame) { foreach (ControllerInstance t in ctrInstanceList) { bool ret = ForceSetActiveOfEmitter(t, false); } } isFocusCapturedBySystemLastFrame = true; return; } if (isFocusCapturedBySystemLastFrame) { systemEventType = WaveVR_Utils.WVR_GetFocusedController(); PrintDebugLog("back from overlay() Focus controller: " + systemEventType); isFocusCapturedBySystemLastFrame = false; this.toSetActiveOfEmitter = true; } if (this.ctrInstanceList.Count < 1) { this.lastEventType = WVR_DeviceType.WVR_DeviceType_Invalid; return; } PrintIntervalLog(() => "Controller instance: " + ctrInstanceList.Count + ", Focus controller: " + systemEventType); if (this.ctrInstanceList.Count == 1) { ControllerInstance t = ctrInstanceList [0]; this.systemEventType = t.type; if (this.isCtrInstanceUpdated) { this.isCtrInstanceUpdated = !this.isCtrInstanceUpdated; PrintDebugLog("Update() Controller focus changes to " + this.systemEventType); } } else // count > 1 { if (this.systemEventType == WVR_DeviceType.WVR_DeviceType_Controller_Right) { if (WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Left).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger) || WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Left).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Trigger)) { this.systemEventType = WVR_DeviceType.WVR_DeviceType_Controller_Left; PrintDebugLog("Update() Controller focus changes from Right to Left, set to runtime."); } } if (this.systemEventType == WVR_DeviceType.WVR_DeviceType_Controller_Left) { // Listen to right if (WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Right).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger) || WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Right).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Trigger)) { this.systemEventType = WVR_DeviceType.WVR_DeviceType_Controller_Right; PrintDebugLog("Update() Controller focus changes from Left to Right, set to runtime."); } } } if (this.lastEventType != this.systemEventType || this.connectionUpdated) { this.lastEventType = this.systemEventType; PrintDebugLog("Update() current focus: " + this.systemEventType); this.connectionUpdated = false; if (this.systemEventType == WVR_DeviceType.WVR_DeviceType_Controller_Right) { activateEventSystem(WVR_DeviceType.WVR_DeviceType_Controller_Right, true); activateEventSystem(WVR_DeviceType.WVR_DeviceType_Controller_Left, false); } if (this.systemEventType == WVR_DeviceType.WVR_DeviceType_Controller_Left) { activateEventSystem(WVR_DeviceType.WVR_DeviceType_Controller_Right, false); activateEventSystem(WVR_DeviceType.WVR_DeviceType_Controller_Left, true); } WaveVR_Utils.WVR_SetFocusedController(this.systemEventType); this.toSetActiveOfEmitter = true; } setActiveOfEmitter(); }