namespace VRTK.Prefabs.CameraRig.SimulatedCameraRig { using UnityEngine; using UnityEngine.XR; using Malimbe.XmlDocumentationAttribute; using Malimbe.PropertySerializationAttribute; using Zinnia.Extension; using Zinnia.Data.Attribute; /// /// Sets up the Simulated CameraRig Prefab based on the provided user settings. /// public class SimulatorConfigurator : MonoBehaviour { #region Facade Settings /// /// The public facade. /// [Serialized] [field: Header("Facade Settings"), DocumentedByXml, Restricted] public SimulatorFacade Facade { get; protected set; } #endregion #region Control Settings /// /// The linked for the PlayArea. /// [Serialized] [field: Header("Control Settings"), DocumentedByXml, Restricted] public ActiveObjectController PersonObjectController { get; protected set; } /// /// The linked for the Left Controller. /// [Serialized] [field: DocumentedByXml, Restricted] public ActiveObjectController LeftObjectController { get; protected set; } /// /// The linked for the Right Controller. /// [Serialized] [field: DocumentedByXml, Restricted] public ActiveObjectController RightObjectController { get; protected set; } #endregion /// /// The original value of . /// protected bool wereXRSettingsEnabled; /// /// The original value of . /// protected float originalFixedDeltaTime; /// /// Disables or restores it to its original value. /// /// Whether to disable or to restore it back to its original value. public virtual void ConfigureXRSettings(bool state) { if (state) { wereXRSettingsEnabled = XRSettings.enabled; XRSettings.enabled = false; } else { XRSettings.enabled = wereXRSettingsEnabled; } } /// /// Sets to the simulated frame rate. /// public virtual void ConfigureSimulatedFrameRate() { Time.fixedDeltaTime = Time.timeScale / Facade.SimulatedFrameRate; } /// /// Configures the speed in which the objects are controlled at. /// public virtual void ConfigureControlSpeed() { PersonObjectController.RunWhenActiveAndEnabled(() => PersonObjectController.MovementSpeed = Facade.PlayerSpeed); LeftObjectController.RunWhenActiveAndEnabled(() => LeftObjectController.MovementSpeed = Facade.ControllerSpeed); RightObjectController.RunWhenActiveAndEnabled(() => RightObjectController.MovementSpeed = Facade.ControllerSpeed); } protected virtual void OnEnable() { wereXRSettingsEnabled = XRSettings.enabled; originalFixedDeltaTime = Time.fixedDeltaTime; ConfigureXRSettings(Facade.DisableXRSettings); ConfigureControlSpeed(); } protected virtual void OnDisable() { ConfigureXRSettings(false); Time.fixedDeltaTime = originalFixedDeltaTime; } } }