This commit is contained in:
CortexCore
2023-10-06 23:43:19 +08:00
parent ebf9c1f526
commit 2c4710bc5d
186 changed files with 111802 additions and 764 deletions

View File

@@ -17,9 +17,11 @@ namespace BITKit.Http
[Header(Constant.Header.Settings)]
[SerializeReference,SubclassSelector] private IReference url;
[SerializeField] private double interval;
[SerializeField] private CollisionDetectionMode detectionMode;
[Header(Constant.Header.Output)]
[SerializeField] private UnityEvent<string> output;
[SerializeField] private UnityEvent<string> onException;
[Header(Constant.Header.Debug)]
[SerializeField, ReadOnly] private double time;
@@ -39,6 +41,14 @@ AutoReset = true
{
timer.Interval = interval*1000;
timer.Elapsed += (x, y) => OnUpdate();
timer.AutoReset = detectionMode switch
{
CollisionDetectionMode.ContinuousDynamic => true,
CollisionDetectionMode.ContinuousSpeculative => true,
CollisionDetectionMode.Continuous => true,
CollisionDetectionMode.Discrete => false,
_ => throw new ArgumentOutOfRangeException()
};
timer.Start();
}
private void OnDestroy()
@@ -50,14 +60,24 @@ AutoReset = true
{
Stopwatch stopwatch = new();
stopwatch.Start();
await _httpClient.GetStringAsync(url.Value);
//var result = await _httpClient.GetStringAsync(url.Value);
var response = await _httpClient.GetAsync(url.Value, _cancellationToken);
var result =await response.Content.ReadAsStringAsync();
_cancellationToken.ThrowIfCancellationRequested();
#if UNITY_EDITOR
if (UnityEditor.EditorApplication.isPlaying is false) return;
#endif
stopwatch.Stop();
time =System.TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalSeconds;
output.Invoke(url.Value);
await UniTask.SwitchToMainThread(_cancellationToken);
if (response.StatusCode is not System.Net.HttpStatusCode.OK)
{
onException.Invoke(result);
}
else
{
output.Invoke(result);
}
if(timer.AutoReset==false)
timer.Start();
}
}
}