// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik // using System; using UnityEngine; namespace Animancer.TransitionLibraries { /// [] /// Details about how to modify a transition when it comes from a specific source. /// /// /// Multiple of these can be used to build a at runtime. /// /// Documentation: /// /// Transition Libraries /// /// https://kybernetik.com.au/animancer/api/Animancer.TransitionLibraries/TransitionModifierDefinition [Serializable] public struct TransitionModifierDefinition : IEquatable { /************************************************************************************************************************/ [SerializeField] private int _From; /// The index of the source transition in the . public readonly int FromIndex => _From; /************************************************************************************************************************/ [SerializeField] private int _To; /// The index of the destination transition in the . public readonly int ToIndex => _To; /************************************************************************************************************************/ [SerializeField] private float _Fade; /// The fade duration for this override to use. public readonly float FadeDuration => _Fade; /************************************************************************************************************************/ /// Creates a new . public TransitionModifierDefinition( int fromIndex, int toIndex, float fadeDuration) { _From = fromIndex; _To = toIndex; _Fade = fadeDuration; } /************************************************************************************************************************/ /// Creates a copy of this override with the specified . public readonly TransitionModifierDefinition WithFadeDuration(float fadeDuration) => new(_From, _To, fadeDuration); /// Creates a copy of this override with the specified and . public readonly TransitionModifierDefinition WithIndices(int fromIndex, int toIndex) => new(fromIndex, toIndex, _Fade); /************************************************************************************************************************/ /// Creates a new string describing this override. public override readonly string ToString() => $"{nameof(TransitionModifierDefinition)}({_From}->{_To}={_Fade})"; /************************************************************************************************************************/ #region Equality /************************************************************************************************************************/ /// Are all fields in this object equal to the equivalent in `obj`? public override readonly bool Equals(object obj) => obj is TransitionModifierDefinition value && Equals(value); /// Are all fields in this object equal to the equivalent fields in `other`? public readonly bool Equals(TransitionModifierDefinition other) => _From == other._From && _To == other._To && _Fade.IsEqualOrBothNaN(other._Fade); /// Are all fields in `a` equal to the equivalent fields in `b`? public static bool operator ==(TransitionModifierDefinition a, TransitionModifierDefinition b) => a.Equals(b); /// Are any fields in `a` not equal to the equivalent fields in `b`? public static bool operator !=(TransitionModifierDefinition a, TransitionModifierDefinition b) => !(a == b); /************************************************************************************************************************/ /// Returns a hash code based on the values of this object's fields. public override readonly int GetHashCode() => AnimancerUtilities.Hash(-871379578, _From.SafeGetHashCode(), _To.SafeGetHashCode(), _Fade.SafeGetHashCode()); /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ } }