自定义固定帧率更新类
using UnityEngine;
public class CustomFixedUpdate
{
public delegate void OnFixedUpdateCallback(float aDeltaTime);
private float m_FixedTimeStep;
private float m_Timer = 0;
private OnFixedUpdateCallback m_Callback;
public float MaxAllowedTimeStep { get; set; } = 0f;
public float DeltaTime
{
get => m_FixedTimeStep;
set => m_FixedTimeStep = Mathf.Max(value, 0.000001f); // max rate: 1000000
}
public float UpdateRate
{
get => 1.0f / DeltaTime;
set => DeltaTime = 1.0f / value;
}
public CustomFixedUpdate(float aTimeStep, OnFixedUpdateCallback aCallback, float aMaxAllowedTimestep = 0f)
{
if (aTimeStep <= 0f)
{
throw new System.ArgumentException("TimeStep needs to be greater than 0");