示例#1
0
    // 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;
            }
        }
    }
示例#2
0
    // 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.");
        }
    }