Example #1
0
        public static void RemoveAnimancerComponent(this Animator animator)
        {
            AnimancerComponent animancer = animator.GetComponent <AnimancerComponent>();

            GameObject.DestroyObject(animancer);
            animancer = null;
        }
Example #2
0
        /// <summary>
        /// Tries to invoke the <see cref="AnimancerEvent.Sequence.endEvent"/> of the <see cref="AnimancerState"/> that
        /// triggered the `animationEvent`.
        /// </summary>
        /// <remarks>
        /// Note that Unity will allocate some garbage every time it triggers an Animation Event with an
        /// <see cref="AnimationEvent"/> parameter.
        /// </remarks>
        public static bool End(AnimancerComponent animancer, AnimationEvent animationEvent)
        {
            if (!animancer.IsPlayableInitialised)
            {
                // This could only happen if another Animator triggers the event on this object somehow.
                Debug.LogWarning($"{nameof(AnimationEvent)} '{nameof(End)}' was triggered by {animationEvent.animatorClipInfo.clip}" +
                                 $", but the {nameof(AnimancerComponent)}.{nameof(AnimancerComponent.Playable)} hasn't been initialised.",
                                 animancer);
                return(false);
            }

            var layers = animancer.Layers;
            var count  = layers.Count;

            // Try targeting the current state on each layer first.
            for (int i = 0; i < count; i++)
            {
                if (TryInvokeOnEndEventRecursive(layers[i].CurrentState, animationEvent))
                {
                    return(true);
                }
            }

            // Otherwise try every state.
            for (int i = 0; i < count; i++)
            {
                if (TryInvokeOnEndEventRecursive(layers[i], animationEvent))
                {
                    return(true);
                }
            }

            if (animationEvent.messageOptions == SendMessageOptions.RequireReceiver)
            {
                Debug.LogWarning($"{nameof(AnimationEvent)} '{nameof(End)}' was triggered by {animationEvent.animatorClipInfo.clip}" +
                                 $", but no state was found with that {nameof(AnimancerState.Key)}.",
                                 animancer);
            }

            return(false);
        }
Example #3
0
        /************************************************************************************************************************/

#if UNITY_EDITOR
        /// <summary>[Editor-Only]
        /// Called when this component is first added in Edit Mode.
        /// Finds the <see cref="Animancer"/> using <see cref="AnimancerEditorUtilities.GetComponentInHierarchy"/>.
        /// </summary>
        protected virtual void Reset()
        {
            _Animancer = AnimancerEditorUtilities.GetComponentInHierarchy <AnimancerComponent>(gameObject);
        }
Example #4
0
        /************************************************************************************************************************/

        /// <summary>
        /// Returns the value of the <see cref="Curve"/> at the current <see cref="AnimancerState.Time"/> of the state
        /// registered with the <see cref="Clip"/> as its key.
        /// </summary>
        public float Evaluate(AnimancerComponent animancer)
        {
            return(Evaluate(animancer.States[_Clip]));
        }
Example #5
0
        /************************************************************************************************************************/

        /// <summary>Modify the current fade to use the specified `function` to calculate the weight.</summary>
        /// <example>See <see cref="CustomFade"/>.</example>
        public static void Apply(AnimancerComponent animancer, Easing.Function function)
        => Apply(animancer.States.Current, function);
Example #6
0
        /************************************************************************************************************************/

        /// <summary>Modify the current fade to use the specified `calculateWeight` delegate.</summary>
        /// <example>See <see cref="CustomFade"/>.</example>
        /// <remarks>The `calculateWeight` should follow the <see cref="OptionalWarning.CustomFadeBounds"/> guideline.</remarks>
        public static void Apply(AnimancerComponent animancer, Func <float, float> calculateWeight)
        => Apply(animancer.States.Current, calculateWeight);
Example #7
0
        /************************************************************************************************************************/

        /// <summary>Modify the current fade to use the specified `curve` to calculate the weight.</summary>
        /// <example>See <see cref="CustomFade"/>.</example>
        /// <remarks>The `curve` should follow the <see cref="OptionalWarning.CustomFadeBounds"/> guideline.</remarks>
        public static void Apply(AnimancerComponent animancer, AnimationCurve curve)
        => Apply(animancer.States.Current, curve);
Example #8
0
        /************************************************************************************************************************/

        /// <summary>
        /// Returns the value of the <see cref="Curve"/> at the current <see cref="AnimancerState.Time"/> of the state
        /// registered with the <see cref="Clip"/> as its key.
        /// </summary>
        public float Evaluate(AnimancerComponent animancer)
        {
            return(Evaluate(animancer.GetState(_Clip)));
        }