78 lines
2.1 KiB
C#
78 lines
2.1 KiB
C#
using Spine.Unity;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 翅膀预制体上的初始化脚本。
|
|
/// 负责管理翅膀的 UI 图标和 Spine 动画播放逻辑:
|
|
/// 出现动画(appear)播放一次后自动切换到待机动画(idle)循环播放。
|
|
/// </summary>
|
|
public class WingItemInit : MonoBehaviour
|
|
{
|
|
[Header("UI 图标")]
|
|
[Tooltip("翅膀在列表/详情中显示的缩略图")]
|
|
public Sprite iconWing;
|
|
|
|
[Header("Spine 动画")]
|
|
[Tooltip("Spine 动画组件,留空则自动获取")]
|
|
public SkeletonAnimation skeletonAnimation;
|
|
|
|
[Tooltip("出现动画名称(播放一次)")]
|
|
public string appear="cx2";
|
|
|
|
[Tooltip("待机动画名称(循环播放)")]
|
|
public string idle="idle";
|
|
|
|
private void Awake()
|
|
{
|
|
if (skeletonAnimation == null)
|
|
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
PlayAppearThenIdle();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放出现动画,播完后自动切换到待机循环。
|
|
/// 切换翅膀时也会调用此方法重新播放出现动画。
|
|
/// </summary>
|
|
public void PlayAppearThenIdle()
|
|
{
|
|
if (skeletonAnimation == null)
|
|
{
|
|
skeletonAnimation = GetComponent<SkeletonAnimation>();
|
|
if (skeletonAnimation == null) return;
|
|
}
|
|
|
|
var state = skeletonAnimation.AnimationState;
|
|
if (state == null) return;
|
|
|
|
// 清空当前轨道
|
|
state.ClearTrack(0);
|
|
|
|
if (!string.IsNullOrEmpty(appear))
|
|
{
|
|
// 播放出现动画(不循环)
|
|
state.SetAnimation(0, appear, false);
|
|
|
|
// 出现动画播完后自动切换到待机(循环)
|
|
if (!string.IsNullOrEmpty(idle))
|
|
state.AddAnimation(0, idle, true, 0f);
|
|
}
|
|
else if (!string.IsNullOrEmpty(idle))
|
|
{
|
|
// 没有出现动画,直接播待机
|
|
state.SetAnimation(0, idle, true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重新播放出现动画(切换翅膀时调用)。
|
|
/// </summary>
|
|
public void ReplayAppear()
|
|
{
|
|
PlayAppearThenIdle();
|
|
}
|
|
}
|