// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace Animancer.TransitionLibraries
{
/// [] A and pair.
///
/// Documentation:
///
/// Transition Libraries
///
/// https://kybernetik.com.au/animancer/api/Animancer.TransitionLibraries/NamedIndex
[Serializable]
public struct NamedIndex :
IComparable,
IEquatable
{
/************************************************************************************************************************/
[SerializeField]
private StringAsset _Name;
/// The name.
public readonly StringAsset Name
=> _Name;
/************************************************************************************************************************/
[SerializeField]
private int _Index;
/// The index.
public readonly int Index
=> _Index;
/************************************************************************************************************************/
/// Creates a new .
public NamedIndex(StringAsset name, int index)
{
_Name = name;
_Index = index;
}
/************************************************************************************************************************/
/// Creates a new .
public readonly NamedIndex With(StringAsset name)
=> new(name, _Index);
/// Creates a new .
public readonly NamedIndex With(int index)
=> new(_Name, index);
/************************************************************************************************************************/
/// Describes this value.
public override readonly string ToString()
=> $"[{_Index}]{_Name}";
/************************************************************************************************************************/
#region Equality
/************************************************************************************************************************/
/// Compares the then .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly int CompareTo(NamedIndex other)
{
var result = _Index.CompareTo(other._Index);
if (result != 0)
return result;
else
return StringAsset.Compare(_Name, other._Name);
}
/************************************************************************************************************************/
/// Are all fields in this object equal to the equivalent in `obj`?
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override readonly bool Equals(object obj)
=> obj is NamedIndex value
&& Equals(value);
/// Are all fields in this object equal to the equivalent fields in `other`?
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(NamedIndex other)
=> _Index == other._Index
&& _Name == other._Name;
/// Are all fields in `a` equal to the equivalent fields in `b`?
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(NamedIndex a, NamedIndex b)
=> a.Equals(b);
/// Are any fields in `a` not equal to the equivalent fields in `b`?
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(NamedIndex a, NamedIndex b)
=> !(a == b);
/************************************************************************************************************************/
/// Returns a hash code based on the values of this object's fields.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override readonly int GetHashCode()
=> AnimancerUtilities.Hash(-871379578,
_Index.SafeGetHashCode(),
_Name.SafeGetHashCode());
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
}
}