Files
SahikandClaude Opus 5.5 ddd5fdc28b Rebuild the game as a single code-driven scene with a package-folder pack source
- One empty scene; App builds the canvas, safe-area layout and a shared 5x6
  Grid in code. Pages (Intro, Main, Choose, Play, Account, Settings) replace
  5 scenes, 5 prefabs and the per-cell spawner/display components.
- Packs: the game reads Rhyculator/package/ (with All files access) or the
  app folder, like a plugged-in USB stick. Zips stay where they are and are
  extracted to a cache keyed by name/size/mtime; folders are read directly.
  Scans run every second on a background thread. Old songs/ imports and inbox
  zips are migrated automatically.
- Download packs by 8-char code from the new pack website, or via
  rhyculator://pack/<code> links; opened/shared zips go into the package folder.
- Play: pause/resume/retry, auto-pause on background, combo and progress bar;
  judging and scoring unchanged. Choose page fits 9:16 screens; empty state,
  pack delete. Android back key handled everywhere.
- Slimming: removed TextMesh Pro, unused 2D/Timeline/VisualScripting/etc.
  packages and modules, scene template, unused sprites; menu theme wav (20MB)
  -> ogg (2.3MB). Build profile replaced by explicit settings in BuildAndroid.
- Tests: PackLibrary/PackReader/migration/serializer tests (39 passing).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 14:18:54 +08:00

85 lines
2.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// 畫面下方的短訊息(跨場景保留),例如「已匯入曲包」
public class Toast : MonoBehaviour
{
private static Toast instance;
private readonly Queue<string> queue = new Queue<string>();
private Text text;
private CanvasGroup group;
private Coroutine running;
public static void Show(string message)
{
Debug.Log("[Toast] " + message);
if (instance == null) instance = Create();
instance.queue.Enqueue(message);
if (instance.running == null) instance.running = instance.StartCoroutine(instance.Run());
}
private static Toast Create()
{
var root = new GameObject("Toast", typeof(Canvas), typeof(CanvasScaler), typeof(CanvasGroup));
DontDestroyOnLoad(root);
var canvas = root.GetComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.sortingOrder = 500;
var scaler = root.GetComponent<CanvasScaler>();
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
scaler.referenceResolution = new Vector2(1080, 2400);
scaler.matchWidthOrHeight = 0f;
var bg = new GameObject("Background", typeof(RectTransform)).AddComponent<Image>();
bg.transform.SetParent(root.transform, false);
bg.color = new Color(0f, 0f, 0f, 0.82f);
bg.raycastTarget = false;
var rt = bg.rectTransform;
rt.anchorMin = rt.anchorMax = new Vector2(0.5f, 0f);
rt.pivot = new Vector2(0.5f, 0f);
rt.anchoredPosition = new Vector2(0, 260);
rt.sizeDelta = new Vector2(960, 150);
var t = new GameObject("Text", typeof(RectTransform)).AddComponent<Text>();
t.transform.SetParent(bg.transform, false);
t.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
t.fontSize = 38;
t.color = Color.white;
t.alignment = TextAnchor.MiddleCenter;
t.horizontalOverflow = HorizontalWrapMode.Wrap;
t.verticalOverflow = VerticalWrapMode.Overflow;
t.raycastTarget = false;
var trt = t.rectTransform;
trt.anchorMin = Vector2.zero;
trt.anchorMax = Vector2.one;
trt.offsetMin = new Vector2(24, 8);
trt.offsetMax = new Vector2(-24, -8);
var toast = root.AddComponent<Toast>();
toast.text = t;
toast.group = root.GetComponent<CanvasGroup>();
toast.group.alpha = 0f;
return toast;
}
private IEnumerator Run()
{
while (queue.Count > 0)
{
text.text = queue.Dequeue();
group.alpha = 1f;
yield return new WaitForSecondsRealtime(3f);
for (float a = 1f; a > 0f; a -= Time.unscaledDeltaTime * 2f)
{
group.alpha = a;
yield return null;
}
group.alpha = 0f;
}
running = null;
}
}