Remove BetterBehavior and GameTime types

This commit is contained in:
Oliver Booth 2021-07-19 12:39:07 +01:00
parent 6e4a9882e9
commit 8059b067c9
No known key found for this signature in database
GPG Key ID: A4AC17007530E9B4
2 changed files with 0 additions and 161 deletions

View File

@ -1,107 +0,0 @@
namespace X10D.Unity
{
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using UnityEngine;
/// <summary>
/// Represents a class which inherits <see cref="MonoBehaviour" /> to offer wider functionality.
/// </summary>
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Unity property")]
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "Unity property")]
[SuppressMessage("ReSharper", "SA1300", Justification = "Unity API-compliant property")]
[SuppressMessage("ReSharper", "CA2007", Justification = "Unnecessary")]
[SuppressMessage("ReSharper", "RCS1090", Justification = "Unnecessary")]
[SuppressMessage("ReSharper", "RCS1213", Justification = "Unity method")]
[SuppressMessage("ReSharper", "UnusedParameter.Global", Justification = "Override method")]
public abstract class BetterBehavior : MonoBehaviour
{
/// <summary>
/// Gets the <see cref="Transform" /> component attached to this object.
/// </summary>
public new Transform transform { get; private set; }
/// <summary>
/// Awake is called when the script instance is being loaded.
/// </summary>
protected virtual void Awake()
{
this.transform = this.GetComponent<Transform>();
}
/// <summary>
/// Frame-rate independent messaging for physics calculations.
/// </summary>
/// <param name="gameTime">A snapshot of timing values.</param>
protected virtual void OnFixedUpdate(in GameTime gameTime)
{
}
/// <summary>
/// Frame-rate independent messaging for physics calculations.
/// </summary>
/// <param name="gameTime">A snapshot of timing values.</param>
/// <returns>Returns a task representing the result of the operation.</returns>
protected virtual Task OnFixedUpdateAsync(GameTime gameTime)
{
return Task.CompletedTask;
}
/// <summary>
/// Called once per frame, after all <c>Update</c> calls.
/// </summary>
/// <param name="gameTime">A snapshot of timing values.</param>
protected virtual void OnLateUpdate(in GameTime gameTime)
{
}
/// <summary>
/// Called once per frame, after all <c>Update</c> calls.
/// </summary>
/// <param name="gameTime">A snapshot of timing values.</param>
/// <returns>Returns a task representing the result of the operation.</returns>
protected virtual Task OnLateUpdateAsync(GameTime gameTime)
{
return Task.CompletedTask;
}
/// <summary>
/// Called once per frame.
/// </summary>
/// <param name="gameTime">A snapshot of timing values.</param>
protected virtual void OnUpdate(in GameTime gameTime)
{
}
/// <summary>
/// Called once per frame.
/// </summary>
/// <param name="gameTime">A snapshot of timing values.</param>
/// <returns>Returns a task representing the result of the operation.</returns>
protected virtual Task OnUpdateAsync(GameTime gameTime)
{
return Task.CompletedTask;
}
private async void FixedUpdate()
{
var time = GameTime.CreateFromCurrentTimes();
this.OnFixedUpdate(time);
await this.OnFixedUpdateAsync(time);
}
private async void LateUpdate()
{
var time = GameTime.CreateFromCurrentTimes();
this.OnLateUpdate(time);
await this.OnLateUpdateAsync(time);
}
private async void Update()
{
var time = GameTime.CreateFromCurrentTimes();
this.OnUpdate(time);
await this.OnUpdateAsync(time);
}
}
}

View File

@ -1,54 +0,0 @@
namespace X10D.Unity
{
using System;
using UnityEngine;
/// <summary>
/// Represents a struct which contains game timing information.
/// </summary>
public readonly struct GameTime
{
private GameTime(float totalTime, float deltaTime, float fixedDeltaTime, int frameCount, float timeScale)
{
this.TotalTime = TimeSpan.FromSeconds(totalTime);
this.DeltaTime = TimeSpan.FromSeconds(deltaTime);
this.FixedDeltaTime = TimeSpan.FromSeconds(fixedDeltaTime);
this.FrameCount = frameCount;
this.TimeScale = timeScale;
}
/// <summary>
/// Gets the time since the last frame was rendered.
/// </summary>
public TimeSpan DeltaTime { get; }
/// <summary>
/// Gets the time since the last physics time step.
/// </summary>
public TimeSpan FixedDeltaTime { get; }
/// <summary>
/// Gets the total number of frames which have been rendered.
/// </summary>
public int FrameCount { get; }
/// <summary>
/// Gets the total time for which the game has been running.
/// </summary>
public TimeSpan TotalTime { get; }
/// <summary>
/// Gets the time scale.
/// </summary>
public float TimeScale { get; }
/// <summary>
/// Creates a new instance of the <see cref="GameTime" /> struct by creating a snapshot of values offered by <see cref="Time" />.
/// </summary>
/// <returns>An instance of <see cref="GameTime" />.</returns>
public static GameTime CreateFromCurrentTimes()
{
return new GameTime(Time.time, Time.deltaTime, Time.fixedDeltaTime, Time.frameCount, Time.timeScale);
}
}
}