Created
September 1, 2020 23:51
-
-
Save ericflo/c1825e8211a8bb02dbb615cc49cb91b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyController : MonoBehaviour | |
{ | |
private void OnEnable() { | |
SetupFixedDeltaTime(); | |
} | |
private void SetupFixedDeltaTime() { | |
var xrSettings = XRGeneralSettings.Instance; | |
if (xrSettings == null) { | |
Debug.Log($"XRGeneralSettings is null."); | |
return; | |
} | |
var xrManager = xrSettings.Manager; | |
if (xrManager == null) { | |
Debug.Log($"XRManagerSettings is null."); | |
return; | |
} | |
var xrLoader = xrManager.activeLoader; | |
if (xrLoader == null) { | |
Debug.Log($"XRLoader is null."); | |
return; | |
} | |
var xrDisplay = xrLoader.GetLoadedSubsystem<XRDisplaySubsystem>(); | |
if (xrDisplay != null) { | |
if (xrDisplay.TryGetDisplayRefreshRate(out float refreshRate)) { | |
Debug.Log($"Refresh Rate: {refreshRate}hz"); | |
float nextFixedDeltaTime = Time.timeScale / refreshRate; | |
Debug.Log("Setting fixed delta time: " + nextFixedDeltaTime); | |
Time.fixedDeltaTime = nextFixedDeltaTime; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment