// This coroutine when started, will wait for every end of frame and then // call the PostFrameUpdate of the vrKernel. private IEnumerator PostFrameUpdate() { while (ContinuePostFrameUpdate) { yield return(new WaitForEndOfFrame()); var mgr = GetComponent <VRManagerScript>(); if (mgr != null && MiddleVR.VRKernel == null) { Debug.LogWarning("[ ] If you have an error mentioning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable."); #pragma warning disable 618 mgr.GetComponent <GUIText>().text = "[ ] Check the console window to check if you have an error mentioning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable."; #pragma warning restore 618 } MVRTools.Log(4, "[>] Unity: Start of VR PostFrameUpdate."); if (kernel == null || deviceMgr == null || clusterMgr == null) { InitManagers(); } if (deviceMgr != null) { var keyboard = deviceMgr.GetKeyboard(); if (keyboard != null) { // Because when the voice chat is on the input are not redirected to MiddleVR we need to check the Input.GetKey(KeyCode.Escape) if (mgr != null && mgr.QuitOnEsc && (keyboard.IsKeyPressed((uint)MiddleVR.VRK_ESCAPE) || Input.GetKey(KeyCode.Escape))) { mgr.QuitApplication(); } } else { if (!LoggedNoKeyboard) { MVRTools.Log("[X] No VR keyboard."); LoggedNoKeyboard = true; } } } if (kernel != null) { kernel.PostFrameUpdate(); } MVRTools.Log(4, "[<] Unity: End of VR PostFrameUpdate."); if (kernel != null && kernel.GetFrame() == 2 && !Application.isEditor) { MVRTools.Log(2, "[ ] If the application is stuck here and you're using Quad-buffer active stereoscopy, make sure that in the Player Settings of Unity, the option 'Run in Background' is checked."); } } }
// Update is called once per frame void Update() { //MVRTools.Log("VRManagerUpdate"); // Initialize interactions if (!m_InteractionsInitialized) { _SetNavigation(Navigation); _SetManipulation(Manipulation); _SetVirtualHandMapping(VirtualHandMapping); m_InteractionsInitialized = true; } MVRNodesMapper nodesMapper = MVRNodesMapper.Instance; nodesMapper.UpdateNodesUnityToMiddleVR(); if (m_isInit) { MVRTools.Log(4, "[>] Unity Update - Start"); if (m_Kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor) { if (!DontChangeWindowGeometry) { m_DisplayMgr.SetUnityWindowGeometry(); } m_isGeometrySet = true; } if (m_Kernel.GetFrame() == 0) { // Set the random seed in kernel for dispatching only during start-up. // With clustering, a client will be set by a call to kernel.Update(). if (!m_ClusterMgr.IsCluster() || (m_ClusterMgr.IsCluster() && m_ClusterMgr.IsServer())) { // The cast is safe because the seed is always positive. uint seed = (uint)UnityEngine.Random.seed; m_Kernel._SetRandomSeed(seed); } } m_Kernel.Update(); if (m_Kernel.GetFrame() == 0) { // Set the random seed in a client only during start-up. if (m_ClusterMgr.IsCluster() && m_ClusterMgr.IsClient()) { // The cast is safe because the seed comes from // a previous value of Unity. int seed = (int)m_Kernel.GetRandomSeed(); UnityEngine.Random.seed = seed; } } UpdateInput(); if (ShowFPS) { this.GetComponent <GUIText>().text = m_Kernel.GetFPS().ToString("f2"); } nodesMapper.UpdateNodesMiddleVRToUnity(false); MVRTools.UpdateCameraProperties(); if (m_displayLog) { string txt = m_Kernel.GetLogString(true); print(txt); m_GUI.text = txt; } vrKeyboard keyb = m_DeviceMgr.GetKeyboard(); if (keyb != null) { if (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)) { if (keyb.IsKeyToggled(MiddleVR.VRK_D)) { ShowFPS = !ShowFPS; } if (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z)) { ShowWand = !ShowWand; ShowWandGeometry(ShowWand); } // Toggle Fly mode on interactions if (keyb.IsKeyToggled(MiddleVR.VRK_F)) { Fly = !Fly; } // Navigation mode switch if (keyb.IsKeyToggled(MiddleVR.VRK_N)) { vrInteraction navigation = _GetNextInteraction("ContinuousNavigation"); if (navigation != null) { MiddleVR.VRInteractionMgr.Activate(navigation); } } } } DeltaTime = m_Kernel.GetDeltaTime(); MVRTools.Log(4, "[<] Unity Update - End"); } else { //Debug.LogWarning("[ ] If you have an error mentioning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable."); } // If QualityLevel changed, we have to reset the Unity Manager if (m_NeedDelayedRenderingReset) { if (m_RenderingResetDelay == 0) { MVRTools.Log(3, "[ ] Graphic quality forced, reset Unity Manager."); MVRTools.VRReset(); MVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA); m_isGeometrySet = false; m_NeedDelayedRenderingReset = false; } else { --m_RenderingResetDelay; } } }
// Update is called once per frame protected void Update() { // Initialize interactions if (!m_InteractionsInitialized) { _SetNavigation(Navigation); _SetManipulation(Manipulation); _SetVirtualHandMapping(VirtualHandMapping); m_InteractionsInitialized = true; } MVRNodesMapper nodesMapper = MVRNodesMapper.Instance; nodesMapper.UpdateNodesUnityToMiddleVR(); if (m_isInit) { MVRTools.Log(4, "[>] Unity Update - Start"); if (m_Kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor) { if (!DontChangeWindowGeometry) { m_DisplayMgr.SetUnityWindowGeometry(); } m_isGeometrySet = true; } // Set the random seed in kernel for dispatching only during start-up. if (m_Kernel.GetFrame() == 0) { // Disable obsolescence warning for Random.seed as we only use it to initalize // the MiddleVR random seed. // Using Random.seed was deprecated because it is a single integer and does not // contain the full state of the random number generator and thus could not be // used for restoring or synchronizing the state. #pragma warning disable 618 // The cast is safe because the seed is always positive. m_Kernel._SetRandomSeed((uint)UnityEngine.Random.seed); #pragma warning restore 618 // With clustering, a client will be set by a call to kernel.Update(). if (m_ClusterMgr.IsCluster()) { if (m_shareRandomStateCommand == null) { m_shareRandomStateCommand = new vrCommand("MVR_ShareRandomState", (vrValue val) => { UnityEngine.Random.state = JsonUtility.FromJson <UnityEngine.Random.State>(val.GetString()); return(new vrValue()); }); } if (m_ClusterMgr.IsServer()) { m_shareRandomStateCommand.Do(new vrValue(JsonUtility.ToJson(UnityEngine.Random.state))); } } } m_Kernel.Update(); UpdateInput(); if (ShowFPS) { m_FPSText.text = m_Kernel.GetFPS().ToString("f2"); } nodesMapper.UpdateNodesMiddleVRToUnity(false); MVRTools.UpdateCameraProperties(m_Kernel, m_DisplayMgr, nodesMapper); vrKeyboard keyb = m_DeviceMgr.GetKeyboard(); if (keyb != null) { if (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)) { if (keyb.IsKeyToggled(MiddleVR.VRK_D)) { ShowFPS = !ShowFPS; } if (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z)) { ShowWand = !ShowWand; ShowWandGeometry(ShowWand); } // Toggle Fly mode on interactions if (keyb.IsKeyToggled(MiddleVR.VRK_F)) { Fly = !Fly; } // Navigation mode switch if (keyb.IsKeyToggled(MiddleVR.VRK_N)) { vrInteraction navigation = _GetNextInteraction("ContinuousNavigation"); if (navigation != null) { MiddleVR.VRInteractionMgr.Activate(navigation); } } } } DeltaTime = m_Kernel.GetDeltaTime(); MVRTools.Log(4, "[<] Unity Update - End"); } else { //Debug.LogWarning("[ ] If you have an error mentioning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable."); } }
IEnumerator EndOfFrame() { yield return(new WaitForEndOfFrame()); VRManagerScript mgr = GetComponent <VRManagerScript>(); if (mgr != null && MiddleVR.VRKernel == null) { Debug.LogWarning("[ ] If you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable."); mgr.GetComponent <GUIText>().text = "[ ] Check the console window to check if you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable."; } MVRTools.Log(4, "[>] Unity: Starting VR End of Frame."); if (kernel == null) { kernel = MiddleVR.VRKernel; } if (dmgr == null) { dmgr = MiddleVR.VRDeviceMgr; } if (cmgr == null) { cmgr = MiddleVR.VRClusterMgr; } if (dmgr != null) { vrKeyboard keyb = dmgr.GetKeyboard(); if (keyb != null) { VRManagerScript vrmgr = GetComponent <VRManagerScript>(); if (vrmgr != null && vrmgr.QuitOnEsc && keyb.IsKeyPressed((uint)MiddleVR.VRK_ESCAPE)) { vrmgr.QuitApplication(); } } else { if (!LoggedNoKeyboard) { MVRTools.Log("[X] No VR keyboard"); LoggedNoKeyboard = true; } } } if (kernel != null) { /* * MVRTools.Log("SavingRT"); ; * SaveRT(); */ kernel.PostFrameUpdate(); } MVRTools.Log(4, "[<] Unity: End of VR End of Frame."); if (kernel != null && kernel.GetFrame() == 2 && !Application.isEditor) { MVRTools.Log(2, "[ ] If the application is stuck here and you're using Quad-buffer active stereoscopy, make sure that in the Player Settings of Unity, the option 'Run in Background' is checked."); } }