/*--------------------------------------------------------------------
- Author Name: DXL
- Creation Time: 6/27/2019 11:53:28 AM
- File Describe: 修改Spine的速度,仅限于Animator
- ------------------------------------------------------------------*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SetSpineSpeed : MonoBehaviour
{
public string stateName; //要修改的状态速度
public float speed = 2f; //要修改的动作倍数
public AnimationClip[] clips; //显示当前spine的animator有几种状态,用于参考
Animator atr;
string lastAniStr; //记录上次的状态名字
void Start()
{
atr = transform.GetComponent<Animator>();
}
void Update()
{
if (atr != null)
{
string aniStr = atr.GetCurrentAnimatorClipInfo(0)[0].clip.name;
if (aniStr == lastAniStr)
{
return;
}
lastAniStr = aniStr;
if (aniStr == stateName)
{
atr.speed = speed;
Debug.Log("spine " + aniStr + " speed changed: " + speed);
}
else
{
atr.speed = 1;
}
}
}
void Reset()
{
clips = transform.GetComponent<Animator>().runtimeAnimatorController.animationClips;
}
}