// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2026 Kybernetik // using System; using UnityEngine; namespace Animancer { /// A generic set of objects corresponding to up/right/down/left. /// /// Documentation: /// /// Directional Animation Sets /// /// https://kybernetik.com.au/animancer/api/Animancer/DirectionalSet4_1 /// [AnimancerHelpUrl(typeof(DirectionalSet4<>))] public class DirectionalSet4 : DirectionalSet { /************************************************************************************************************************/ #region Fields and Properties /************************************************************************************************************************/ [SerializeField] private T _Up; /// [] The object for . /// was not called before setting this value. public T Up { get => _Up; set { AssertAllowChanges(); _Up = value; AnimancerUtilities.SetDirty(this); } } /************************************************************************************************************************/ [SerializeField] private T _Right; /// [] The object for . /// was not called before setting this value. public T Right { get => _Right; set { AssertAllowChanges(); _Right = value; AnimancerUtilities.SetDirty(this); } } /************************************************************************************************************************/ [SerializeField] private T _Down; /// [] The object for . /// was not called before setting this value. public T Down { get => _Down; set { AssertAllowChanges(); _Down = value; AnimancerUtilities.SetDirty(this); } } /************************************************************************************************************************/ [SerializeField] private T _Left; /// [] The object for . /// was not called before setting this value. public T Left { get => _Left; set { AssertAllowChanges(); _Left = value; AnimancerUtilities.SetDirty(this); } } /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ #region Directions /************************************************************************************************************************/ /// public override int DirectionCount => 4; /************************************************************************************************************************/ /// protected override string GetDirectionName(int direction) => ((Direction4)direction).ToString(); /************************************************************************************************************************/ /// Returns the object associated with the specified `direction`. public T Get(Direction4 direction) => direction switch { Direction4.Up => _Up, Direction4.Right => _Right, Direction4.Down => _Down, Direction4.Left => _Left, _ => throw AnimancerUtilities.CreateUnsupportedArgumentException(direction), }; /// public override T Get(int direction) => Get((Direction4)direction); /************************************************************************************************************************/ /// public override T Get(Vector2 direction) { if (direction.x >= 0) { if (direction.y >= 0) return direction.x > direction.y ? _Right : _Up; else return direction.x > -direction.y ? _Right : _Down; } else { if (direction.y >= 0) return direction.x < -direction.y ? _Left : _Up; else return direction.x < direction.y ? _Left : _Down; } } /************************************************************************************************************************/ /// Sets the object associated with the specified `direction`. public void Set(Direction4 direction, T value) { switch (direction) { case Direction4.Up: Up = value; break; case Direction4.Right: Right = value; break; case Direction4.Down: Down = value; break; case Direction4.Left: Left = value; break; default: throw AnimancerUtilities.CreateUnsupportedArgumentException(direction); } } /// public override void Set(int direction, T value) => Set((Direction4)direction, value); /************************************************************************************************************************/ /// public override Vector2 GetDirection(int direction) => ((Direction4)direction).ToVector2(); /************************************************************************************************************************/ /// public override int GetDirection(string name) { var direction = AnimancerUtilities.GetDirection(name); if (direction.x == 0) { if (direction.y > 0) return (int)Direction4.Up; else if (direction.y < 0) return (int)Direction4.Down; else return -1; } else { if (direction.x > 0) return (int)Direction4.Right; else if (direction.x < 0) return (int)Direction4.Left; else return -1; } } /************************************************************************************************************************/ /// public override Vector2 Snap(Vector2 vector) => Directions.SnapToDirection4(vector); /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ } }