namespace Zinnia.Data.Operation.Extraction { using System; using UnityEngine; using UnityEngine.Events; using Zinnia.Data.Attribute; using Zinnia.Extension; /// /// Extracts and emits the found in relation to the . /// /// The result type. /// The unity event to emit. /// The event element type. public abstract class ComponentExtractor : ValueExtractor where TEvent : UnityEvent, new() { /// /// The criteria to search for the related . /// [Flags] public enum SearchCriteria { /// /// Search for the component on the current and on any descendant. /// IncludeDescendants = 1 << 0, /// /// Search for the component on the current and on any ancestor. /// IncludeAncestors = 1 << 1 } [Tooltip("Determines whether to search for the TResultElement component on the ancestors and or descendants of the Source.")] [SerializeField] [UnityFlags] private SearchCriteria searchAlsoOn = (SearchCriteria)(-1); /// /// Determines whether to search for the component on the ancestors and or descendants of the . /// public SearchCriteria SearchAlsoOn { get { return searchAlsoOn; } set { searchAlsoOn = value; } } /// /// Attempts to set the via a . /// /// The source of the component. public virtual void SetSource(GameObject source) { if (!this.IsValidState()) { return; } Source = source != null ? source.transform : null; } /// /// Extracts the from the given . /// /// The data to extract from. /// The extracted data. public virtual TResultElement Extract(GameObject data) { if (!this.IsValidState()) { return default; } SetSource(data); return Extract(); } /// /// Extracts the from the given . /// /// The data to extract from. public virtual void DoExtract(GameObject data) { Extract(data); } } }