56 lines
1.3 KiB
C#
56 lines
1.3 KiB
C#
|
using System;
|
|||
|
using Cysharp.Threading.Tasks;
|
|||
|
using Spine;
|
|||
|
using Spine.Unity;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Game.Spine;
|
|||
|
|
|||
|
public interface ISpineAnimator
|
|||
|
{
|
|||
|
SkeletonAnimation skeletonAnimation { get; }
|
|||
|
|
|||
|
void PlayAni(string animaName, bool isLoop);
|
|||
|
UniTask<bool> PlayAniAsync(string animaName, bool isLoop = false);
|
|||
|
void StopAni();
|
|||
|
}
|
|||
|
|
|||
|
public class SpineAnimator : MonoBehaviour, ISpineAnimator
|
|||
|
{
|
|||
|
[SerializeField] private SkeletonAnimation _skeletonAnimation;
|
|||
|
|
|||
|
public SkeletonAnimation skeletonAnimation => this._skeletonAnimation;
|
|||
|
|
|||
|
private UniTask _task;
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
if (this._skeletonAnimation == null)
|
|||
|
throw new NullReferenceException();
|
|||
|
|
|||
|
// this._skeletonAnimation.skeletonDataAsset.defaultMix;
|
|||
|
// this._skeletonAnimation.state.Complete += Finish;
|
|||
|
this.StopAni();
|
|||
|
}
|
|||
|
|
|||
|
private void Finish(TrackEntry trackentry)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public virtual void PlayAni(string animaName, bool isLoop = false)
|
|||
|
{
|
|||
|
_skeletonAnimation.AnimationName = animaName;
|
|||
|
this._skeletonAnimation.loop = isLoop;
|
|||
|
}
|
|||
|
|
|||
|
public async UniTask<bool> PlayAniAsync(string animaName, bool isLoop)
|
|||
|
{
|
|||
|
await UniTask.Yield();
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public void StopAni()
|
|||
|
{
|
|||
|
_skeletonAnimation.AnimationName = default;
|
|||
|
}
|
|||
|
}
|