Skip to content

Instantly share code, notes, and snippets.

@h-sigma
Created January 30, 2022 15:59
Show Gist options
  • Save h-sigma/2e238000c6fb7c16494a4100ac8aa536 to your computer and use it in GitHub Desktop.
Save h-sigma/2e238000c6fb7c16494a4100ac8aa536 to your computer and use it in GitHub Desktop.
public interface ITimeProvider
{
float renderDeltaTime { get; }
float fixedDeltaTime { get; } //ideally, do not include this, and use Time.fixedDeltaTime always
float renderTime { get; }
float fixedTime { get; }
}
public class TimeProvider : MonoBehavior
{
public static ITimeProvider Interface { get; private set; }
public static ITimeProvider Gameplay { get; private set; }
//usage:
// UpdateMaterialColor(TimeProvider.Gameplay.renderDeltaTime);
// jumpCooldown = Mathf.Max(0, jumpCooldown - jumpCooldownRate * TimeProvider.Gameplay.fixedDeltaTime);
public void Awake()
{
Interface = new TimeProviderImpl();
Gameplay = new TimeProviderImpl();
}
}
// You can do multiple approaches for TimeProviderImpl based on your game
// 1. Implement a separate class for each type of time provider, and hard-code how it gets the interface values,
// possibly without any changes from UnityEngine.Time
// 2. Implement an accumulator-type implementation, where you feed it the delta every update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment