// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik //
#if UNITY_EDITOR
using UnityEngine;
namespace Animancer.Editor
{
/// [Editor-Only] A utility for calculating where a pointer is aiming inside a uniformly sized list.
/// https://kybernetik.com.au/animancer/api/Animancer.Editor/ListTargetCalculation
public struct ListTargetCalculation
{
/************************************************************************************************************************/
/// The target list index.
public int Index;
/// The target position within the target list index.
/// 0 means the target is right at the start, 0.5 in the middle, and 1 at the end.
public float LocalOffset;
/************************************************************************************************************************/
/// Creates a new .
public ListTargetCalculation(
int index,
float localOffset)
{
Index = index;
LocalOffset = localOffset;
}
/// Calculates the target of the specified parameters.
public ListTargetCalculation(
float start,
float size,
float target)
{
target -= start;
target /= size;
Index = Mathf.FloorToInt(target);
LocalOffset = target - Index;
}
/// Calculates the target of the specified parameters.
public ListTargetCalculation(
float start,
float size,
int count,
float target)
: this(start, size, target)
{
Index = Mathf.Clamp(Mathf.FloorToInt(Index), 0, count);
}
/************************************************************************************************************************/
/// Describes the and .
public override readonly string ToString()
=> $"({Index}, {LocalOffset})";
/************************************************************************************************************************/
}
}
#endif