// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik // using UnityEngine; namespace Animancer.Units { /// [Editor-Conditional] /// Causes a float field to display a suffix to indicate what kind of units the value represents as well as /// displaying it as several different fields which convert the value between different units. /// /// /// Documentation: /// /// Units Attribute /// /// https://kybernetik.com.au/animancer/api/Animancer.Units/UnitsAttribute /// [System.Diagnostics.Conditional(Strings.UnityEditor)] public class UnitsAttribute : PropertyAttribute { /************************************************************************************************************************/ /// The multipliers to convert from the field's actual value to each unit type. /// valueInUnitX = valueInBaseUnits * Multipliers[x]; public readonly float[] Multipliers; /// The unit suffix to display at the end of the value in each field. public readonly string[] Suffixes; /// The index of the multiplier where the field stores its actual value. /// The multiplier at this index must always be 1. public readonly int UnitIndex; /************************************************************************************************************************/ /// The validation rule applied to the value. public Validate.Value Rule { get; set; } /// Should the field have a toggle to set its value to ? public bool IsOptional { get; set; } /// The value to display if the actual value is . public float DefaultValue { get; set; } /// Optional text to display instead of the regular fields when the value is . public string DisabledText { get; set; } /************************************************************************************************************************/ /// Creates a new . protected UnitsAttribute() { } /// Creates a new . public UnitsAttribute(string suffix) { Multipliers = new float[] { 1 }; Suffixes = new string[] { suffix }; } /// Creates a new . public UnitsAttribute(float[] multipliers, string[] suffixes, int unitIndex = 0) { Multipliers = multipliers; Suffixes = suffixes; UnitIndex = unitIndex; Debug.Assert(multipliers.Length == suffixes.Length, $"[Units] The {nameof(multipliers)} and {nameof(suffixes)} arrays have different lengths."); Debug.Assert((uint)UnitIndex < (uint)multipliers.Length, $"[Units] The {nameof(unitIndex)} is outside the {nameof(multipliers)} array."); } /************************************************************************************************************************/ } }