public static void OverrideBlendTree(BlendTree value, int childIndex, Motion newMotion)
        {
            List <ChildMotion> cloneMotions = new List <ChildMotion>();

            value.children.ToList().ForEach(i => cloneMotions.Add(i));

            for (int i = value.children.Length - 1; i >= 0; i--)
            {
                value.RemoveChild(i);
            }

            for (int i = 0; i < cloneMotions.Count; i++)
            {
                if (i == childIndex)
                {
                    value.AddChild(newMotion);
                }
                else
                {
                    value.AddChild(cloneMotions[i].motion);
                }
            }

            for (int i = 0; i < value.children.Length; i++)
            {
                value.children[i] = cloneMotions[i];
            }
        }
예제 #2
0
        /// <summary>
        /// 更新blendTree motion
        /// </summary>
        /// <param name="_value"></param>
        /// <param name="_childIndex"></param>
        /// <param name="_motion"></param>
        public static void OverrideBlendTree(BlendTree _value, int _childIndex, Motion _motion)
        {
            List <ChildMotion> childMotions = new List <ChildMotion>();

            _value.children.ToList().ForEach(child => childMotions.Add(child));

            for (int i = _value.children.Length - 1; i >= 0; i--)
            {
                _value.RemoveChild(i);
            }

            for (int i = 0; i < childMotions.Count; i++)
            {
                if (i == _childIndex)
                {
                    _value.AddChild(_motion);
                }
                else
                {
                    _value.AddChild(childMotions[i].motion);
                }
            }

            for (int i = 0; i < _value.children.Length; i++)
            {
                _value.children[i] = childMotions[i];
            }
        }
예제 #3
0
        private BlendTree CopyTreeIdentically(BlendTree originalTree, Side side)
        {
            var newTree = new BlendTree();

            // Object.Instantiate(...) is triggering some weird issues about assertions failures.
            // Copy the blend tree manually
            newTree.name           = "zAutogeneratedPup_" + originalTree.name + "_DO_NOT_EDIT";
            newTree.blendType      = originalTree.blendType;
            newTree.blendParameter = HandleWeightCorrection(
                RemapAutoWeightOrElse(side, originalTree.blendParameter)
                );
            newTree.blendParameterY = HandleWeightCorrection(
                RemapAutoWeightOrElse(side, originalTree.blendParameterY)
                );
            newTree.minThreshold           = originalTree.minThreshold;
            newTree.maxThreshold           = originalTree.maxThreshold;
            newTree.useAutomaticThresholds = originalTree.useAutomaticThresholds;

            var copyOfChildren = originalTree.children;

            while (newTree.children.Length > 0)
            {
                newTree.RemoveChild(0);
            }

            newTree.children = copyOfChildren
                               .Select(childMotion => new ChildMotion
            {
                motion               = childMotion.motion,
                threshold            = childMotion.threshold,
                position             = childMotion.position,
                timeScale            = childMotion.timeScale,
                cycleOffset          = childMotion.cycleOffset,
                directBlendParameter = HandleWeightCorrection(RemapAutoWeightOrElse(side, childMotion.directBlendParameter)),
                mirror               = childMotion.mirror
            })
                               .ToArray();

            return(newTree);
        }
예제 #4
0
        private BlendTree CopyTreeIdentically(BlendTree originalTree)
        {
            var newTree = new BlendTree();

            // Object.Instantiate(...) is triggering some weird issues about assertions failures.
            // Copy the blend tree manually
            newTree.name                   = "autoBT_" + originalTree.name;
            newTree.blendType              = originalTree.blendType;
            newTree.blendParameter         = originalTree.blendParameter;
            newTree.blendParameterY        = originalTree.blendParameterY;
            newTree.minThreshold           = originalTree.minThreshold;
            newTree.maxThreshold           = originalTree.maxThreshold;
            newTree.useAutomaticThresholds = originalTree.useAutomaticThresholds;

            var copyOfChildren = originalTree.children;

            while (newTree.children.Length > 0)
            {
                newTree.RemoveChild(0);
            }

            newTree.children = copyOfChildren
                               .Select(childMotion => new ChildMotion
            {
                motion               = childMotion.motion,
                threshold            = childMotion.threshold,
                position             = childMotion.position,
                timeScale            = childMotion.timeScale,
                cycleOffset          = childMotion.cycleOffset,
                directBlendParameter = childMotion.directBlendParameter,
                mirror               = childMotion.mirror
            })
                               .ToArray();

            return(newTree);
        }
예제 #5
0
 public void RemoveNodeMotions(IEnumerable <UnityEditor.Graphs.Node> nodes)
 {
     foreach (UnityEditor.Graphs.Node current in nodes)
     {
         Node node = current as Node;
         if (!(this.m_RootBlendTree == node.motion))
         {
             if (!(node.motion == null))
             {
                 if (node.parent)
                 {
                     BlendTree blendTree = node.parent.motion as BlendTree;
                     int       index     = Graph.FindMotionIndexOnBlendTree(blendTree, node.motion);
                     blendTree.RemoveChild(index);
                 }
                 BlendTree blendTree2 = node.motion as BlendTree;
                 if (blendTree2 && MecanimUtilities.AreSameAsset(this.m_RootBlendTree, blendTree2))
                 {
                     MecanimUtilities.DestroyBlendTreeRecursive(blendTree2);
                 }
             }
         }
     }
 }
예제 #6
0
    static void CheckAndRefreshAnimatorController(string animatorControllerPath, AnimationClip[] newClips, AnimatorStateMachine stateMachine, AnimatorController animatorController)
    {
        for (int i = 0; i < stateMachine.states.Length; i++)
        {
            ChildAnimatorState childState = stateMachine.states[i];

            string motionName = GetMotionName(animatorControllerPath, childState.state.name);
            if (!string.IsNullOrEmpty(motionName))
            {
                for (int j = 0; j < newClips.Length; j++)
                {
                    if (newClips[j].name.CompareTo(motionName) == 0)
                    {
                        childState.state.motion = (Motion)newClips[j];
                        Debug.Log("替换成功 animatorController:" + animatorController.name + " motionName:" + motionName);
                        s_countChange++;
                        break;
                    }
                }
            }
            else
            {
                if (childState.state.motion == null)
                {
                    if (childState.state.name.CompareTo("New State") == 0)
                    {
                        continue;
                    }

                    Debug.LogError("替换失败 animatorController:" + animatorController.name + " Null : " + childState.state.name);
                    continue;
                }
                if (childState.state.motion.GetType() == typeof(AnimationClip))
                {
                    for (int j = 0; j < newClips.Length; j++)
                    {
                        if (newClips[j].name.CompareTo(childState.state.motion.name) == 0)
                        {
                            childState.state.motion = (Motion)newClips[j];
                            Debug.Log("替换成功 animatorController:" + animatorController.name + "childState.state.name:" + childState.state.name);
                            s_countChange++;
                            break;
                        }
                    }
                }
#if BlendTree
                else if (childState.state.motion.GetType() == typeof(BlendTree))
                {
                    //BlendTree这个类有BUG,不能直接修改Motion, 要先记录原本的信息,再全部删除原本的,再修改,再加上去.

                    List <Motion> allMotion    = new List <Motion>();
                    List <float>  allThreshold = new List <float>();
                    BlendTree     tree         = (BlendTree)childState.state.motion;

                    for (int k = 0; k < tree.children.Length; k++)
                    {
                        allMotion.Add(tree.children[k].motion);
                        allThreshold.Add(tree.children[k].threshold);
                    }

                    for (int k = 0; k < allMotion.Count; k++)
                    {
                        if (allMotion[k].GetType() == typeof(AnimationClip))
                        {
                            for (int j = 0; j < newClips.Length; j++)
                            {
                                if (newClips[j].name.CompareTo(allMotion[k].name) == 0)
                                {
                                    allMotion[k] = (Motion)newClips[j];
                                    s_countChange++;
                                    break;
                                }
                            }
                        }
                        else if (allMotion[k].GetType() == typeof(BlendTree))
                        {
                            Debug.LogError("You need to change it!");
                        }
                    }

                    for (int k = tree.children.Length - 1; k >= 0; k--)
                    {
                        tree.RemoveChild(k);
                    }

                    for (int k = 0; k < allMotion.Count; k++)
                    {
                        tree.AddChild(allMotion[k], allThreshold[k]);
                    }
                }
#endif
            }
        }



        for (int i = 0; i < stateMachine.stateMachines.Length; i++)
        {
            CheckAndRefreshAnimatorController(animatorControllerPath, newClips, stateMachine.stateMachines[i].stateMachine, animatorController);
        }
    }
예제 #7
0
    static void SaveAnimatorControllerMotion(string animatorControllerPath, AnimatorStateMachine stateMachine, AnimatorController animatorController)
    {
        for (int i = 0; i < stateMachine.states.Length; i++)
        {
            ChildAnimatorState childState = stateMachine.states[i];
            if (childState.state.motion == null)
            {
                if (childState.state.name.CompareTo("New State") == 0)
                {
                    continue;
                }

                continue;
            }
            if (childState.state.motion.GetType() == typeof(AnimationClip))
            {
                var    motionNameDict = s_animatorControllerMotionDict[animatorControllerPath];
                string stateName      = childState.state.name;
                string motionName     = childState.state.motion.name;
                if (motionNameDict.ContainsKey(stateName))
                {
                    motionNameDict[stateName] = motionName;
                }
                else
                {
                    motionNameDict.Add(stateName, motionName);
                }
            }

#if BlendTree
            else if (childState.state.motion.GetType() == typeof(BlendTree))
            {
                //BlendTree这个类有BUG,不能直接修改Motion, 要先记录原本的信息,再全部删除原本的,再修改,再加上去.

                List <Motion> allMotion    = new List <Motion>();
                List <float>  allThreshold = new List <float>();
                BlendTree     tree         = (BlendTree)childState.state.motion;

                for (int k = 0; k < tree.children.Length; k++)
                {
                    allMotion.Add(tree.children[k].motion);
                    allThreshold.Add(tree.children[k].threshold);
                }

                for (int k = 0; k < allMotion.Count; k++)
                {
                    if (allMotion[k].GetType() == typeof(AnimationClip))
                    {
                        for (int j = 0; j < newClips.Length; j++)
                        {
                            if (newClips[j].name.CompareTo(allMotion[k].name) == 0)
                            {
                                allMotion[k] = (Motion)newClips[j];
                                s_countChange++;
                                break;
                            }
                        }
                    }
                    else if (allMotion[k].GetType() == typeof(BlendTree))
                    {
                        Debug.LogError("You need to change it!");
                    }
                }

                for (int k = tree.children.Length - 1; k >= 0; k--)
                {
                    tree.RemoveChild(k);
                }

                for (int k = 0; k < allMotion.Count; k++)
                {
                    tree.AddChild(allMotion[k], allThreshold[k]);
                }
            }
#endif
        }

        for (int i = 0; i < stateMachine.stateMachines.Length; i++)
        {
            SaveAnimatorControllerMotion(animatorControllerPath, stateMachine.stateMachines[i].stateMachine, animatorController);
        }
    }
예제 #8
0
    static void CheckAndRefreshAnimatorController(List <AnimationClip> clips, AnimatorStateMachine stateMachine)
    {
        for (int i = 0; i < stateMachine.states.Length; i++)
        {
            ChildAnimatorState childState = stateMachine.states[i];
            if (childState.state.motion == null)
            {
                Debug.LogError("Null motion : " + childState.state.name);
                continue;
            }

            if (childState.state.motion.GetType() == typeof(AnimationClip))
            {
                for (int j = 0; j < clips.Count; j++)
                {
                    if (clips[j].name.CompareTo(childState.state.motion.name) == 0)
                    {
                        childState.state.motion = (Motion)clips[j];
                        break;
                    }
                }
            }
            else if (childState.state.motion.GetType() == typeof(BlendTree))
            {
                //BlendTree这个类有BUG,不能直接修改Motion, 要先记录原本的信息,再全部删除原本的,再修改,再加上去.
                List <Motion> allMotion    = new List <Motion>();
                List <float>  allThreshold = new List <float>();
                BlendTree     tree         = (BlendTree)childState.state.motion;

                for (int k = 0; k < tree.children.Length; k++)
                {
                    allMotion.Add(tree.children[k].motion);
                    allThreshold.Add(tree.children[k].threshold);
                }

                for (int k = 0; k < allMotion.Count; k++)
                {
                    if (allMotion[k].GetType() == typeof(AnimationClip))
                    {
                        for (int j = 0; j < clips.Count; j++)
                        {
                            if (clips[j].name.CompareTo(allMotion[k].name) == 0)
                            {
                                allMotion[k] = (Motion)clips[j];
                                break;
                            }
                        }
                    }
                    else if (allMotion[k].GetType() == typeof(BlendTree))
                    {
                        Debug.LogError("不能多层BlendTree!");
                    }
                }

                for (int k = tree.children.Length - 1; k >= 0; k--)
                {
                    tree.RemoveChild(k);
                }

                for (int k = 0; k < allMotion.Count; k++)
                {
                    tree.AddChild(allMotion[k], allThreshold[k]);
                }
            }
        }

        for (int i = 0; i < stateMachine.stateMachines.Length; i++)
        {
            CheckAndRefreshAnimatorController(clips, stateMachine.stateMachines[i].stateMachine);
        }
    }