前言
动画控制分为Animator和Animation,本文有简单的Animation控制功能
代码模块
本文可以执行播放动画和动画结束判定功能。
using System.Collections;
using System.Collections.Generic;
using OLife.Tournament;
using UnityEngine;
using UnityMVVM.Util;
public class AnimationPlayer : Singleton<AnimationPlayer>
{
private Animation animationComponent; // Animation 组件
public bool isPlaying = false; // 是否正在播放动画
private string Aniname;
void Update()
{
if (animationComponent != null)
{
if (isPlaying && !animationComponent.isPlaying)
{
// 动画播放完成
OnAnimationComplete(Aniname);
}
}
}
public void PlayAnimation(Animation animationComponent, string name)
{
Aniname = name;
this.animationComponent = animationComponent;
isPlaying = true;
animationComponent.Play(name);
}
public void PlayAnimation(Animation animationComponent)
{
animationComponent.Play(name);
}
void OnAnimationComplete(string Aniname)
{
isPlaying = false;
animationComponent = null;
//EventManager.TriggerEvent(Aniname, null);
Debug.Log("Animation completed.");
// 在这里执行播放完成后的逻辑
}
}