作者: Onepengr 时间: 2022-10-14 14:04
using System.Collections;
using UnityEngine;
using Spine.Unity;
namespace Game
{
//[ExecuteInEditMode]
public class SpineForAnimator : MonoBehaviour
{
private void Update()
{
if (_playingIdx == index)
{
return;
}
if (_ui != null)
{
PlayUISpine();
}else if (_scene != null)
{
PlaySceneSpine();
}
}
private void PlayUISpine()
{
var animations = _ui.Skeleton.Data.Animations;
Debug.Assert(index < animations.Count, "property index can not more than animation count!");
var state = _ui.AnimationState;
var willName = animations.Items[index].Name;
//播放Spine动画
state.ClearTrack(0);
_ui.Skeleton.SetToSetupPose();
state.SetAnimation(0, willName, loop);
_playingIdx = index;
}
private void PlaySceneSpine()
{
var animations = _scene.skeleton.Data.Animations;
Debug.Assert(index < animations.Count, "property index can not more than animation count!");
var state = _scene.AnimationState;
var willName = animations.Items[index].Name;
//播放Spine动画
state.ClearTrack(0);
_scene.Skeleton.SetToSetupPose();
state.SetAnimation(0, willName, loop);
_playingIdx = index;
}
}
}