This commit is contained in:
CortexCore
2024-04-22 03:48:37 +08:00
parent 0362b2c606
commit c1f51826b3
35 changed files with 556 additions and 270 deletions

View File

@@ -16,8 +16,6 @@ namespace BITKit.Sensors
[SerializeField,ReadOnly] private int _position;
private static int[] _keys;
public static void Register(int id,ISensor sensor)
{
Sensors.Add(id,sensor);
@@ -33,7 +31,6 @@ namespace BITKit.Sensors
IsDirty = true;
}
[SerializeField] private MonoBehaviour[] sensors;
[SerializeReference,SubclassSelector] private ITicker ticker;
private bool _isBusy;
@@ -56,9 +53,7 @@ namespace BITKit.Sensors
if(IsDirty)
{
_position = 0;
_keys = Sensors.Where(IsEnabled).Select(x=>x.Key).ToArray();
IsDirty = false;
sensors = Sensors.Values.Where(IsEnabled).OfType<MonoBehaviour>().ToArray();
}
if (Sensors.Count is 0)
@@ -68,26 +63,22 @@ namespace BITKit.Sensors
}
var current = Sensors.ElementAt(_position++).Value;
var currentUpdateTime = LastDetectedTime.GetOrAdd(current.Id,Time.time);
if (current.AutoUpdate)
{
var currentUpdateTime = LastDetectedTime.GetOrAdd(current.Id,Time.time);
await current.Execute(Time.time-currentUpdateTime);
float UpdateValueFactory(int key, float old) => Time.time;
LastDetectedTime.AddOrUpdate(current.Id,Time.time,UpdateValueFactory);
if (destroyCancellationToken.IsCancellationRequested) {
_isBusy = false;
return;
if (destroyCancellationToken.IsCancellationRequested) {
_isBusy = false;
return;
}
}
_position %= Sensors.Count;
_isBusy = false;
}
private bool IsEnabled(ISensor sensor)
{
return sensor.AutoUpdate;
}
private bool IsEnabled(KeyValuePair<int,ISensor> pair)
{
return pair.Value.AutoUpdate;
return;
float UpdateValueFactory(int key, float old) => Time.time;
}
}