Пример #1
0
 private void CreateController()
 {
     if (((this.m_Controller == null) && (this.m_AvatarPreview != null)) && ((this.m_AvatarPreview.Animator != null) && (this.m_RefTransition != null)))
     {
         this.m_LayerIndex           = 0;
         this.m_Controller           = new AnimatorController();
         this.m_Controller.pushUndo  = false;
         this.m_Controller.hideFlags = HideFlags.HideAndDontSave;
         this.m_Controller.AddLayer("preview");
         bool flag = true;
         if (this.m_LayerMask != null)
         {
             int humanoidBodyPartCount = this.m_LayerMask.humanoidBodyPartCount;
             for (int i = 0; (i < humanoidBodyPartCount) && flag; i++)
             {
                 if (!this.m_LayerMask.GetHumanoidBodyPartActive(i))
                 {
                     flag = false;
                 }
             }
             if (!flag)
             {
                 this.m_Controller.AddLayer("Additionnal");
                 this.m_LayerIndex++;
                 AnimatorControllerLayer[] layers = this.m_Controller.layers;
                 layers[this.m_LayerIndex].avatarMask = this.m_LayerMask;
                 this.m_Controller.layers             = layers;
             }
         }
         this.m_StateMachine           = this.m_Controller.layers[this.m_LayerIndex].stateMachine;
         this.m_StateMachine.pushUndo  = false;
         this.m_StateMachine.hideFlags = HideFlags.HideAndDontSave;
         this.m_SrcMotion = this.m_RefSrcState.motion;
         this.m_DstMotion = this.m_RefDstState.motion;
         this.m_ParameterMinMax.Clear();
         if ((this.m_SrcMotion != null) && (this.m_SrcMotion is BlendTree))
         {
             BlendTree srcMotion = this.m_SrcMotion as BlendTree;
             for (int j = 0; j < srcMotion.recursiveBlendParameterCount; j++)
             {
                 string recursiveBlendParameter = srcMotion.GetRecursiveBlendParameter(j);
                 if (this.m_Controller.IndexOfParameter(recursiveBlendParameter) == -1)
                 {
                     this.m_Controller.AddParameter(recursiveBlendParameter, AnimatorControllerParameterType.Float);
                     this.m_ParameterMinMax.Add(new Vector2(srcMotion.GetRecursiveBlendParameterMin(j), srcMotion.GetRecursiveBlendParameterMax(j)));
                 }
             }
         }
         if ((this.m_DstMotion != null) && (this.m_DstMotion is BlendTree))
         {
             BlendTree dstMotion = this.m_DstMotion as BlendTree;
             for (int k = 0; k < dstMotion.recursiveBlendParameterCount; k++)
             {
                 string name = dstMotion.GetRecursiveBlendParameter(k);
                 int    num5 = this.m_Controller.IndexOfParameter(name);
                 if (num5 == -1)
                 {
                     this.m_Controller.AddParameter(name, AnimatorControllerParameterType.Float);
                     this.m_ParameterMinMax.Add(new Vector2(dstMotion.GetRecursiveBlendParameterMin(k), dstMotion.GetRecursiveBlendParameterMax(k)));
                 }
                 else
                 {
                     Vector2 vector  = this.m_ParameterMinMax[num5];
                     Vector2 vector2 = this.m_ParameterMinMax[num5];
                     this.m_ParameterMinMax[num5] = new Vector2(Mathf.Min(dstMotion.GetRecursiveBlendParameterMin(k), vector[0]), Mathf.Max(dstMotion.GetRecursiveBlendParameterMax(k), vector2[1]));
                 }
             }
         }
         this.m_SrcState           = this.m_StateMachine.AddState(this.m_RefSrcState.name);
         this.m_SrcState.pushUndo  = false;
         this.m_SrcState.hideFlags = HideFlags.HideAndDontSave;
         this.m_DstState           = this.m_StateMachine.AddState(this.m_RefDstState.name);
         this.m_DstState.pushUndo  = false;
         this.m_DstState.hideFlags = HideFlags.HideAndDontSave;
         this.CopyStateForPreview(this.m_RefSrcState, ref this.m_SrcState);
         this.CopyStateForPreview(this.m_RefDstState, ref this.m_DstState);
         this.m_Transition           = this.m_SrcState.AddTransition(this.m_DstState, true);
         this.m_Transition.pushUndo  = false;
         this.m_Transition.hideFlags = HideFlags.DontSave;
         this.CopyTransitionForPreview(this.m_RefTransition, ref this.m_Transition);
         this.DisableIKOnFeetIfNeeded();
         AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
         this.m_Controller.OnAnimatorControllerDirty = (System.Action)Delegate.Combine(this.m_Controller.OnAnimatorControllerDirty, new System.Action(this.ControllerDirty));
     }
 }
Пример #2
0
 private void CreateController()
 {
     if (this.m_Controller == null && this.m_AvatarPreview != null && this.m_AvatarPreview.Animator != null && this.m_RefTransition != null)
     {
         this.m_LayerIndex           = 0;
         this.m_Controller           = new AnimatorController();
         this.m_Controller.pushUndo  = false;
         this.m_Controller.hideFlags = HideFlags.HideAndDontSave;
         this.m_Controller.AddLayer("preview");
         bool flag = true;
         if (this.m_LayerMask != null)
         {
             AvatarMaskBodyPart avatarMaskBodyPart = AvatarMaskBodyPart.Root;
             while (avatarMaskBodyPart < AvatarMaskBodyPart.LastBodyPart && flag)
             {
                 if (!this.m_LayerMask.GetHumanoidBodyPartActive(avatarMaskBodyPart))
                 {
                     flag = false;
                 }
                 avatarMaskBodyPart++;
             }
             if (!flag)
             {
                 this.m_Controller.AddLayer("Additionnal");
                 this.m_LayerIndex++;
                 AnimatorControllerLayer[] layers = this.m_Controller.layers;
                 layers[this.m_LayerIndex].avatarMask = this.m_LayerMask;
                 this.m_Controller.layers             = layers;
             }
         }
         this.m_StateMachine           = this.m_Controller.layers[this.m_LayerIndex].stateMachine;
         this.m_StateMachine.pushUndo  = false;
         this.m_StateMachine.hideFlags = HideFlags.HideAndDontSave;
         this.m_SrcMotion = this.m_RefSrcState.motion;
         this.m_DstMotion = this.m_RefDstState.motion;
         this.m_ParameterMinMax.Clear();
         if (this.m_SrcMotion && this.m_SrcMotion is BlendTree)
         {
             BlendTree blendTree = this.m_SrcMotion as BlendTree;
             for (int i = 0; i < blendTree.recursiveBlendParameterCount; i++)
             {
                 string recursiveBlendParameter = blendTree.GetRecursiveBlendParameter(i);
                 if (this.m_Controller.IndexOfParameter(recursiveBlendParameter) == -1)
                 {
                     this.m_Controller.AddParameter(recursiveBlendParameter, AnimatorControllerParameterType.Float);
                     this.m_ParameterMinMax.Add(new Vector2(blendTree.GetRecursiveBlendParameterMin(i), blendTree.GetRecursiveBlendParameterMax(i)));
                 }
             }
         }
         if (this.m_DstMotion && this.m_DstMotion is BlendTree)
         {
             BlendTree blendTree2 = this.m_DstMotion as BlendTree;
             for (int j = 0; j < blendTree2.recursiveBlendParameterCount; j++)
             {
                 string recursiveBlendParameter2 = blendTree2.GetRecursiveBlendParameter(j);
                 int    num = this.m_Controller.IndexOfParameter(recursiveBlendParameter2);
                 if (num == -1)
                 {
                     this.m_Controller.AddParameter(recursiveBlendParameter2, AnimatorControllerParameterType.Float);
                     this.m_ParameterMinMax.Add(new Vector2(blendTree2.GetRecursiveBlendParameterMin(j), blendTree2.GetRecursiveBlendParameterMax(j)));
                 }
                 else
                 {
                     this.m_ParameterMinMax[num] = new Vector2(Mathf.Min(blendTree2.GetRecursiveBlendParameterMin(j), this.m_ParameterMinMax[num][0]), Mathf.Max(blendTree2.GetRecursiveBlendParameterMax(j), this.m_ParameterMinMax[num][1]));
                 }
             }
         }
         this.m_SrcState           = this.m_StateMachine.AddState(this.m_RefSrcState.name);
         this.m_SrcState.pushUndo  = false;
         this.m_SrcState.hideFlags = HideFlags.HideAndDontSave;
         this.m_DstState           = this.m_StateMachine.AddState(this.m_RefDstState.name);
         this.m_DstState.pushUndo  = false;
         this.m_DstState.hideFlags = HideFlags.HideAndDontSave;
         this.CopyStateForPreview(this.m_RefSrcState, ref this.m_SrcState);
         this.CopyStateForPreview(this.m_RefDstState, ref this.m_DstState);
         this.m_Transition           = this.m_SrcState.AddTransition(this.m_DstState, true);
         this.m_Transition.pushUndo  = false;
         this.m_Transition.hideFlags = HideFlags.DontSave;
         this.CopyTransitionForPreview(this.m_RefTransition, ref this.m_Transition);
         this.DisableIKOnFeetIfNeeded();
         AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
         AnimatorController expr_404 = this.m_Controller;
         expr_404.OnAnimatorControllerDirty = (Action)Delegate.Combine(expr_404.OnAnimatorControllerDirty, new Action(this.ControllerDirty));
     }
 }
        void CreateController()
        {
            if (m_Controller == null && m_AvatarPreview != null && m_AvatarPreview.Animator != null && m_RefTransition != null)
            {
                // controller
                m_LayerIndex           = 0;
                m_Controller           = new AnimatorController();
                m_Controller.pushUndo  = false;
                m_Controller.hideFlags = HideFlags.HideAndDontSave;
                m_Controller.AddLayer("preview");

                bool isDefaultMask = true;

                if (m_LayerMask != null)
                {
                    for (AvatarMaskBodyPart i = 0; i < AvatarMaskBodyPart.LastBodyPart && isDefaultMask; i++)
                    {
                        if (!m_LayerMask.GetHumanoidBodyPartActive(i))
                        {
                            isDefaultMask = false;
                        }
                    }

                    if (!isDefaultMask)
                    {
                        m_Controller.AddLayer("Additionnal");
                        m_LayerIndex++;
                        AnimatorControllerLayer[] layers = m_Controller.layers;
                        layers[m_LayerIndex].avatarMask = m_LayerMask;
                        m_Controller.layers             = layers;
                    }
                }
                m_StateMachine           = m_Controller.layers[m_LayerIndex].stateMachine;
                m_StateMachine.pushUndo  = false;
                m_StateMachine.hideFlags = HideFlags.HideAndDontSave;

                m_SrcMotion = m_RefSrcState.motion;
                m_DstMotion = m_RefDstState.motion;

                /// Add parameters
                m_ParameterMinMax.Clear();

                if (m_SrcMotion && m_SrcMotion is BlendTree)
                {
                    BlendTree leftBlendTree = m_SrcMotion as BlendTree;

                    for (int i = 0; i < leftBlendTree.recursiveBlendParameterCount; i++)
                    {
                        string blendValueName = leftBlendTree.GetRecursiveBlendParameter(i);
                        if (m_Controller.IndexOfParameter(blendValueName) == -1)
                        {
                            m_Controller.AddParameter(blendValueName, AnimatorControllerParameterType.Float);
                            m_ParameterMinMax.Add(new Vector2(leftBlendTree.GetRecursiveBlendParameterMin(i), leftBlendTree.GetRecursiveBlendParameterMax(i)));
                        }
                    }
                }

                if (m_DstMotion && m_DstMotion is BlendTree)
                {
                    BlendTree rightBlendTree = m_DstMotion as BlendTree;

                    for (int i = 0; i < rightBlendTree.recursiveBlendParameterCount; i++)
                    {
                        string blendValueName = rightBlendTree.GetRecursiveBlendParameter(i);
                        int    parameterIndex = m_Controller.IndexOfParameter(blendValueName);
                        if (parameterIndex == -1)
                        {
                            m_Controller.AddParameter(blendValueName, AnimatorControllerParameterType.Float);
                            m_ParameterMinMax.Add(new Vector2(rightBlendTree.GetRecursiveBlendParameterMin(i), rightBlendTree.GetRecursiveBlendParameterMax(i)));
                        }
                        else
                        {
                            m_ParameterMinMax[parameterIndex] =
                                new Vector2(Mathf.Min(rightBlendTree.GetRecursiveBlendParameterMin(i), m_ParameterMinMax[parameterIndex][0]),
                                            Mathf.Max(rightBlendTree.GetRecursiveBlendParameterMax(i), m_ParameterMinMax[parameterIndex][1]));
                        }
                    }
                }


                // states
                m_SrcState           = m_StateMachine.AddState(m_RefSrcState.name);
                m_SrcState.pushUndo  = false;
                m_SrcState.hideFlags = HideFlags.HideAndDontSave;
                m_DstState           = m_StateMachine.AddState(m_RefDstState.name);
                m_DstState.pushUndo  = false;
                m_DstState.hideFlags = HideFlags.HideAndDontSave;

                CopyStateForPreview(m_RefSrcState, ref m_SrcState);
                CopyStateForPreview(m_RefDstState, ref m_DstState);

                // transition
                m_Transition           = m_SrcState.AddTransition(m_DstState, true);
                m_Transition.pushUndo  = false;
                m_Transition.hideFlags = HideFlags.DontSave;
                CopyTransitionForPreview(m_RefTransition, ref m_Transition);

                DisableIKOnFeetIfNeeded();


                AnimatorController.SetAnimatorController(m_AvatarPreview.Animator, m_Controller);

                m_Controller.OnAnimatorControllerDirty += ControllerDirty;
            }
        }
Пример #4
0
        private void CreateController()
        {
            if (!((UnityEngine.Object) this.m_Controller == (UnityEngine.Object)null) || this.m_AvatarPreview == null || (!((UnityEngine.Object) this.m_AvatarPreview.Animator != (UnityEngine.Object)null) || !((UnityEngine.Object) this.m_RefTransition != (UnityEngine.Object)null)))
            {
                return;
            }
            this.m_LayerIndex           = 0;
            this.m_Controller           = new AnimatorController();
            this.m_Controller.pushUndo  = false;
            this.m_Controller.hideFlags = HideFlags.HideAndDontSave;
            this.m_Controller.AddLayer("preview");
            bool flag = true;

            if ((UnityEngine.Object) this.m_LayerMask != (UnityEngine.Object)null)
            {
                for (AvatarMaskBodyPart index = AvatarMaskBodyPart.Root; index < AvatarMaskBodyPart.LastBodyPart && flag; ++index)
                {
                    if (!this.m_LayerMask.GetHumanoidBodyPartActive(index))
                    {
                        flag = false;
                    }
                }
                if (!flag)
                {
                    this.m_Controller.AddLayer("Additionnal");
                    ++this.m_LayerIndex;
                    AnimatorControllerLayer[] layers = this.m_Controller.layers;
                    layers[this.m_LayerIndex].avatarMask = this.m_LayerMask;
                    this.m_Controller.layers             = layers;
                }
            }
            this.m_StateMachine           = this.m_Controller.layers[this.m_LayerIndex].stateMachine;
            this.m_StateMachine.pushUndo  = false;
            this.m_StateMachine.hideFlags = HideFlags.HideAndDontSave;
            this.m_SrcMotion = this.m_RefSrcState.motion;
            this.m_DstMotion = this.m_RefDstState.motion;
            this.m_ParameterMinMax.Clear();
            if ((bool)((UnityEngine.Object) this.m_SrcMotion) && this.m_SrcMotion is BlendTree)
            {
                BlendTree srcMotion = this.m_SrcMotion as BlendTree;
                for (int index = 0; index < srcMotion.recursiveBlendParameterCount; ++index)
                {
                    string recursiveBlendParameter = srcMotion.GetRecursiveBlendParameter(index);
                    if (this.m_Controller.IndexOfParameter(recursiveBlendParameter) == -1)
                    {
                        this.m_Controller.AddParameter(recursiveBlendParameter, AnimatorControllerParameterType.Float);
                        this.m_ParameterMinMax.Add(new Vector2(srcMotion.GetRecursiveBlendParameterMin(index), srcMotion.GetRecursiveBlendParameterMax(index)));
                    }
                }
            }
            if ((bool)((UnityEngine.Object) this.m_DstMotion) && this.m_DstMotion is BlendTree)
            {
                BlendTree dstMotion = this.m_DstMotion as BlendTree;
                for (int index1 = 0; index1 < dstMotion.recursiveBlendParameterCount; ++index1)
                {
                    string recursiveBlendParameter = dstMotion.GetRecursiveBlendParameter(index1);
                    int    index2 = this.m_Controller.IndexOfParameter(recursiveBlendParameter);
                    if (index2 == -1)
                    {
                        this.m_Controller.AddParameter(recursiveBlendParameter, AnimatorControllerParameterType.Float);
                        this.m_ParameterMinMax.Add(new Vector2(dstMotion.GetRecursiveBlendParameterMin(index1), dstMotion.GetRecursiveBlendParameterMax(index1)));
                    }
                    else
                    {
                        this.m_ParameterMinMax[index2] = new Vector2(Mathf.Min(dstMotion.GetRecursiveBlendParameterMin(index1), this.m_ParameterMinMax[index2][0]), Mathf.Max(dstMotion.GetRecursiveBlendParameterMax(index1), this.m_ParameterMinMax[index2][1]));
                    }
                }
            }
            this.m_SrcState           = this.m_StateMachine.AddState(this.m_RefSrcState.name);
            this.m_SrcState.pushUndo  = false;
            this.m_SrcState.hideFlags = HideFlags.HideAndDontSave;
            this.m_DstState           = this.m_StateMachine.AddState(this.m_RefDstState.name);
            this.m_DstState.pushUndo  = false;
            this.m_DstState.hideFlags = HideFlags.HideAndDontSave;
            this.CopyStateForPreview(this.m_RefSrcState, ref this.m_SrcState);
            this.CopyStateForPreview(this.m_RefDstState, ref this.m_DstState);
            this.m_Transition           = this.m_SrcState.AddTransition(this.m_DstState, true);
            this.m_Transition.pushUndo  = false;
            this.m_Transition.hideFlags = HideFlags.DontSave;
            this.CopyTransitionForPreview(this.m_RefTransition, ref this.m_Transition);
            this.DisableIKOnFeetIfNeeded();
            AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
            this.m_Controller.OnAnimatorControllerDirty += new System.Action(this.ControllerDirty);
        }