using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public static class IListExtensions
{
/// <summary>
/// Shuffles the element order of the specified list.
/// </summary>
public static void Shuffle<T>(this IList<T> ts)
{
var count = ts.Count;
var last = count - 1;
for (var i = 0; i < last; ++i)
{
var r = UnityEngine.Random.Range(i, count);
var tmp = ts[i];
ts[i] = ts[r];
ts[r] = tmp;
}
}
}
public class PlayAnimations : MonoBehaviour
{
private AnimationClip[] clips;
private Animator animator;
private void Awake()
{
// Get the animator component
animator = GetComponent<Animator>();
// Get all available clips
clips = animator.runtimeAnimatorController.animationClips;
}
private void Start()
{
StartCoroutine(PlayRandomly());
}
private IEnumerator PlayRandomly()
{
var clipList = clips.ToList();
while (true)
{
clipList.Shuffle();
foreach (var randClip in clipList)
{
animator.Play(randClip.name);
yield return new WaitForSeconds(randClip.length);
}
}
}
}
Это позволит получить все анимации из состояний обычного автомата верхнего контроллера. Но я создал вспомогательный конечный автомат с именем Magic StateMachine.
И я хочу получить все анимационные клипы из состояний только внутри Magic StateMachine.
Снимок экрана контроллера аниматора:

И скриншот вспомогательного автомата и состояний, из которых я хочу получить анимационные клипы и воспроизводить их случайным образом:
