void Awake() { // シングルトン if (s_Instance) { Destroy(gameObject); } else { s_Instance = gameObject; DontDestroyOnLoad(gameObject); TargetFrameRate = m_TargetFrameRate; FPSCheckIntervalTime = m_FPSCheckIntervalTime; FPSAdjustment = m_FPSAdjustment; Application.targetFrameRate = TargetFrameRate; #if UNITY_EDITOR m_PrevTargetFrameRate = m_TargetFrameRate; m_PrevFPSCheckIntervalTime = m_FPSCheckIntervalTime; m_PrevFPSAdjustment = m_FPSAdjustment; #endif } }
void Update() { #if UNITY_EDITOR // インスペクターからの値反映や // インスペクターへの表示 if (m_TargetFrameRate == m_PrevTargetFrameRate) { m_TargetFrameRate = TargetFrameRate; m_PrevTargetFrameRate = m_TargetFrameRate; } else { TargetFrameRate = m_TargetFrameRate; m_PrevTargetFrameRate = m_TargetFrameRate; } if (m_FPSCheckIntervalTime == m_PrevFPSCheckIntervalTime) { m_FPSCheckIntervalTime = FPSCheckIntervalTime; m_PrevFPSCheckIntervalTime = m_FPSCheckIntervalTime; } else { FPSCheckIntervalTime = m_FPSCheckIntervalTime; m_PrevFPSCheckIntervalTime = m_FPSCheckIntervalTime; } if (m_FPSAdjustment == m_PrevFPSAdjustment) { m_FPSAdjustment = FPSAdjustment; m_PrevFPSAdjustment = m_FPSAdjustment; } else { FPSAdjustment = m_FPSAdjustment; m_PrevFPSAdjustment = m_FPSAdjustment; } #endif // 独自delta timeの更新 if (TargetFrameRate <= 0) { UnscaledDeltaTime = Time.unscaledDeltaTime; DeltaTime = Time.deltaTime; } else { UnscaledDeltaTime = 1f / TargetFrameRate; DeltaTime = UnscaledDeltaTime * Time.timeScale; } // CurrentFPSの更新 m_FrameCountSinceCheck++; m_TimeSinceCheck += Time.unscaledDeltaTime; if (m_TimeSinceCheck >= m_FPSCheckIntervalTime) { CurrentFPS = m_FrameCountSinceCheck / m_TimeSinceCheck; m_FrameCountSinceCheck = 0; m_TimeSinceCheck = 0f; } // WaitForFramesで使うtime scaleを確保 TimeScale = Time.timeScale; }