This commit is contained in:
2026-04-25 23:37:10 +02:00
commit 19d6bd934a
476 changed files with 9198 additions and 0 deletions
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UIElements;
namespace RPGCoreCommon.Select
{
/// <summary>
/// Result of using <see cref="Select"/>. Contains information what was clicked in a moment of execution.
/// </summary>
public class SelectUtilResult
{
/// <summary>
/// Source of selection:
/// <ul>
/// <li><see cref="SelectType.None"/> - probably pressed void, so nothing to select</li>
/// <li><see cref="SelectType.Scene"/> - something from scene (GameObject and/or Component)</li>
/// <li><see cref="SelectType.UI"/> - something from UI</li>
/// </ul>
/// </summary>
public SelectType hit { get; private set; }
/// <summary>UI only: select position on UI</summary>
public Vector2 uiPosition { get; private set; }
/// <summary>UI only: All that extends <see cref="ISelectableUI"/>. Can be VisualElement itself, its userData or its dataSource.</summary>
public List<ISelectableUI> uiSelectables { get; private set; } = new();
/// <summary>UI only: first from <see cref="uiSelectables"/></summary>
public ISelectableUI uiSelectable => uiSelectables.FirstOrDefault();
/// <summary>Scene only: select position on scene</summary>
public Vector3 position { get; private set; }
/// <summary>Scene only: selected GameObject</summary>
public GameObject gameObject { get; private set; }
/// <summary>Scene only: selected GameObject's Component</summary>
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;
}
}
}