using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UIElements; namespace RPGCoreCommon.Select { /// /// Result of using . Contains information what was clicked in a moment of execution. /// public class SelectUtilResult { /// /// Source of selection: /// /// public SelectType hit { get; private set; } /// UI only: select position on UI public Vector2 uiPosition { get; private set; } /// UI only: All that extends . Can be VisualElement itself, its userData or its dataSource. public List uiSelectables { get; private set; } = new(); /// UI only: first from public ISelectableUI uiSelectable => uiSelectables.FirstOrDefault(); /// Scene only: select position on scene public Vector3 position { get; private set; } /// Scene only: selected GameObject public GameObject gameObject { get; private set; } /// Scene only: selected GameObject's Component public Component component { get; private set; } internal SelectUtilResult(Vector3 position, GameObject gameObject = null, Component component = null) { hit = SelectType.Scene; this.position = position; this.gameObject = gameObject; this.component = component; } internal SelectUtilResult(Vector2 uiPosition, VisualElement visualElement = null) { hit = visualElement == null ? SelectType.None : SelectType.UI; this.uiPosition = uiPosition; while (visualElement != null) { if (visualElement is ISelectableUI iSelectableUI) uiSelectables.Add(iSelectableUI); else if (visualElement.dataSource is ISelectableUI dataSource) uiSelectables.Add(dataSource); else if (visualElement.userData is ISelectableUI userData) uiSelectables.Add(userData); visualElement = visualElement.parent; } } internal SelectUtilResult() { hit = SelectType.None; } } }