Skip to content

Instantly share code, notes, and snippets.

@PopupAsylumUK
Created January 15, 2019 17:01
Show Gist options
  • Save PopupAsylumUK/1798b160ea5768c16a45a92320073227 to your computer and use it in GitHub Desktop.
Save PopupAsylumUK/1798b160ea5768c16a45a92320073227 to your computer and use it in GitHub Desktop.
Class wraps the functionality of UnityEngine.Time, and provides a static bool to unscale Time.deltaTime
public static class Time {
public static bool unscaleDeltaTime;
// The time this frame has started (RO). This is the time in seconds since the start of the game.
public static float time { get { return UnityEngine.Time.time; } }
// The time this frame has started (RO). This is the time in seconds since the last level has been loaded.
public static float timeSinceLevelLoad { get { return UnityEngine.Time.timeSinceLevelLoad; } }
// The time in seconds it took to complete the last frame (RO).
public static float deltaTime { get { return unscaleDeltaTime ? unscaledDeltaTime : UnityEngine.Time.deltaTime; } }
// The time the latest MonoBehaviour::pref::FixedUpdate has started (RO). This is the time in seconds since the start of the game.
public static float fixedTime { get { return UnityEngine.Time.fixedTime; } }
// The cached real time (realTimeSinceStartup) at the start of this frame
public static float unscaledTime { get { return UnityEngine.Time.unscaledTime; } }
// The real time corresponding to this fixed frame
public static float fixedUnscaledTime { get { return UnityEngine.Time.fixedUnscaledTime; } }
// The delta time based upon the realTime
public static float unscaledDeltaTime { get { return UnityEngine.Time.unscaledDeltaTime; } }
// The delta time based upon the realTime
public static float fixedUnscaledDeltaTime { get { return UnityEngine.Time.fixedUnscaledDeltaTime; } }
// The interval in seconds at which physics and other fixed frame rate updates (like MonoBehaviour's MonoBehaviour::pref::FixedUpdate) are performed.
public static float fixedDeltaTime { get { return UnityEngine.Time.fixedDeltaTime; } set { UnityEngine.Time.fixedDeltaTime = value; } }
// The maximum time a frame can take. Physics and other fixed frame rate updates (like MonoBehaviour's MonoBehaviour::pref::FixedUpdate)
public static float maximumDeltaTime { get { return UnityEngine.Time.maximumDeltaTime; } set { UnityEngine.Time.maximumDeltaTime = value; } }
// A smoothed out Time.deltaTime (RO).
public static float smoothDeltaTime { get { return UnityEngine.Time.smoothDeltaTime; } }
// The maximum time a frame can spend on particle updates. If the frame takes longer than this, then updates are split into multiple smaller updates.
public static float maximumParticleDeltaTime { get { return UnityEngine.Time.maximumParticleDeltaTime; } set { UnityEngine.Time.maximumParticleDeltaTime = value; } }
// The scale at which the time is passing. This can be used for slow motion effects.
public static float timeScale { get { return UnityEngine.Time.timeScale; } set { UnityEngine.Time.timeScale = value; } }
// The total number of frames that have passed (RO).
public static int frameCount { get { return UnityEngine.Time.frameCount; } }
//*undocumented*
public static int renderedFrameCount { get { return UnityEngine.Time.renderedFrameCount; } }
// The real time in seconds since the game started (RO).
public static float realtimeSinceStartup { get { return UnityEngine.Time.realtimeSinceStartup; } }
// If /captureFramerate/ is set to a value larger than 0, time will advance in
public static int captureFramerate { get { return UnityEngine.Time.captureFramerate; } set { UnityEngine.Time.captureFramerate = value; } }
// Returns true if inside a fixed time step callback such as FixedUpdate, otherwise false.
public static bool inFixedTimeStep
{
get
{
return UnityEngine.Time.inFixedTimeStep;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment