Land Explorer in HomeCamp with boot loading, journal UI, and CDN publish tooling.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
udx
2026-11-04 16:18:01 +08:00
co-authored by Cursor
parent 9eec364f30
commit 80678ec499
405 changed files with 48053 additions and 420302 deletions
+52 -106
View File
@@ -1,132 +1,78 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AOT.UI
{
/// <summary>
/// 启动更新条(运行时生成,竖屏安全区友好)。
/// </summary>
/// <summary>Local JSON-authored loading screen, available before CDN initialization.</summary>
public sealed class BootPatchView : MonoBehaviour
{
Text _status;
Image _fill;
TMP_Text _status, _percentage;
RectTransform _fill;
CanvasGroup _group;
float _target, _shown;
public static BootPatchView Create()
public static BootPatchView Create(BootPatchView prefab)
{
var root = new GameObject("BootPatchUI");
DontDestroyOnLoad(root);
var canvasGo = new GameObject("Canvas");
canvasGo.transform.SetParent(root.transform, false);
var canvas = canvasGo.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.sortingOrder = 1000;
canvasGo.AddComponent<CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
var scaler = canvasGo.GetComponent<CanvasScaler>();
scaler.referenceResolution = new Vector2(1080, 1920);
scaler.matchWidthOrHeight = 0.5f;
canvasGo.AddComponent<GraphicRaycaster>();
var bg = CreateUiObject("Background", canvasGo.transform);
var bgImage = bg.AddComponent<Image>();
bgImage.color = new Color(0.08f, 0.09f, 0.12f, 1f);
StretchFull(bg.GetComponent<RectTransform>());
var title = CreateUiObject("Title", canvasGo.transform);
var titleText = title.AddComponent<Text>();
titleText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
titleText.text = "AIGame";
titleText.alignment = TextAnchor.MiddleCenter;
titleText.fontSize = 64;
titleText.color = Color.white;
var titleRt = title.GetComponent<RectTransform>();
titleRt.anchorMin = new Vector2(0.1f, 0.62f);
titleRt.anchorMax = new Vector2(0.9f, 0.72f);
titleRt.offsetMin = Vector2.zero;
titleRt.offsetMax = Vector2.zero;
var statusGo = CreateUiObject("Status", canvasGo.transform);
var status = statusGo.AddComponent<Text>();
status.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
status.text = "启动中…";
status.alignment = TextAnchor.MiddleCenter;
status.fontSize = 28;
status.color = new Color(0.85f, 0.88f, 0.92f, 1f);
var statusRt = statusGo.GetComponent<RectTransform>();
statusRt.anchorMin = new Vector2(0.1f, 0.42f);
statusRt.anchorMax = new Vector2(0.9f, 0.5f);
statusRt.offsetMin = Vector2.zero;
statusRt.offsetMax = Vector2.zero;
var barBg = CreateUiObject("ProgressBg", canvasGo.transform);
var barBgImage = barBg.AddComponent<Image>();
barBgImage.color = new Color(1f, 1f, 1f, 0.12f);
var barBgRt = barBg.GetComponent<RectTransform>();
barBgRt.anchorMin = new Vector2(0.15f, 0.36f);
barBgRt.anchorMax = new Vector2(0.85f, 0.39f);
barBgRt.offsetMin = Vector2.zero;
barBgRt.offsetMax = Vector2.zero;
var barFill = CreateUiObject("ProgressFill", barBg.transform);
var fill = barFill.AddComponent<Image>();
fill.color = new Color(0.35f, 0.75f, 0.55f, 1f);
var fillRt = barFill.GetComponent<RectTransform>();
fillRt.anchorMin = Vector2.zero;
fillRt.anchorMax = new Vector2(0f, 1f);
fillRt.offsetMin = Vector2.zero;
fillRt.offsetMax = Vector2.zero;
fillRt.pivot = new Vector2(0f, 0.5f);
var view = root.AddComponent<BootPatchView>();
view._status = status;
view._fill = fill;
if (prefab == null)
{
Debug.LogError("[Boot] Loading prefab missing; run BuildBootLoading.Build before exporting.");
return null;
}
var view = Instantiate(prefab);
DontDestroyOnLoad(view.gameObject);
return view;
}
void Awake()
{
_status = transform.Find("LoadingCard/Txt_Status").GetComponent<TMP_Text>();
_percentage = transform.Find("LoadingCard/Txt_Percentage").GetComponent<TMP_Text>();
_fill = transform.Find("LoadingCard/ProgressTrack/FillClip").GetComponent<RectTransform>();
_group = GetComponent<CanvasGroup>();
SetStatus("正在准备冒险…");
DrawProgress();
}
void Update()
{
_shown = Mathf.MoveTowards(_shown, _target, Time.unscaledDeltaTime * .65f);
DrawProgress();
}
void DrawProgress()
{
if (_fill != null) _fill.anchorMax = new Vector2(_shown, 1f);
if (_percentage != null) _percentage.text = Mathf.FloorToInt(_shown * 100f) + "%";
}
public void SetStatus(string text)
{
if (_status != null)
_status.text = text ?? string.Empty;
if (_status != null) _status.text = text ?? string.Empty;
}
public void SetProgress(float normalized01)
{
if (_fill == null) return;
float v = Mathf.Clamp01(normalized01);
var rt = _fill.rectTransform;
rt.anchorMax = new Vector2(v, 1f);
}
public void SetProgress(float normalized01) => _target = Mathf.Max(_target, Mathf.Clamp01(normalized01));
public void SetError(string message)
{
SetStatus(message);
if (_fill != null)
_fill.color = new Color(0.85f, 0.3f, 0.3f, 1f);
Debug.LogError("[Boot] " + message);
SetStatus("加载失败,请重新进入游戏");
if (_status != null) _status.color = new Color(.72f, .22f, .18f);
}
public void Hide()
public void Hide() => StartCoroutine(FadeOut());
System.Collections.IEnumerator FadeOut()
{
_shown = _target = 1f; DrawProgress();
yield return new WaitForSecondsRealtime(.12f);
for (float time = 0; time < .25f; time += Time.unscaledDeltaTime)
{
if (_group != null) _group.alpha = 1f - time / .25f;
yield return null;
}
gameObject.SetActive(false);
}
public void DestroyUi()
{
Destroy(gameObject);
}
static GameObject CreateUiObject(string name, Transform parent)
{
var go = new GameObject(name, typeof(RectTransform));
go.transform.SetParent(parent, false);
return go;
}
static void StretchFull(RectTransform rt)
{
rt.anchorMin = Vector2.zero;
rt.anchorMax = Vector2.one;
rt.offsetMin = Vector2.zero;
rt.offsetMax = Vector2.zero;
}
public void DestroyUi() => Destroy(gameObject);
}
}