1
This commit is contained in:
@@ -8,6 +8,7 @@ using Cysharp.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.LowLevel;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
@@ -58,15 +59,18 @@ namespace BITKit
|
||||
}
|
||||
|
||||
[SerializeField] private int tickRate = 32;
|
||||
[SerializeField] private bool isMainThread;
|
||||
[SerializeField] private bool isConcurrent;
|
||||
[SerializeField] private string lastTickTime="0";
|
||||
private readonly Timer _timer = new();
|
||||
private float _deltaTime;
|
||||
private double _lastTime;
|
||||
|
||||
private PlayerLoopSystem _playerLoop;
|
||||
|
||||
private int _update;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_playerLoop = PlayerLoop.GetCurrentPlayerLoop();
|
||||
tickRate = Mathf.Clamp(tickRate, 1, 128);
|
||||
|
||||
_deltaTime = 1f / tickRate;
|
||||
@@ -81,32 +85,34 @@ namespace BITKit
|
||||
_timer.Dispose();
|
||||
});
|
||||
}
|
||||
private async void Tick(object sender, ElapsedEventArgs e)
|
||||
|
||||
private void Update()
|
||||
{
|
||||
TickCount++;
|
||||
try
|
||||
{
|
||||
|
||||
var delta = (float)(BITApp.Time.TimeAsDouble - _lastTime);
|
||||
_lastTime = BITApp.Time.TimeAsDouble;
|
||||
if (isMainThread) await UniTask.SwitchToMainThread(destroyCancellationToken);
|
||||
#if UNITY_EDITOR
|
||||
if (EditorApplication.isPlaying is false)
|
||||
{
|
||||
Restart();
|
||||
}
|
||||
if (EditorApplication.isPlaying is false)
|
||||
{
|
||||
_update = 0;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
for (var i = 0; i < _update; i++)
|
||||
{
|
||||
var delta = Time.deltaTime;
|
||||
while (_ActionQueue.TryDequeue(out var action))
|
||||
{
|
||||
action?.Invoke();
|
||||
}
|
||||
_TickEvents?.Invoke(delta);
|
||||
// using var xEnumerator = _TickActions.GetEnumerator();
|
||||
// while (xEnumerator.MoveNext())
|
||||
// {
|
||||
// xEnumerator.Current!.Invoke(delta);
|
||||
// }
|
||||
//_TickEvents?.Invoke((float)delta);
|
||||
_TickEvents?.Invoke(delta);
|
||||
}
|
||||
_update = 0;
|
||||
}
|
||||
|
||||
private void Tick(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
TickCount++;
|
||||
try
|
||||
{
|
||||
_update++;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -126,7 +132,6 @@ _TickEvents?.Invoke(delta);
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user