//父级脚本,挂在animator上
using UnityEngine;
using System.Collections;public class UIAnimatorParent : MonoBehaviour
{
//父级脚本
//控制动画时长
float animTime = 0.1f;
//停止时间
float stopTime = 0f;
//是否开始播放动画
bool isStart = false;
public bool isBacking = false;
Animator animator;
string nextAnim;
public string playName = "";
private UIAnimator[] allUIA;
void Awake()
{
animator = this.transform.GetComponent<Animator>();
allUIA = transform.GetComponentsInChildren<UIAnimator>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Z))
{
PlayAnimation(playName, 1);
}
if (isBacking)
{
stopTime -= Time.deltaTime;
//Debug.Log(animator.playbackTime);
if (stopTime <= 0f)
{
isBacking = false;
animator.StopPlayback();
isStart = false;
if (string.IsNullOrEmpty(nextAnim))
{
}
else
{
PlayAnimation(nextAnim, 1);
nextAnim = null;
}
}
return;
}
//判断播放时长是否大于最大动画时长
if (isStart)
{
if (stopTime > animTime)
{
AllStoped();
}
else
{
stopTime += Time.deltaTime;
}
}
}
//全部结束
public void AllStoped()
{
isStart = false;
stopTime = 0;
animTime = 0.1f;
//animator.CrossFade("default", 0);
animator.StopPlayback();
animator.StopRecording();
animator.Stop();
animator.enabled = false;
for (int i = 0; i < allUIA.Length; i++)
{
allUIA[i].StopAnimation();
}
if (stopDelegate != null)
{
if (callDelegateName == playName)
{
stopDelegate();
ClearDelegate();
}
}
//所有动画播放完毕回调,动画播放完毕后开始正式执行逻辑
}
int lastPlayType = 1;
public delegate void animStoped();
animStoped stopDelegate;
string callDelegateName;
//清除结束回调
public void ClearDelegate()
{
stopDelegate = null;
callDelegateName = null;
}
//播放动画
public void PlayAnimation(string _playName, int type = 1,animStoped delega = null)
{
playName = _playName;
if (lastPlayType == 2)
{