C# 按4个游戏对象的顺序播放-队列中的动画师(不是具有多个状态的单个动画师)
我不熟悉团结。我有4个游戏对象,比如红色、绿色、蓝色、黄色,索引分别映射为0、1、2和3。此外,我还将索引顺序保存在列表C# 按4个游戏对象的顺序播放-队列中的动画师(不是具有多个状态的单个动画师),c#,unity3d,animation,C#,Unity3d,Animation,我不熟悉团结。我有4个游戏对象,比如红色、绿色、蓝色、黄色,索引分别映射为0、1、2和3。此外,我还将索引顺序保存在列表列表systemTrack中。 现在,我正在调用与list{0,1,2,3}相关的animator序列(这可以是随机的0-3) 我可以在给定的时间执行一个动画循环 void Start() { animator.Play("blue_animation", 0, 0); } 如何根据列表按顺序调用?也许Update()是正确的调用位置。 到目
列表systemTrack
中。
现在,我正在调用与list{0,1,2,3}
相关的animator
序列(这可以是随机的0-3)
我可以在给定的时间执行一个动画循环
void Start() {
animator.Play("blue_animation", 0, 0);
}
如何根据列表按顺序调用?也许Update()
是正确的调用位置。
到目前为止,我发现-但它有一个动画师对象与多个状态调用顺序,这不是我的情况。
对于
动画
组件,除了新的Animator
组件,几乎没有其他讨论可用。在您当前的课程中,您可以使用类似的
这至少可以将您的实现开销减少到
- 确保在最后一个状态结束时触发动画事件
- 确保在
AnimatorQueueController
- 在原始脚本中,而不是
引用中,而是将Animator
存储在列表中AnimatorQueueController
c#
List<AnimatorQueueController> animatorQueues;
private void Start()
{
StartCoroutine(RunAllControllersSequencial());
}
IEnumerator RunAllControllersSequencial()
{
foreach (var queue in animatorQueues)
{
// This runs the routine and waits until it finishes
yield return queue.RunAnimationQueueAndWait();
}
}
public class AnimationQueueController : MonoBehaviour
{
[SerializeField] private Animator _animator;
// Here set the first state name for each instance via the Inspector
[SerializeField] private string firstStateName = "first_state";
private void Awake ()
{
if(!_animator) _animator = GetComponent<Animator>();
}
// Simply have another routine you can yield so it is executed and at the same time waits until it is done
public IEnumerator RunAnimationQueueAndWaitUntilEnd()
{
hasReachedEnd = false;
_animator.Play(firstStateName, 0 ,0);
yield return new WaitUntil(() => hasReachedEnd);
}
// This is the method you will invoke via the Animation Event
// See https://docs.unity3d.com/Manual/script-AnimationWindowEvent.html
public void AnimationEnd()
{
hasReachedEnd = true;
}
}