This commit is contained in:
CortexCore
2024-08-06 10:27:59 +08:00
parent cc3d6f0ef1
commit d5c21759b5
6 changed files with 412 additions and 84 deletions

View File

@@ -78,6 +78,8 @@ namespace BITKit
private IReference getLatestUrl;
[SerializeField, SerializeReference, SubclassSelector]
private WebProvider webProvider;
[SerializeReference, SubclassSelector] private ITicker checkTick;
[SerializeField] private bool dontDestroyOnLoad;
event Action<string> IApplicationService.OnClientVersionCheck
@@ -114,8 +116,6 @@ namespace BITKit
private UnityWebRequest downloadRequest;
private CancellationTokenSource _cancellationTokenSource;
public async UniTask<string> DownloadLatestVersionAsync()
{
var filePath =
@@ -136,13 +136,11 @@ namespace BITKit
while (downloadRequest.downloadHandler.isDone is false)
{
OnDownloadProgress?.Invoke(downloadRequest.downloadProgress);
_cancellationTokenSource.Token.ThrowIfCancellationRequested();
destroyCancellationToken.ThrowIfCancellationRequested();
await UniTask.NextFrame();
}
await File.WriteAllBytesAsync(filePath, downloadRequest.downloadHandler.data,_cancellationTokenSource.Token);
await File.WriteAllBytesAsync(filePath, downloadRequest.downloadHandler.data,destroyCancellationToken);
OnDownloadComplete?.Invoke(filePath);
return filePath;
@@ -150,14 +148,14 @@ namespace BITKit
public string DownloadLatestUrl => getLatestUrl.Value;
public string CheckLatestVersionUrl=>getVersionUrl.Value;
private bool _isBusy;
private void Awake()
{
Singleton = this;
_cancellationTokenSource = new CancellationTokenSource();
}
private async void Start()
private void Start()
{
if (dontDestroyOnLoad)
{
@@ -165,27 +163,44 @@ namespace BITKit
}
try
{
_cancellationTokenSource.Token.ThrowIfCancellationRequested();
var latestVersion = await webProvider.GetAsync(getVersionUrl.Get(), _cancellationTokenSource.Token);
var currentVersion = Application.version;
BIT4Log.Log<ApplicationService>(latestVersion != currentVersion
? $"当前版本{currentVersion}不是最新版本{latestVersion},请及时更新"
: $"当前版本{currentVersion}是最新版本");
OnClientVersionCheck?.Invoke(currentVersion);
OnLatestVersionCheck?.Invoke(latestVersion);
OnTick(0);
}
catch(OperationCanceledException){}
catch (Exception e)
{
BIT4Log.LogException(e);
}
}
private void OnDestroy()
destroyCancellationToken.Register(Dispose);
checkTick?.Add(OnTick);
}
private async void OnTick(float deltaTime)
{
if(_isBusy)return;
try
{
var latestVersion = await webProvider.GetAsync(getVersionUrl.Get(), destroyCancellationToken);
if (destroyCancellationToken.IsCancellationRequested) return;
var currentVersion = Application.version;
OnClientVersionCheck?.Invoke(currentVersion);
OnLatestVersionCheck?.Invoke(latestVersion);
}
catch (OperationCanceledException)
{
}
catch (Exception e)
{
BIT4Log.LogException(e);
}
_isBusy = false;
}
private void Dispose()
{
checkTick?.Remove(OnTick);
downloadRequest?.Abort();
_cancellationTokenSource?.Cancel();
}
}

View File

@@ -254,6 +254,10 @@ namespace BITKit.Net.Kcp
stopWatch.Stop();
BIT4Log.Log<MonoKcpClient>($"已返回\n开始:{value.StartTime}\n结束:{value.EndTime}\n延迟:{stopWatch.ElapsedMilliseconds}ms");
SendRT(nameof(KCPNetServer.OnNetRpcTest),64,12.8f,true);
stopWatch.Reset();
stopWatch.Start();
var hello =

View File

@@ -81,6 +81,7 @@ namespace BITKit.UX
public static void UnRegister(IUXPanel panel) => UnRegistryQueue.Enqueue(panel);
public static void Entry<T>() where T : IUXPanel => EntryQueue.Push(Panels[typeof(T).Name]);
public static void EntryByName(string name)=> EntryQueue.Push(Panels[name]);
public static void Return()
{