Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按4个游戏对象的顺序播放-队列中的动画师(不是具有多个状态的单个动画师)_C#_Unity3d_Animation - Fatal编程技术网

C# 按4个游戏对象的顺序播放-队列中的动画师(不是具有多个状态的单个动画师)

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()是正确的调用位置。 到目

我不熟悉团结。我有4个游戏对象,比如红色、绿色、蓝色、黄色,索引分别映射为0、1、2和3。此外,我还将索引顺序保存在列表
列表systemTrack
中。 现在,我正在调用与list
{0,1,2,3}
相关的
animator
序列(这可以是随机的0-3)

我可以在给定的时间执行一个动画循环

 void Start() {
    animator.Play("blue_animation", 0, 0);
 } 
如何根据列表按顺序调用?也许
Update()
是正确的调用位置。

到目前为止,我发现-但它有一个动画师对象与多个状态调用顺序,这不是我的情况。
对于
动画
组件,除了
新的Animator
组件,几乎没有其他讨论可用。

在您当前的课程中,您可以使用类似的

这至少可以将您的实现开销减少到

  • 确保在最后一个状态结束时触发动画事件
  • 确保在
    AnimatorQueueController
  • 在原始脚本中,而不是
    Animator
    引用中,而是将
    AnimatorQueueController
    存储在列表中

请使用正确的标签。。。是或更好是早期Unity版本中使用的类似JavaScript风格的自定义语言,现在已经被长期弃用。。。您的代码显然是
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;
    }
}