55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System.Collections;
|
||
using Spine.Unity;
|
||
using UnityEngine;
|
||
|
||
/// <summary>
|
||
/// Spine SkeletonGraphic 版 NPC,动画名在 Inspector 配置。
|
||
/// </summary>
|
||
public class EventMatchNpcSpinePresenter : EventMatchNpcPresenter
|
||
{
|
||
[SerializeField] SkeletonGraphic skeletonGraphic;
|
||
[SerializeField] string idleAnimation = "match_easter_npc_idle";
|
||
[SerializeField] string successAnimation = "match_easter_npc_success";
|
||
[SerializeField] string successMoreAnimation = "match_easter_npc_success_more";
|
||
|
||
void Awake()
|
||
{
|
||
if (skeletonGraphic == null)
|
||
skeletonGraphic = GetComponent<SkeletonGraphic>();
|
||
}
|
||
|
||
void Start()
|
||
{
|
||
if (skeletonGraphic != null && !string.IsNullOrEmpty(idleAnimation))
|
||
skeletonGraphic.AnimationState.SetAnimation(0, idleAnimation, true);
|
||
}
|
||
|
||
Coroutine _playReactionCo;
|
||
|
||
void OnDestroy()
|
||
{
|
||
if (_playReactionCo != null)
|
||
StopCoroutine(_playReactionCo);
|
||
}
|
||
|
||
public override void PlayMatchReaction(bool isSuccessMore)
|
||
{
|
||
if (skeletonGraphic == null)
|
||
return;
|
||
if (_playReactionCo != null)
|
||
StopCoroutine(_playReactionCo);
|
||
_playReactionCo = StartCoroutine(PlayMatchReactionRoutine(isSuccessMore));
|
||
}
|
||
|
||
IEnumerator PlayMatchReactionRoutine(bool isSuccessMore)
|
||
{
|
||
string clip = isSuccessMore ? successMoreAnimation : successAnimation;
|
||
skeletonGraphic.AnimationState.SetAnimation(0, clip, false);
|
||
float duration = skeletonGraphic.AnimationState.GetCurrent(0).Animation.Duration;
|
||
yield return Awaiters.Seconds(duration);
|
||
_playReactionCo = null;
|
||
if (skeletonGraphic != null && !string.IsNullOrEmpty(idleAnimation))
|
||
skeletonGraphic.AnimationState.SetAnimation(0, idleAnimation, true);
|
||
}
|
||
}
|