Exemplo n.º 1
0
 public void Release()
 {
     if (tmpAnimatorController != null)
     {
         if (animator != null)
         {
             animator.runtimeAnimatorController = null;
         }
         {
             var layerCount = tmpAnimatorController.layers.Length;
             for (int i = 0; i < layerCount; i++)
             {
                 tmpAnimatorController.RemoveLayer(0);
             }
         }
         UnityEditor.Animations.AnimatorController.DestroyImmediate(tmpAnimatorController);
         tmpAnimatorController = null;
     }
     animator  = null;
     animation = null;
     if (vaEdit != null)
     {
         Component.DestroyImmediate(vaEdit);
         vaEdit = null;
     }
     if (gameObject != null)
     {
         GameObject.DestroyImmediate(gameObject);
         gameObject = null;
     }
     sourceObject = null;
 }
Exemplo n.º 2
0
        public void ValidateLayers(AnimatorController controller)
        {
            for (int i = 0; i < AvaCryptKeyNames.Length; ++i)
            {
                if (controller.layers.All(l => l.name != AvaCryptKeyNames[i]))
                {
                    CreateLayer(i, controller);
                }
                else
                {
                    Debug.Log($"Layer already existing: {AvaCryptKeyNames[i]}");
                    AnimatorControllerLayer layer = controller.layers.FirstOrDefault(l => l.name == AvaCryptKeyNames[i]);

                    if (layer.stateMachine == null)
                    {
                        Debug.Log("Layer missing state machine.");

                        // Try to delete blend tree and layers if by chance they still exist for some reason.
                        DeleteObjectFromController(controller, string.Format(StateMachineName, i));
                        DeleteObjectFromController(controller, string.Format(BlendTreeName, i));

                        controller.RemoveLayer(controller.layers.ToList().IndexOf(layer));

                        CreateLayer(i, controller);
                    }
                    else
                    {
                        ValidateLayerBlendTree(i, layer, controller);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void ValidateLayers(AnimatorController controller)
        {
            for (int i = 0; i < _avaCryptKeyNames.Length; ++i)
            {
                if (controller.layers.All(l => l.name != _avaCryptKeyNames[i]))
                {
                    CreateLayer(i, controller);
                }
                else
                {
                    Debug.Log($"Layer already existing: {_avaCryptKeyNames[i]}");
                    AnimatorControllerLayer layer = controller.layers.FirstOrDefault(l => l.name == _avaCryptKeyNames[i]);

                    if (layer == null || layer.stateMachine == null)
                    {
                        Debug.Log("Layer missing state machine.");

                        controller.RemoveLayer(controller.layers.ToList().IndexOf(layer));

                        CreateLayer(i, controller);
                    }
                    else
                    {
                        ValidateBitKeySwitch(i, layer, controller);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Release()
        {
#if UNITY_2018_3_OR_NEWER
            if (m_PlayableGraph.IsValid())
            {
                m_PlayableGraph.Destroy();
            }
#endif
            if (animator != null && animator.runtimeAnimatorController != null)
            {
                UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, null);
            }
            if (tmpAnimatorController != null)
            {
                {
                    var layerCount = tmpAnimatorController.layers.Length;
                    for (int i = 0; i < layerCount; i++)
                    {
                        tmpAnimatorController.RemoveLayer(0);
                    }
                }
                UnityEditor.Animations.AnimatorController.DestroyImmediate(tmpAnimatorController);
                tmpAnimatorController = null;
            }
            tmpAnimatorControllerLayer = null;
            tmpAnimationState          = null;

            RevertTransparent();

            animator  = null;
            animation = null;
            if (vaEdit != null)
            {
                Component.DestroyImmediate(vaEdit);
                vaEdit = null;
            }
            if (gameObject != null)
            {
                GameObject.DestroyImmediate(gameObject);
                gameObject = null;
            }
            sourceObject = null;
        }
Exemplo n.º 5
0
        private void Change(bool change)
        {
            var t             = gameObject.transform;
            var localPosition = t.localPosition;
            var localRotation = t.localRotation;
            var localScale    = t.localScale;

            Undo.RecordObject(this, "Change Animator Controller");
            Undo.RecordObject(animatorCache, "Change Animator Controller");
            if (change)
            {
                Assert.IsFalse(changed);
                animatorCache.hideFlags |= HideFlags.NotEditable;

                originalAnimatorApplyRootMotion = animatorCache.applyRootMotion;
                originalAnimatorUpdateMode      = animatorCache.updateMode;
                originalAnimatorCullingMode     = animatorCache.cullingMode;

                animatorCache.applyRootMotion = false;
                animatorCache.updateMode      = AnimatorUpdateMode.Normal;
                animatorCache.cullingMode     = AnimatorCullingMode.AlwaysAnimate;

                #region AnimatorController
                {
                    originalRuntimeAnimatorController = animatorCache.runtimeAnimatorController;
                    tmpAnimatorController             = new UnityEditor.Animations.AnimatorController();
                    tmpAnimatorController.name        = "Very Animation Temporary Controller";
                    tmpAnimatorController.hideFlags  |= HideFlags.HideAndDontSave;
                    {
                        tmpAnimatorController.AddLayer("Very Animation Layer");
                        layers = tmpAnimatorController.layers;
                        foreach (var layer in layers)
                        {
                            layer.iKPass = true;
                            var stateMachine = layer.stateMachine;
                            stateMachine.hideFlags |= HideFlags.HideAndDontSave;
                            {
                                state            = stateMachine.AddState("Animation");
                                state.hideFlags |= HideFlags.HideAndDontSave;
                                stateNameHash    = state.nameHash;
                            }
                            layer.stateMachine = stateMachine;
                        }
                        tmpAnimatorController.layers = layers;
                    }
                    UnityEditor.Animations.AnimatorController.SetAnimatorController(animatorCache, tmpAnimatorController);
                }
                #endregion
                changed = true;
            }
            else
            {
                Assert.IsTrue(changed);
                animatorCache.hideFlags &= ~HideFlags.NotEditable;

                animatorCache.applyRootMotion = originalAnimatorApplyRootMotion;
                animatorCache.updateMode      = originalAnimatorUpdateMode;
                animatorCache.cullingMode     = originalAnimatorCullingMode;

                #region AnimatorController
                {
                    {
                        var layerCount = tmpAnimatorController.layers.Length;
                        for (int i = 0; i < layerCount; i++)
                        {
                            tmpAnimatorController.RemoveLayer(0);
                        }
                    }
                    DestroyImmediate(tmpAnimatorController);
                    tmpAnimatorController = null;
                    animatorCache.runtimeAnimatorController = originalRuntimeAnimatorController;
                }
                #endregion

                originalRuntimeAnimatorController = null;

                changed = false;
            }

            //Cause unknown. It does not allow initialization.
            {
                t.localPosition = localPosition;
                t.localRotation = localRotation;
                t.localScale    = localScale;
            }
        }