aha
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace StinkySteak.SimulationTimer
|
||||
{
|
||||
public struct PauseableSimulationTimer
|
||||
{
|
||||
public static PauseableSimulationTimer None => default;
|
||||
|
||||
private float _targetTime;
|
||||
private bool _isPaused;
|
||||
|
||||
private float _pauseAtTime;
|
||||
|
||||
public float TargetTime => GetTargetTime();
|
||||
public bool IsPaused => _isPaused;
|
||||
|
||||
private float GetTargetTime()
|
||||
{
|
||||
if (!_isPaused)
|
||||
{
|
||||
return _targetTime;
|
||||
}
|
||||
|
||||
return _targetTime + Time.time - _pauseAtTime;
|
||||
}
|
||||
|
||||
public static PauseableSimulationTimer CreateFromSeconds(float duration)
|
||||
{
|
||||
return new PauseableSimulationTimer()
|
||||
{
|
||||
_targetTime = duration + Time.time
|
||||
};
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (_isPaused) return;
|
||||
|
||||
_isPaused = true;
|
||||
_pauseAtTime = Time.time;
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
if (!_isPaused) return;
|
||||
|
||||
_targetTime = GetTargetTime();
|
||||
_isPaused = false;
|
||||
_pauseAtTime = 0;
|
||||
}
|
||||
|
||||
public bool IsRunning => _targetTime > 0;
|
||||
|
||||
public bool IsExpired()
|
||||
=> Time.time >= TargetTime && IsRunning;
|
||||
|
||||
public bool IsExpiredOrNotRunning()
|
||||
=> Time.time >= TargetTime;
|
||||
|
||||
public float RemainingSeconds
|
||||
=> Mathf.Max(TargetTime - Time.time, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1ad3772cd6fb4848a960ac3a397aaa0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 129321
|
||||
packageName: Mirror
|
||||
packageVersion: 96.0.1
|
||||
assetPath: Assets/Mirror/Examples/BenchmarkStinkySteak/Dependencies/Unity-Simulation-Timer/Runtime/PauseableSimulationTimer.cs
|
||||
uploadId: 736421
|
@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace StinkySteak.SimulationTimer
|
||||
{
|
||||
public struct SimulationTimer
|
||||
{
|
||||
public static SimulationTimer None => default;
|
||||
|
||||
private float _targetTime;
|
||||
|
||||
public float TargetTime => _targetTime;
|
||||
|
||||
public static SimulationTimer CreateFromSeconds(float duration)
|
||||
{
|
||||
return new SimulationTimer()
|
||||
{
|
||||
_targetTime = duration + Time.time
|
||||
};
|
||||
}
|
||||
|
||||
public bool IsRunning => _targetTime > 0;
|
||||
|
||||
public bool IsExpired()
|
||||
=> Time.time >= _targetTime && IsRunning;
|
||||
|
||||
public bool IsExpiredOrNotRunning()
|
||||
=> Time.time >= _targetTime;
|
||||
|
||||
public float RemainingSeconds
|
||||
=> Mathf.Max(_targetTime - Time.time, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3dc5b6ba56d2c94b8078dc70de8d5c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 129321
|
||||
packageName: Mirror
|
||||
packageVersion: 96.0.1
|
||||
assetPath: Assets/Mirror/Examples/BenchmarkStinkySteak/Dependencies/Unity-Simulation-Timer/Runtime/SimulationTimer.cs
|
||||
uploadId: 736421
|
Reference in New Issue
Block a user