// MIT License - Copyright (c) 2023 wallstop // Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE namespace WallstopStudios.UnityHelpers.Core.Extension { using UnityEngine; /// /// Extension methods for Unity's Animator class. /// public static class AnimatorExtensions { /// /// Resets all trigger parameters on the Animator to their default state. /// /// The Animator whose triggers will be reset. /// /// This method iterates through all parameters on the Animator and resets any parameters of type Trigger. /// Only processes the Animator if it is not null and is active and enabled. /// Non-trigger parameters are left unchanged. /// This is useful for cleaning up trigger states between animation transitions or when resetting an Animator to a known state. /// Thread-safe: No. Must be called from the main Unity thread. /// Performance: O(n) where n is the number of parameters on the Animator. /// public static void ResetTriggers(this Animator animator) { if (animator == null || !animator.isActiveAndEnabled) { return; } foreach (AnimatorControllerParameter animatorParameter in animator.parameters) { if (animatorParameter.type != AnimatorControllerParameterType.Trigger) { continue; } animator.ResetTrigger(animatorParameter.name); } } } }