// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2022 Kybernetik // using System; using UnityEngine; namespace Animancer { /// A generic set of objects corresponding to left/right. /// /// Documentation: /// /// Directional Animation Sets /// /// https://kybernetik.com.au/animancer/api/Animancer/DirectionalSet2_1 /// [AnimancerHelpUrl(typeof(DirectionalSet2<>))] public class DirectionalSet2 : DirectionalSet { /************************************************************************************************************************/ #region Fields and Properties /************************************************************************************************************************/ [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); } } /************************************************************************************************************************/ [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); } } /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ #region Directions /************************************************************************************************************************/ /// public override int DirectionCount => 2; /************************************************************************************************************************/ /// protected override string GetDirectionName(int direction) => ((Direction2)direction).ToString(); /************************************************************************************************************************/ /// Returns the object associated with the specified `direction`. public T Get(Direction2 direction) => direction switch { Direction2.Left => _Left, Direction2.Right => _Right, _ => throw AnimancerUtilities.CreateUnsupportedArgumentException(direction), }; /// public override T Get(int direction) => Get((Direction2)direction); /************************************************************************************************************************/ /// public override T Get(Vector2 direction) => Get(direction.x); /// Negative `direction` returns , 0 or positive returns . public T Get(float direction) => direction < 0 ? _Left : _Right; /************************************************************************************************************************/ /// Sets the object associated with the specified `direction`. public void Set(Direction2 direction, T value) { switch (direction) { case Direction2.Left: Left = value; break; case Direction2.Right: Right = value; break; default: throw AnimancerUtilities.CreateUnsupportedArgumentException(direction); } } /// public override void Set(int direction, T value) => Set((Direction2)direction, value); /************************************************************************************************************************/ /// public override Vector2 GetDirection(int direction) => ((Direction2)direction).ToVector2(); /************************************************************************************************************************/ /// public override int GetDirection(string name) { var direction = AnimancerUtilities.GetDirection(name); if (direction.x == 0) direction.x = direction.y; return direction.x switch { > 0 => (int)Direction2.Right, < 0 => (int)Direction2.Left, _ => -1 }; } /************************************************************************************************************************/ /// public override Vector2 Snap(Vector2 vector) => Directions.SnapToDirection2(vector); /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ } }