| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- namespace DevilLink2.UI
- {
- // Illustrated scene layers. Only local art moves; the rim/title/progress and Button stay fixed.
- public sealed class LobbyModeMagic : MonoBehaviour
- {
- private LobbyScreen lobby;
- private int mode;
- private float clock;
- private Image subject, aura, footGlow, upperSand, lowerSand, veilLeft, veilRight;
- private Image backRing, floorRing, waterRing;
- private readonly Image[] sparks = new Image[6];
- private Sprite[] lotusFrames;
- private int lotusFrame = -1;
- private static readonly Color Gold = new Color(1f, .78f, .40f);
- private static readonly Color Rose = new Color(.95f, .30f, .72f);
- private static readonly Color Blue = new Color(.46f, .62f, 1f);
- private const string Folder = "LobbyModeAnimation/";
- private const string Scene = Folder + "SceneR1/";
- public static void Install(LobbyScreen owner, Image artwork, int index)
- {
- if (!artwork || artwork.transform.Find("ModeAnimation")) return;
- string key = index == 0 ? "Classic" : index == 1 ? "TimeAttack" : "Zen";
- Sprite scene = Load(Scene + key + "_Scene"), halo = Load(Folder + "SoftGlow"), star = Load(Folder + "Star");
- Sprite main = Load(index == 0 ? Folder + "Crown" : index == 1 ? Folder + "Hourglass" : Scene + "Lotus_Whole");
- Sprite veil = Load(Scene + "EnergyVeil"), rune = Load(Scene + "RuneRing"), water = Load(Scene + "WaterRipple");
- Sprite sandTop = index == 1 ? Load(Folder + "Sand_Upper") : null;
- Sprite sandBottom = index == 1 ? Load(Folder + "Sand_Lower") : null;
- if (!scene || !halo || !star || !main || !veil || !rune || !water ||
- (index == 1 && (!sandTop || !sandBottom))) {
- Debug.LogWarning("Lobby scene sprites are not imported; keeping original card: " + key, artwork);
- return;
- }
- artwork.sprite = scene;
- var root = UIBuilder.Rect("ModeAnimation", artwork.transform, 0, 0, 130, 238);
- // Invisible clipping bounds, not a visible frame. Excludes jewels, baked titles and progress.
- root.gameObject.AddComponent<RectMask2D>().padding = new Vector4(10, 94, 10, 32);
- var view = root.gameObject.AddComponent<LobbyModeMagic>();
- view.lobby = owner; view.mode = index;
- view.veilLeft = view.Picture("DriftingBackdropLeft", veil, 32, 83, 30, 96);
- view.veilRight = view.Picture("DriftingBackdropRight", veil, 98, 82, 29, 94);
- view.aura = view.Picture("Atmosphere", halo, 65, 88, 100, 94);
- if (index == 1) view.backRing = view.Ring("TemporalOrbit", rune, 65, 81, 91, .55f);
- view.footGlow = view.Picture("BaseEnergy", halo, 65, index == 0 ? 124 : 130, 86, 20);
- view.floorRing = view.Ring("BaseRing", index == 2 ? water : rune, 65, index == 0 ? 124 : 129, 87, .25f);
- if (index == 0) {
- view.subject = view.Picture("FloatingCrown", main, 65, 84, 88, 59.6f);
- for (int i = 0; i < 3; i++)
- view.sparks[i] = view.Picture("CrownJewel" + i, star, 24 + i * 20, 42, 6, 6, view.subject.transform);
- } else if (index == 1) {
- view.subject = view.Picture("WorkingHourglass", main, 65, 81, 62, 91);
- view.upperSand = view.Picture("UpperMagicSand", sandTop, 65, 79.2f, 22.8f, 24.6f);
- view.lowerSand = view.Picture("LowerMagicSand", sandBottom, 65, 112.9f, 24.6f, 24.6f);
- BottomPivot(view.upperSand, 65, 79.2f); BottomPivot(view.lowerSand, 65, 112.9f);
- for (int i = 0; i < 2; i++)
- view.sparks[i] = view.Picture("NeckStream" + i, halo, 65, 81, 2.2f, 3.6f);
- } else {
- // Every frame contains a whole bloom. No cut petals, independent rotations or gaps.
- view.lotusFrames = Resources.LoadAll<Sprite>(Scene + "Lotus_Breath");
- Array.Sort(view.lotusFrames, (a, b) => string.CompareOrdinal(a.name, b.name));
- if (view.lotusFrames.Length == 32) main = view.lotusFrames[0];
- else {
- view.lotusFrames = null;
- Debug.LogWarning("Lotus atlas must contain 32 frames; using intact whole-flower fallback.", artwork);
- }
- view.subject = view.Picture("WholeBreathingLotus", main, 65, 95, 104, 78);
- view.waterRing = view.Ring("OuterWaterRipple", water, 65, 129, 87, .25f);
- }
- // Two foreground motes per mode, pooled once and faded at the wrap point.
- for (int i = 4; i < 6; i++) view.sparks[i] = view.Picture("ForegroundMote" + i, index == 2 ? halo : star, 38 + (i - 4) * 51, 120, 4, 4);
- view.ApplyPose();
- }
- private static Sprite Load(string path) => Resources.Load<Sprite>(path);
- private Image Picture(string name, Sprite sprite, float cx, float cy, float w, float h, Transform parent = null)
- {
- var image = LobbyArtView.Picture(name, parent ? parent : transform, sprite, 0, 0, w, h);
- var r = image.rectTransform; r.anchorMin = r.anchorMax = new Vector2(0, 1); r.pivot = new Vector2(.5f, .5f);
- r.anchoredPosition = new Vector2(cx, -cy);
- image.color = Color.white; image.material = null; image.raycastTarget = false;
- return image;
- }
- private Image Ring(string name, Sprite sprite, float x, float y, float size, float flatten)
- {
- var plane = UIBuilder.Rect(name + "Plane", transform, x, y, 0, 0);
- plane.localScale = new Vector3(1, flatten, 1);
- return Picture(name, sprite, 0, 0, size, size, plane);
- }
- private static void BottomPivot(Image image, float x, float y)
- { image.rectTransform.pivot = new Vector2(.5f, 0); image.rectTransform.anchoredPosition = new Vector2(x, -y); }
- private static void Tint(Image image, Color tint, float alpha)
- { tint.a = Mathf.Clamp01(alpha); image.color = tint; }
- private static void Position(Image image, float x, float y)
- { image.rectTransform.anchoredPosition = new Vector2(x, -y); }
- private static void Turn(Image image, float angle)
- { image.rectTransform.localRotation = Quaternion.Euler(0, 0, angle); }
- private void Update()
- {
- if (!lobby || !lobby.IsVisible) return;
- clock += Time.unscaledDeltaTime;
- ApplyPose();
- }
- private void ApplyPose()
- {
- if (!aura) return;
- float period = mode == 0 ? 3.8f : mode == 1 ? 2.8f : 4.8f;
- float phase = clock * Mathf.PI * 2 / period;
- float breath = .5f - .5f * Mathf.Cos(phase);
- Color tint = mode == 0 ? Gold : mode == 1 ? Rose : Blue;
- // Independent atmospheric layers drift through the painted setting, not the UI layout.
- Position(veilLeft, 32 + 2 * Mathf.Sin(phase * .5f), 83 + 3 * Mathf.Cos(phase * .5f));
- Position(veilRight, 98 - 2 * Mathf.Sin(phase * .5f), 82 - 3 * Mathf.Cos(phase * .5f));
- Turn(veilLeft, 4 * Mathf.Sin(phase * .5f)); Turn(veilRight, -5 * Mathf.Cos(phase * .5f));
- Tint(veilLeft, tint, .21f + .07f * breath); Tint(veilRight, tint, .17f + .06f * (1 - breath));
- Tint(aura, tint, .08f + .045f * breath);
- Tint(footGlow, tint, .16f + .12f * breath);
- if (mode == 0) {
- Position(subject, 65, 84 - 2.8f * Mathf.Sin(phase));
- Turn(floorRing, clock * 9); Tint(floorRing, Gold, .20f + .12f * breath);
- floorRing.rectTransform.localScale = Vector3.one * (1 + .035f * Mathf.Sin(phase));
- for (int i = 0; i < 3; i++) {
- float shimmer = Mathf.Pow(.5f + .5f * Mathf.Sin(phase + i * 1.7f), 4);
- Tint(sparks[i], Gold, .04f + .55f * shimmer);
- }
- } else if (mode == 1) {
- upperSand.rectTransform.localScale = new Vector3(1, .68f + .22f * Mathf.Cos(phase), 1);
- lowerSand.rectTransform.localScale = new Vector3(1, .68f - .22f * Mathf.Cos(phase), 1);
- Tint(upperSand, Color.white, .72f); Tint(lowerSand, Color.white, .72f);
- Turn(backRing, clock * 18); Tint(backRing, Rose, .43f);
- Turn(floorRing, -clock * 12); Tint(floorRing, Rose, .36f + .08f * breath);
- for (int i = 0; i < 2; i++) {
- float t = Mathf.Repeat(clock / .82f + i * .5f, 1);
- Position(sparks[i], 65 + .5f * Mathf.Sin(t * Mathf.PI * 2), 74.6f + t * 27.3f);
- Tint(sparks[i], new Color(1, .87f, .96f), Mathf.Sin(t * Mathf.PI) * .9f);
- }
- } else {
- Position(subject, 65, 95 - 1.1f * Mathf.Sin(phase));
- if (lotusFrames != null) {
- int frame = Mathf.FloorToInt(Mathf.Repeat(clock / 4.8f, 1) * lotusFrames.Length);
- if (frame != lotusFrame) { lotusFrame = frame; subject.sprite = lotusFrames[frame]; }
- }
- Ripple(floorRing, Mathf.Repeat(clock / 3.2f, 1));
- Ripple(waterRing, Mathf.Repeat(clock / 3.2f + .5f, 1));
- }
- for (int i = 4; i < 6; i++) {
- float t = Mathf.Repeat(clock / (period + .8f) + (i - 4) * .5f, 1);
- Position(sparks[i], 38 + (i - 4) * 51 + 3 * Mathf.Sin(t * Mathf.PI * 2), 131 - t * 61);
- Tint(sparks[i], tint, Mathf.Sin(t * Mathf.PI) * (mode == 2 ? .45f : .55f));
- }
- }
- private static void Ripple(Image image, float t)
- {
- image.rectTransform.localScale = Vector3.one * (.45f + .76f * t);
- Tint(image, Blue, Mathf.Sin(t * Mathf.PI) * .38f);
- }
- private void OnEnable() { clock = 0; lotusFrame = -1; ApplyPose(); }
- private void OnDisable()
- {
- clock = 0; lotusFrame = -1;
- ApplyPose(); // Restore all local baselines; no pending coroutines, tweens or animation callbacks.
- }
- }
- }
|