namespace Zinnia.Data.Operation.Extraction { using System; using UnityEngine; using UnityEngine.Events; using Zinnia.Extension; /// /// Extracts and emits the components of a . /// [Obsolete("Use `Zinnia.Data.Type.Transformation.Conversion.Vector2ToFloat` instead.")] public class Vector2ComponentExtractor : MonoBehaviour { /// /// Defines an event with a value. /// [Serializable] public class UnityEvent : UnityEvent { } /// /// The components of a /// public enum Vector2Component { /// /// The X component. /// X, /// /// The Y component. /// Y } [Tooltip("The source to extract from.")] [SerializeField] private Vector2 source; /// /// The source to extract from. /// public Vector2 Source { get { return source; } set { source = value; } } [Tooltip("The component to extract from the Vector2.")] [SerializeField] private Vector2Component componentToExtract = Vector2Component.X; /// /// The component to extract from the . /// public Vector2Component ComponentToExtract { get { return componentToExtract; } set { componentToExtract = value; } } /// /// Emitted when the component from is extracted. /// public UnityEvent Extracted = new UnityEvent(); /// /// The extracted component. /// public float? Result { get; protected set; } /// /// Extracts the component from the . /// /// The extracted . public virtual float? Extract() { if (!this.CheckIsActiveAndEnabled()) { Result = null; return null; } switch (ComponentToExtract) { case Vector2Component.X: Result = Source.x; break; case Vector2Component.Y: Result = Source.y; break; } Extracted?.Invoke(Result.Value); return Result; } /// /// Extracts the component from the . /// public virtual void DoExtract() { if (!this.IsValidState()) { return; } Extract(); } /// /// Extracts the component from the . /// /// The source to extract from. /// The extracted . public virtual float? Extract(Vector2 source) { if (!this.IsValidState()) { return null; } Source = source; return Extract(); } /// /// Extracts the component from the . /// /// The source to extract from. public virtual void DoExtract(Vector2 source) { if (!this.IsValidState()) { return; } Extract(source); } } }