Add prototype gameplay loop with character/battlefield assets and server game APIs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
udx
2026-10-20 18:50:00 +08:00
co-authored by Cursor
parent 79369e4473
commit 6c64210331
833 changed files with 998079 additions and 1042 deletions
@@ -24,11 +24,22 @@ namespace HotUpdate.Net
public event Action<string> OnWsDisconnected;
public event Action<int> OnReconnecting;
public event Action<string> OnMaintenance;
public event Action<string> OnLoginFailed;
BootContext _boot;
bool _started;
bool _maintenance;
bool _everConnected;
bool _authenticating;
/// <summary>Renew the same guest identity after an authenticated game API returns 401.</summary>
public void RenewSession()
{
if (_maintenance || _authenticating) return;
Socket?.Dispose(); Socket = null; Session = null;
_started = false;
StartGuestSession();
}
public void Bind(BootContext boot)
{
@@ -61,7 +72,8 @@ namespace HotUpdate.Net
/// <summary>UI「立即重连」:重置退避并马上再连。</summary>
public void RequestReconnect()
{
if (_maintenance || Session == null || !Session.IsValid) return;
if (_maintenance) return;
if (Session == null || !Session.IsValid) { StartGuestSession(); return; }
SetStatus("手动重连…");
if (Socket != null)
{
@@ -87,6 +99,7 @@ namespace HotUpdate.Net
IEnumerator RunGuestFlow()
{
_authenticating = true;
SetStatus("auth…");
var deviceId = DeviceId.GetOrCreate();
var username = $"guest_{deviceId}";
@@ -95,11 +108,14 @@ namespace HotUpdate.Net
AuthResponse auth = null;
string err = null;
yield return AuthApi.EnsureAccount(HttpBase, username, password, (r, e) => { auth = r; err = e; });
_authenticating = false;
if (auth == null || string.IsNullOrEmpty(auth.token))
{
SetStatus($"auth fail: {err}");
_started = false;
SetStatus("登录服务连接失败,请重试");
Debug.LogError($"[GameNet] auth failed: {err}");
OnLoginFailed?.Invoke(err);
yield break;
}