Exemplo n.º 1
0
        /// <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 AssetState.AnimationState[originChilds.Length];
            for (int i = 0; i < originChilds.Length; i++)
            {
                AssetState.AnimationState newMotion = new AssetState.AnimationState();
                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排序
        }
Exemplo n.º 2
0
        /// <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<AssetState.AnimationState> assetMotions = new List<AssetState.AnimationState>();
            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;

                AnimatorStateTransition[] transs = state.transitions;
                List<AssetTransitions.Transtions> stateTranstions = new List<AssetTransitions.Transtions>();
                for (int i = 0; i < transs.Length; i++)
                {
                    AnimatorStateTransition transdata = transs[i];
                    AssetTransitions.Transtions ttranstion = new AssetTransitions.Transtions();
                    ttranstion.CopyData(transdata);
                    stateTranstions.Add(ttranstion);
                }


                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);
                    assetBlendTree.transtions = stateTranstions.ToArray();
                    assetBlendTrees.Add(assetBlendTree);
                }
                else
                {
                    AnimationClip originClip = motion as AnimationClip;
                    AssetState.AnimationState newMotion = new AssetState.AnimationState();
                    newMotion.clip = originClip;
                    newMotion.speed = state.speed;
                    newMotion.stateName = state.name;
                    newMotion.transtions = stateTranstions.ToArray();
                    assetMotions.Add(newMotion);
                }

                
            }

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