add kcp
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user