Update() public static method

public static Update ( ) : void
return void
Esempio n. 1
0
    void Update()
    {
        if (cameras.Length == 0)
        {
            enabled = false;
            return;
        }

        // If our FixedUpdate rate doesn't match our render framerate, then catch the handoff here.
        SteamVR_Utils.QueueEventOnRenderThread(Unity.k_nRenderEventID_PostPresentHandoff);

        // Force controller update in case no one else called this frame to ensure prevState gets updated.
        SteamVR_Controller.Update();

        // Dispatch any OpenVR events.
        var vr      = SteamVR.instance;
        var vrEvent = new VREvent_t();

        for (int i = 0; i < 64; i++)
        {
            if (!vr.hmd.PollNextEvent(ref vrEvent))
            {
                break;
            }

            switch ((EVREventType)vrEvent.eventType)
            {
            case EVREventType.VREvent_InputFocusCaptured:                     // another app has taken focus (likely dashboard)
                SteamVR_Utils.Event.Send("input_focus", false);
                break;

            case EVREventType.VREvent_InputFocusReleased:                     // that app has released input focus
                SteamVR_Utils.Event.Send("input_focus", true);
                break;

            default:
                var name = System.Enum.GetName(typeof(EVREventType), vrEvent.eventType);
                if (name != null)
                {
                    SteamVR_Utils.Event.Send(name.Substring(8) /*strip VREvent_*/, vrEvent);
                }
                break;
            }
        }

        // Ensure various settings to minimize latency.
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true; // don't require companion window focus
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;    // this applies to the companion window

        if (lockPhysicsUpdateRateToRenderFrequency)
        {
            Time.fixedDeltaTime = 1.0f / vr.hmd_DisplayFrequency;
        }
    }
        /// <summary>
        /// Callback for NewPoses event. Check whether devices have (dis)connected,
        /// update their state, and manage the Manipulator objects.
        /// </summary>
        /// <param name="devicePoses">The data structure containing the current state of all devices.</param>
        protected void OnDevicePosesReady(TrackedDevicePose_t[] devicePoses)
        {
            // detect devices that have (dis)connected
            for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
            {
                bool isConnected = devicePoses[i].bDeviceIsConnected;
                if (isDeviceConnected[i] != isConnected)
                {
                    SteamVR_Events.DeviceConnected.Send((int)i, isConnected);
                }
                isDeviceConnected[i] = isConnected;
            }

            OnTrackedDeviceRoleChanged(); //the events are NOT trustworthy!

            // update poses for tracked devices
            SteamVR_Controller.Update();

            // update Manipulator objects' state
            if (DeviceIndexIsValid(ControllerIndexLeft))
            {
                SteamVR_Utils.RigidTransform controllerPose = new SteamVR_Utils.RigidTransform(
                    devicePoses[ControllerIndexLeft].mDeviceToAbsoluteTracking);
                SteamVR_Controller.Device controllerState =
                    SteamVR_Controller.Input((int)ControllerIndexLeft);

                if (controllerState != null)
                {
                    // state is stored in Manipulator object
                    ManipulatorLeft.UpdateState(controllerPose, controllerState);

                    // notify listeners
                    Events.ManipulatorLeftUpdated.Send(controllerState);
                }
            }

            if (DeviceIndexIsValid(ControllerIndexRight))
            {
                SteamVR_Utils.RigidTransform controllerPose = new SteamVR_Utils.RigidTransform(
                    devicePoses[ControllerIndexRight].mDeviceToAbsoluteTracking);
                SteamVR_Controller.Device controllerState =
                    SteamVR_Controller.Input((int)ControllerIndexRight);

                if (controllerState != null)
                {
                    // state is stored in Manipulator object
                    ManipulatorRight.UpdateState(controllerPose, controllerState);

                    // notify listeners
                    Events.ManipulatorRightUpdated.Send(controllerState);
                }
            }
        }
Esempio n. 3
0
    void Update()
    {
        if (cameras.Length == 0)
        {
            enabled = false;
            return;
        }

        // Force controller update in case no one else called this frame to ensure prevState gets updated.
        SteamVR_Controller.Update();

        // Ensure various settings to minimize latency.
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true; // don't require companion window focus
        QualitySettings.maxQueuedFrames = 0;
        QualitySettings.vSyncCount      = 0;    // this applies to the companion window
    }
Esempio n. 4
0
        private void OnDevicePosesReady(TrackedDevicePose_t[] devicePoses)
        {
            // detect devices that have (dis)connected
            for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
            {
                bool isConnected = devicePoses[i].bDeviceIsConnected;
                if (isDeviceConnected[i] != isConnected)
                {
                    SteamVR_Events.DeviceConnected.Send((int)i, isConnected);
                }
                isDeviceConnected[i] = isConnected;
            }

            // update poses for tracked devices
            SteamVR_Controller.Update();

            // update Manipulator objects' state
            if (DeviceIndexIsValid(ControllerIndexLeft))
            {
                SteamVR_Utils.RigidTransform controllerPose = new SteamVR_Utils.RigidTransform(
                    devicePoses[ControllerIndexLeft].mDeviceToAbsoluteTracking);
                SteamVR_Controller.Device controllerState =
                    SteamVR_Controller.Input((int)ControllerIndexLeft);

                ManipulatorLeft.GetComponent <Manipulator>().UpdateState(controllerPose, controllerState);
            }

            if (DeviceIndexIsValid(ControllerIndexRight))
            {
                SteamVR_Utils.RigidTransform controllerPose = new SteamVR_Utils.RigidTransform(
                    devicePoses[ControllerIndexRight].mDeviceToAbsoluteTracking);
                SteamVR_Controller.Device controllerState =
                    SteamVR_Controller.Input((int)ControllerIndexRight);

                ManipulatorRight.GetComponent <Manipulator>().UpdateState(controllerPose, controllerState);
            }
        }
Esempio n. 5
0
    private void Update()
    {
#if !(UNITY_5_6)
        if (poseUpdater == null)
        {
            var go = new GameObject("poseUpdater");
            go.transform.parent = transform;
            poseUpdater         = go.AddComponent <SteamVR_UpdatePoses>();
        }
#endif
        // Force controller update in case no one else called this frame to ensure prevState gets updated.
        SteamVR_Controller.Update();

        // Dispatch any OpenVR events.
        var system = OpenVR.System;
        if (system != null)
        {
            var vrEvent = new VREvent_t();
            var size    = (uint)Marshal.SizeOf(typeof(VREvent_t));
            for (int i = 0; i < 64; i++)
            {
                if (!system.PollNextEvent(ref vrEvent, size))
                {
                    break;
                }

                switch ((EVREventType)vrEvent.eventType)
                {
                case EVREventType.VREvent_InputFocusCaptured:
                    // another app has taken focus (likely dashboard)
                    if (vrEvent.data.process.oldPid == 0)
                    {
                        SteamVR_Events.InputFocus.Send(false);
                    }
                    break;

                case EVREventType.VREvent_InputFocusReleased: // that app has released input focus
                    if (vrEvent.data.process.pid == 0)
                    {
                        SteamVR_Events.InputFocus.Send(true);
                    }
                    break;

                case EVREventType.VREvent_ShowRenderModels:
                    SteamVR_Events.HideRenderModels.Send(false);
                    break;

                case EVREventType.VREvent_HideRenderModels:
                    SteamVR_Events.HideRenderModels.Send(true);
                    break;

                default:
                    SteamVR_Events.System((EVREventType)vrEvent.eventType).Send(vrEvent);
                    break;
                }
            }
        }

        // Ensure various settings to minimize latency.
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true; // don't require companion window focus
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;    // this applies to the companion window

        if (lockPhysicsUpdateRateToRenderFrequency && Time.timeScale > 0.0f)
        {
            var vr = SteamVR.instance;
            if (vr != null)
            {
                var timing = new Compositor_FrameTiming();
                timing.m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming));
                vr.compositor.GetFrameTiming(ref timing, 0);

                Time.fixedDeltaTime = Time.timeScale / vr.hmd_DisplayFrequency;
            }
        }
    }
Esempio n. 6
0
    protected override void OnUpdate()
    {
#if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4_5)
        if (poseUpdater == null)
        {
            var go = new GameObject("poseUpdater");
            go.transform.parent = transform;
            poseUpdater         = go.AddComponent <SteamVR_UpdatePoses>();
        }
#else
        if (cameras.Length == 0)
        {
            enabled = false;
            return;
        }

        // If our FixedUpdate rate doesn't match our render framerate, then catch the handoff here.
        SteamVR_Utils.QueueEventOnRenderThread(SteamVR.Unity.k_nRenderEventID_PostPresentHandoff);
#endif
        // Force controller update in case no one else called this frame to ensure prevState gets updated.
        SteamVR_Controller.Update();

        // Dispatch any OpenVR events.
        var system = OpenVR.System;
        if (system != null)
        {
            var vrEvent = new VREvent_t();
            var size    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));
            for (int i = 0; i < 64; i++)
            {
                if (!system.PollNextEvent(ref vrEvent, size))
                {
                    break;
                }

                switch ((EVREventType)vrEvent.eventType)
                {
                case EVREventType.VREvent_InputFocusCaptured:                         // another app has taken focus (likely dashboard)
                    SteamVR_Utils.Event.Send("input_focus", false);
                    break;

                case EVREventType.VREvent_InputFocusReleased:                         // that app has released input focus
                    SteamVR_Utils.Event.Send("input_focus", true);
                    break;

                case EVREventType.VREvent_ShowRenderModels:
                    SteamVR_Utils.Event.Send("hide_render_models", false);
                    break;

                case EVREventType.VREvent_HideRenderModels:
                    SteamVR_Utils.Event.Send("hide_render_models", true);
                    break;

                default:
                    var name = System.Enum.GetName(typeof(EVREventType), vrEvent.eventType);
                    if (name != null)
                    {
                        SteamVR_Utils.Event.Send(name.Substring(8) /*strip VREvent_*/, vrEvent);
                    }
                    break;
                }
            }
        }

        // Ensure various settings to minimize latency.
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true; // don't require companion window focus
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;    // this applies to the companion window

        if (lockPhysicsUpdateRateToRenderFrequency)
        {
            var vr = SteamVR.instance;
            if (vr != null)
            {
                var timing = new Compositor_FrameTiming();
                timing.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
                vr.compositor.GetFrameTiming(ref timing, 0);

                Time.fixedDeltaTime = Time.timeScale * timing.m_nNumFramePresents / SteamVR.instance.hmd_DisplayFrequency;
            }
        }
    }
Esempio n. 7
0
    // Token: 0x06005F65 RID: 24421 RVA: 0x00218144 File Offset: 0x00216544
    private void Update()
    {
        SteamVR_Controller.Update();
        CVRSystem system = OpenVR.System;

        if (system != null)
        {
            VREvent_t arg         = default(VREvent_t);
            uint      uncbVREvent = (uint)Marshal.SizeOf(typeof(VREvent_t));
            for (int i = 0; i < 64; i++)
            {
                if (!system.PollNextEvent(ref arg, uncbVREvent))
                {
                    break;
                }
                EVREventType eventType = (EVREventType)arg.eventType;
                if (eventType != EVREventType.VREvent_InputFocusCaptured)
                {
                    if (eventType != EVREventType.VREvent_InputFocusReleased)
                    {
                        if (eventType != EVREventType.VREvent_HideRenderModels)
                        {
                            if (eventType != EVREventType.VREvent_ShowRenderModels)
                            {
                                SteamVR_Events.System((EVREventType)arg.eventType).Send(arg);
                            }
                            else
                            {
                                SteamVR_Events.HideRenderModels.Send(false);
                            }
                        }
                        else
                        {
                            SteamVR_Events.HideRenderModels.Send(true);
                        }
                    }
                    else if (arg.data.process.pid == 0u)
                    {
                        SteamVR_Events.InputFocus.Send(true);
                    }
                }
                else if (arg.data.process.oldPid == 0u)
                {
                    SteamVR_Events.InputFocus.Send(false);
                }
            }
        }
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true;
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;
        if (this.lockPhysicsUpdateRateToRenderFrequency && Time.timeScale > 0f)
        {
            SteamVR instance = SteamVR.instance;
            if (instance != null)
            {
                Compositor_FrameTiming compositor_FrameTiming = default(Compositor_FrameTiming);
                compositor_FrameTiming.m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming));
                instance.compositor.GetFrameTiming(ref compositor_FrameTiming, 0u);
                Time.fixedDeltaTime = Time.timeScale / instance.hmd_DisplayFrequency;
            }
        }
    }
Esempio n. 8
0
    void Update()
    {
        // Force controller update in case no one else called this frame to ensure prevState gets updated.
        SteamVR_Controller.Update();

        // If our FixedUpdate rate doesn't match our render framerate, then catch the handoff here.
        //SteamVR_Utils.QueueEventOnRenderThread(SteamVR.Unity.k_nRenderEventID_PostPresentHandoff);

        // Dispatch any OpenVR events.
        var system = OpenVR.System;

        if (system != null)
        {
            var vrEvent = new VREvent_t();
            var size    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));
            for (int i = 0; i < 64; i++)
            {
                if (!system.PollNextEvent(ref vrEvent, size))
                {
                    break;
                }

                switch ((EVREventType)vrEvent.eventType)
                {
                case EVREventType.VREvent_InputFocusCaptured:                         // another app has taken focus (likely dashboard)
                    if (vrEvent.data.process.oldPid == 0)
                    {
                        SteamVR_Events.InputFocus.Send(false);
                    }
                    break;

                case EVREventType.VREvent_InputFocusReleased:                         // that app has released input focus
                    if (vrEvent.data.process.pid == 0)
                    {
                        SteamVR_Events.InputFocus.Send(true);
                    }
                    break;

                case EVREventType.VREvent_ShowRenderModels:
                    SteamVR_Events.HideRenderModels.Send(false);
                    break;

                case EVREventType.VREvent_HideRenderModels:
                    SteamVR_Events.HideRenderModels.Send(true);
                    break;

                default:
                    SteamVR_Events.System((EVREventType)vrEvent.eventType).Send(vrEvent);
                    break;
                }
            }
        }

        // Ensure various settings to minimize latency.
        Application.targetFrameRate     = -1;
        Application.runInBackground     = true; // don't require companion window focus
        QualitySettings.maxQueuedFrames = -1;
        QualitySettings.vSyncCount      = 0;    // this applies to the companion window

        if (lockPhysicsUpdateRateToRenderFrequency && Time.timeScale > 0.0f)
        {
            var vr = SteamVR.instance;
            if (vr != null)
            {
                var timing = new Compositor_FrameTiming();
                timing.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
                vr.compositor.GetFrameTiming(ref timing, 0);

                Time.fixedDeltaTime = Time.timeScale / vr.hmd_DisplayFrequency;
            }
        }
    }