Add hot-update boot pipeline, UI bundles/atlas assets, and design docs.
Ignore AIClient/Library and AIClient/HybridCLRData permanently; include HybridCLR/YooAsset project setup and UI tooling. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AOT.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 启动更新条(运行时生成,竖屏安全区友好)。
|
||||
/// </summary>
|
||||
public sealed class BootPatchView : MonoBehaviour
|
||||
{
|
||||
Text _status;
|
||||
Image _fill;
|
||||
|
||||
public static BootPatchView Create()
|
||||
{
|
||||
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;
|
||||
return view;
|
||||
}
|
||||
|
||||
public void SetStatus(string text)
|
||||
{
|
||||
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 SetError(string message)
|
||||
{
|
||||
SetStatus(message);
|
||||
if (_fill != null)
|
||||
_fill.color = new Color(0.85f, 0.3f, 0.3f, 1f);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user