45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TKS.OutGame
|
|
{
|
|
/// <summary>
|
|
/// UI 이미지 프레임 재생(로비 영웅 대기 · PD 2026-11-11) — 프레임·순서·유지 초·깜빡임 = 유닛 meta 클립(UnitArtData · 전투 FrameAnimator 와 같은 규칙).
|
|
/// 매 프레임 바뀔 수 있으므로 Frame 캔버스 안에서만(UiLayer.Isolate · 이미 Frame 층 안이면 그 층을 씀).
|
|
/// </summary>
|
|
public class UiFrameAnim : MonoBehaviour
|
|
{
|
|
Image img;
|
|
UnitArtData data;
|
|
string clip;
|
|
Sprite[] frames;
|
|
float t0;
|
|
float nextBlink;
|
|
float blinkEnd = -1f;
|
|
|
|
public static UiFrameAnim Attach(Image img, UnitArtData data, string clip)
|
|
{
|
|
Sprite[] fr;
|
|
if (img == null || data == null || !data.Clips.TryGetValue(clip, out fr) || fr.Length < 2) return null;
|
|
var a = img.gameObject.AddComponent<UiFrameAnim>();
|
|
a.img = img;
|
|
a.data = data;
|
|
a.clip = clip;
|
|
a.frames = fr;
|
|
// 영웅마다 시작 시점을 달리(모두 같이 움직이면 어색)
|
|
a.t0 = Time.unscaledTime - Random.value * data.CycleSeconds(clip, fr.Length);
|
|
UiLayer.Isolate(img.gameObject);
|
|
return a;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (img == null || frames == null) return;
|
|
float now = Time.unscaledTime - t0;
|
|
int k = data.ApplyBlink(clip, frames.Length, data.FrameAt(clip, frames.Length, now), now, ref nextBlink, ref blinkEnd);
|
|
var sp = frames[k];
|
|
if (img.sprite != sp) img.sprite = sp;
|
|
}
|
|
}
|
|
}
|