mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 06:25:42 +00:00
Remove BetterBehavior and GameTime types
This commit is contained in:
parent
6e4a9882e9
commit
8059b067c9
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user