【问题标题】:Unity add children to blendtreeUnity 将子节点添加到 blendtree
【发布时间】:2020-09-02 10:03:58
【问题描述】:

我正在尝试制作一个脚本,该脚本将接收动画列表并自动将它们添加到混合树中。我查看了混合树 API 并想出了这个:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;

public class AnimationSwitcher : MonoBehaviour
{
    public List<Motion> animations;
    public Animator animator;




    public BlendTree blendTree;

    public void addMotions()
    {
        for (int i = 0; i < animations.Count; i++)
        {
            blendTree.AddChild(animations[i]);
        }
    }
    
}

我知道我必须使用 animator 组件,但是对于如何使用它来添加 blendtree 子组件,我无法获得易于阅读的答案。我试过在编辑器中分配混合树,但也没有用

【问题讨论】:

    标签: c# visual-studio unity3d animation


    【解决方案1】:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;
    using UnityEditor.Animations;
    
    public class AnimationSwitcher : MonoBehaviour
    {
        public List<Motion> animations;
        public AnimatorController animator;
        private BlendTree blendTree;
    
        void Start()
        {
            animator.CreateBlendTreeInController("Active", out blendTree);
            blendTree.AddChild(animations[0]);
        }
    
    
        public void addMotions()
        {
            for (int i = 0; i < animations.Count; i++)
            {
                blendTree.AddChild(animations[i]);
            }
        }
       
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      相关资源
      最近更新 更多