// Magica Cloth. // Copyright (c) MagicaSoft, 2020-2022. // https://magicasoft.jp using UnityEngine; namespace MagicaCloth { /// /// 時間管理クラス /// [System.Serializable] public class UpdateTimeManager { // アップデート回数 public enum UpdateCount { _60 = 60, _90_Default = 90, _120 = 120, _150 = 150, _180 = 180, } // 1秒間の更新回数 [SerializeField] private UpdateCount updatePerSeccond = UpdateCount._90_Default; // 更新モード public enum UpdateMode { UnscaledTime = 0, // 非同期更新 OncePerFrame = 1, // 固定更新(基本1フレームに1回) DelayUnscaledTime = 10, // 非同期更新(遅延実行) } [SerializeField] private UpdateMode updateMode = UpdateMode.UnscaledTime; // グローバルタイムスケール private float timeScale = 1.0f; /// /// 遅延実行時の未来予測率 /// [SerializeField] [Range(0.0f, 1.0f)] private float futurePredictionRate = 1.0f; /// /// ボーンスケールの更新(Unity2019.2.13まで) /// [SerializeField] private bool updateBoneScale = false; private int fixedUpdateCount = 0; //========================================================================================= public void ResetFixedUpdateCount() { fixedUpdateCount = 0; } public void AddFixedUpdateCount() { fixedUpdateCount++; } public int FixedUpdateCount { get { return fixedUpdateCount; } } /// /// アップデートモード取得 /// /// public UpdateMode GetUpdateMode() { return updateMode; } public void SetUpdateMode(UpdateMode mode) { updateMode = mode; } /// /// 1秒間の更新回数 /// public int UpdatePerSecond { get { return (int)updatePerSeccond; } } public void SetUpdatePerSecond(UpdateCount ucount) { updatePerSeccond = ucount; } /// /// 更新間隔時間 /// public float UpdateIntervalTime { get { return 1.0f / UpdatePerSecond; } } /// /// 更新力(90upsを基準とした倍数) /// 60fps = 1.5 / 90ups = 1.0f / 120fps = 0.75 /// public float UpdatePower { get { float power = 90.0f / (float)UpdatePerSecond; //power = Mathf.Pow(power, 0.3f); // 調整 return power; } } /// /// タイムスケール /// 1.0未満に設定することで全体のスロー再生が可能 /// ただし完全なスローではないので注意 /// public float TimeScale { get { return timeScale; } set { timeScale = Mathf.Clamp01(value); } } /// /// 現在のフレーム更新時間 /// public float DeltaTime { get { return Time.deltaTime; } } public float PhysicsDeltaTime { get { return Time.fixedDeltaTime * fixedUpdateCount; } } /// /// 現在の平均フレーム更新時間(=平均FPS) /// public float AverageDeltaTime { get { return Time.smoothDeltaTime; } } /// /// 非同期時間更新判定 /// public bool IsUnscaledUpdate { get { return updateMode == UpdateMode.UnscaledTime || updateMode == UpdateMode.DelayUnscaledTime; } } /// /// 遅延実行判定 /// public bool IsDelay { get { return updateMode == UpdateMode.DelayUnscaledTime; } } /// /// 遅延実行時の未来予測率(0.0-1.0) /// public float FuturePredictionRate { get { return futurePredictionRate; } set { futurePredictionRate = Mathf.Clamp01(value); } } /// /// ボーンスケール更新判定(Unity2019.2.13まで) /// public bool UpdateBoneScale { get { return updateBoneScale; } set { updateBoneScale = value; } } /// /// この端末が使用可能なワーカースレッド数 /// /// public int WorkerMaximumCount { get { return Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerMaximumCount; } } } }