aha
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 StinkySteak
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0c6073310113462d96a86bea89ec4ea
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 129321
|
||||
packageName: Mirror
|
||||
packageVersion: 96.0.1
|
||||
assetPath: Assets/Mirror/Examples/BenchmarkStinkySteak/Dependencies/Unity-Simulation-Timer/LICENSE.md
|
||||
uploadId: 736421
|
@ -0,0 +1,63 @@
|
||||
# Simulation Timer
|
||||
An Lightweight Efficient Timer for Unity. Inspired by Photon Fusion TickTimer
|
||||
## Usage/Examples
|
||||
|
||||
#### Simulation Timer
|
||||
|
||||

|
||||
|
||||
```csharp
|
||||
private SimulationTimer _disableTimer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_disableTimer = SimulationTimer.CreateFromSeconds(_delay);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(_disableTimer.IsExpired())
|
||||
{
|
||||
_gameObject.SetActive(false);
|
||||
_disableTimer = SimulationTimer.None;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Pauseable Simulation Timer
|
||||
|
||||

|
||||
|
||||
```csharp
|
||||
private PauseableSimulationTimer _timer;
|
||||
|
||||
public PauseableSimulationTimer Timer => _timer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_timer = PauseableSimulationTimer.CreateFromSeconds(_delay);
|
||||
}
|
||||
|
||||
public void TogglePause()
|
||||
{
|
||||
if(!_timer.IsPaused)
|
||||
{
|
||||
_timer.Pause();
|
||||
return;
|
||||
}
|
||||
|
||||
_timer.Resume();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(_timer.IsExpired())
|
||||
{
|
||||
_gameObject.SetActive(false);
|
||||
_timer = PauseableSimulationTimer.None;
|
||||
}
|
||||
}
|
||||
```
|
||||
## Class Reference
|
||||
`SimulationTimer`: Default Timer
|
||||
`PauseableTimer`: Pauseable Timer
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee0478529536d0c4982dac64c0021021
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 129321
|
||||
packageName: Mirror
|
||||
packageVersion: 96.0.1
|
||||
assetPath: Assets/Mirror/Examples/BenchmarkStinkySteak/Dependencies/Unity-Simulation-Timer/README.md
|
||||
uploadId: 736421
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97dc55e998bbf3443b386473b013a62c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -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
|
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "com.stinkysteak.simulationtimer",
|
||||
"version": "0.1.0",
|
||||
"displayName": "Simulation Timer",
|
||||
"description": "Efficient and Scalable Frame Timer",
|
||||
"unity": "2021.3",
|
||||
"documentationUrl": "https://github.com/StinkySteak/com.stinkysteak.simulationtimer",
|
||||
"changelogUrl": "https://github.com/StinkySteak/com.stinkysteak.simulationtimer/blob/main/CHANGELOG.md",
|
||||
"licensesUrl": "https://github.com/StinkySteak/com.stinkysteak.simulationtimer/blob/main/LICENSE.md",
|
||||
"author": {
|
||||
"name": "Stinkysteak",
|
||||
"email": "stinkysteak@steaksoft.com",
|
||||
"url": "https://steaksoft.net"
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb3de65e983cc7f4caaed498f0a300ff
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 129321
|
||||
packageName: Mirror
|
||||
packageVersion: 96.0.1
|
||||
assetPath: Assets/Mirror/Examples/BenchmarkStinkySteak/Dependencies/Unity-Simulation-Timer/package.json
|
||||
uploadId: 736421
|
Reference in New Issue
Block a user