c# - 如何从子状态机获取动画?
问题描述
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 中从状态中获取所有动画剪辑。
动画控制器的屏幕截图:
以及子状态机的屏幕截图以及我想要从中获取动画片段并随机播放的状态:
解决方案
推荐阅读
- camunda - Camunda“接收任务”打开“异步之后”会导致“无法关联消息”错误
- django - django ModelAdmin autocomplete_fields 中的 ID 保存在哪里?
- git - 如何恢复从一个分支合并的所有提交
- python - Python中的更多阈值算法?
- c# - 在 ItemsSourceUpdated 之后关注 DataGridRow
- java - 如何理解“应用程序的状态应存储在文件中”?
- firebase - Firebase 实时数据库 - 如何使用 REST API 管理数据库规则
- r - R中混合数据的DBSCAN
- javascript - 如何从子组件调用 React Hook 以刷新结果
- asp.net-core - 为多租户运行多个数据库的 ABP IO 代码示例