/// <summary>
        /// 把 BlendTree 转换为 AssetBlendTree
        /// </summary>
        /// <param name="originBlendTree"></param>
        /// <param name="assetBlendTree"></param>
        private void TransBlendTree(BlendTree originBlendTree, AssetBlendTree assetBlendTree, string blendTreeName)
        {
            assetBlendTree.stateName = blendTreeName;
            assetBlendTree.parameter = originBlendTree.blendParameter;
            if (originBlendTree.blendType == BlendTreeType.Simple1D)
            {
                assetBlendTree.blendTreeType = AssetBlendTree.BlendTreeType._1D;    // 目前只支持1D混合树
            }
            else
            {
                Debug.LogError("not support blendTree type except Simple1D");
                return;
            }

            ChildMotion[] originChilds = originBlendTree.children;
            assetBlendTree.motions = new AssetStateController.Motion[originChilds.Length];
            for (int i = 0; i < originChilds.Length; i++)
            {
                AssetStateController.Motion newMotion = new AssetStateController.Motion();
                AnimationClip clip = (originChilds[i].motion as AnimationClip);     // 混合树子节点 转换为clip类型
                newMotion.blendTreeType = assetBlendTree.blendTreeType;
                newMotion.clip          = clip;
                newMotion.threshold     = originChilds[i].threshold;
                newMotion.speed         = originChilds[i].timeScale;

                assetBlendTree.motions[i] = newMotion;
            }
            assetBlendTree.Sort();  // 按照threshold排序
        }
        public AssetBlendTree CreateBlendTreeAsset(string name)
        {
            AssetBlendTree asset = ScriptableObject.CreateInstance <AssetBlendTree>();

            asset.name = name;
            AssetDatabase.CreateAsset(asset, GetNewAssetPath(name));
            AssetDatabase.Refresh();
            return(asset);
        }
        private void OnEnable()
        {
            m_Target  = target as AssetBlendTree;
            m_Motions = serializedObject.FindProperty("motions");
            m_Param   = serializedObject.FindProperty("parameter");
            m_Type    = serializedObject.FindProperty("blendTreeType");
            m_Name    = serializedObject.FindProperty("stateName");

            m_Target.Sort();
            m_Target.SetBlendTreeType();
        }
        /// <summary>
        /// 把 AnimatorStateMachine 转换为 AssetStateGroup
        /// </summary>
        /// <param name="originStateMachine"></param>
        /// <param name="assetStateGroup"></param>
        /// <param name="isSync"></param>
        /// <param name="groupName"></param>
        private void TransStateGroup(AnimatorStateMachine originStateMachine, AssetStateGroup assetStateGroup,
                                     bool isSync, AnimatorControllerLayer overrideLayer, string groupName = null)
        {
            ChildAnimatorState[] animCtrlStates             = originStateMachine.states;
            List <AssetStateController.Motion> assetMotions = new List <AssetStateController.Motion>();
            List <AssetBlendTree> assetBlendTrees           = new List <AssetBlendTree>();

            for (int j = 0; j < animCtrlStates.Length; j++)
            {
                EditorUtility.DisplayProgressBar("Transform State Group...", string.Format("duel with the {0} state...", j), j / (float)animCtrlStates.Length);

                AnimatorState state       = animCtrlStates[j].state;
                Motion        motion      = isSync ? overrideLayer.GetOverrideMotion(state) : state.motion; // 如果是同步层,取OverrideMotion
                bool          isBlendTree = motion is BlendTree;
                if (isBlendTree)
                {
                    BlendTree      originBlendTree = motion as BlendTree;
                    string         blendTreeName   = string.Format("{0}_blendTree_{1}", assetStateGroup.name, state.name);
                    AssetBlendTree assetBlendTree  = CreateBlendTreeAsset(blendTreeName);
                    TransBlendTree(originBlendTree, assetBlendTree, state.name);
                    assetBlendTrees.Add(assetBlendTree);
                }
                else
                {
                    AnimationClip originClip = motion as AnimationClip;
                    AssetStateController.Motion newMotion = new AssetStateController.Motion();

                    newMotion.clip      = originClip;
                    newMotion.speed     = state.speed;
                    newMotion.stateName = state.name;
                    assetMotions.Add(newMotion);
                }
            }

            assetStateGroup.groupName  = groupName;
            assetStateGroup.motions    = assetMotions.ToArray();
            assetStateGroup.blendTrees = assetBlendTrees.ToArray();
        }