// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 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 modifier to use instead of the transition's default value.
public readonly float FadeDuration
=> _Fade;
/************************************************************************************************************************/
[SerializeField]
private float _NormalizedStartTime;
/// The normalized start time for this modifier to use instead of the transition's default value.
public readonly float NormalizedStartTime
=> _NormalizedStartTime;
/************************************************************************************************************************/
/// Creates a new .
public TransitionModifierDefinition(
int fromIndex,
int toIndex,
float fadeDuration,
float normalizedStartTime)
{
_From = fromIndex;
_To = toIndex;
_Fade = fadeDuration;
_NormalizedStartTime = normalizedStartTime;
}
/************************************************************************************************************************/
/// Does this modifier contain valid values?
public bool Validate()
{
var noFade = float.IsNaN(_Fade);
var noStart = float.IsNaN(_NormalizedStartTime);
if (noFade && noStart)
return false;
if (!noFade)
{
if (_Fade < 0)
_Fade = 0;
}
return true;
}
/************************************************************************************************************************/
/// Creates a copy of this modifier with the specified .
public readonly TransitionModifierDefinition WithFadeDuration(float fadeDuration)
=> new(_From, _To, fadeDuration, _NormalizedStartTime);
/// Creates a copy of this modifier with the specified .
public readonly TransitionModifierDefinition WithNormalizedStartTime(float normalizedStartTime)
=> new(_From, _To, _Fade, normalizedStartTime);
/// Creates a copy of this modifier with the specified and .
public readonly TransitionModifierDefinition WithDetails(float fadeDuration, float normalizedStartTime)
=> new(_From, _To, fadeDuration, normalizedStartTime);
/// Creates a copy of this modifier with the specified and .
public readonly TransitionModifierDefinition WithIndices(int fromIndex, int toIndex)
=> new(fromIndex, toIndex, _Fade, _NormalizedStartTime);
/************************************************************************************************************************/
/// Creates a new from this modifier.
public readonly TransitionDetails ToTransitionDetails()
=> new(_Fade, _NormalizedStartTime);
/************************************************************************************************************************/
/// Creates a new string describing this modifier.
public override readonly string ToString()
=> $"{nameof(TransitionModifierDefinition)}({_From}->{_To}, F={_Fade}, S={_NormalizedStartTime})";
/************************************************************************************************************************/
#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)
&& _NormalizedStartTime.IsEqualOrBothNaN(other._NormalizedStartTime);
/// 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.GetHashCode(),
_To.GetHashCode(),
_Fade.GetHashCode(),
_NormalizedStartTime.GetHashCode());
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
}
}