init
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
using VOID.Generic.Objects.Abstract;
|
||||
using VOID.UserInterface;
|
||||
using VOID.UserInterface.Game.Party;
|
||||
using VOID.UserInterface.Game.Util;
|
||||
|
||||
namespace VOID.Generic.Player.Util
|
||||
{
|
||||
public static class SelectUtil
|
||||
{
|
||||
private const int LayerMask = LayerManager.Static | LayerManager.Dynamic;
|
||||
|
||||
/// <summary>
|
||||
/// Returns result from SelectFromUI() or SelectFromScene() depending on whether it was over UI
|
||||
/// </summary>
|
||||
public static SelectUtilResult Select()
|
||||
{
|
||||
return GameUI.current.isCursorOverUI ? SelectFromUI() : SelectFromScene();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns clicked AbstractObject or position if something else clicked from scene
|
||||
/// </summary>
|
||||
public static SelectUtilResult SelectFromScene()
|
||||
{
|
||||
if (GameUI.current.isCursorOverUI) return new SelectUtilResult();
|
||||
|
||||
var hit = SelectHit();
|
||||
|
||||
if (!hit.collider) return new SelectUtilResult();
|
||||
|
||||
var hitPosition = hit.point;
|
||||
var hitObject = hit.collider.gameObject.GetComponentInParent<AbstractObject>();
|
||||
|
||||
if (hitObject == PlayerController.current.activeUnit) return new SelectUtilResult();
|
||||
|
||||
if (!hitObject) return new SelectUtilResult(hitPosition);
|
||||
|
||||
return new SelectUtilResult(hitPosition, hitObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns clicked AbstractObject or BasicAbility from UI. Using cached position and ui elements if provided.
|
||||
/// </summary>
|
||||
public static SelectUtilResult SelectFromUI(List<VisualElement> cachedElements = null)
|
||||
{
|
||||
if (cachedElements is { Count: 0 }) return new SelectUtilResult();
|
||||
if (cachedElements is null && !GameUI.current.isCursorOverUI) return new SelectUtilResult();
|
||||
|
||||
// Here we only handle first element - we don't care whats behind it
|
||||
switch (GameUI.current.PickTopComponentUI(cachedElements))
|
||||
{
|
||||
case SlotUI slotUI: return new SelectUtilResult(slotUI).WithUI(cachedElements);
|
||||
case UnitPortraitUI unitPortraitUI: return new SelectUtilResult(unitPortraitUI).WithUI(cachedElements);
|
||||
default: return new SelectUtilResult();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Vector3 of clicked position
|
||||
/// </summary>
|
||||
public static Vector3 SelectPosition()
|
||||
{
|
||||
return SelectHit().point;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see cref="RaycastHit"/> of clicked position
|
||||
/// </summary>
|
||||
public static RaycastHit SelectHit()
|
||||
{
|
||||
Physics.Raycast(
|
||||
Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue()),
|
||||
out var hit,
|
||||
Mathf.Infinity,
|
||||
LayerMask);
|
||||
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed31bdea373641d0ba8d504ba6cc5ef5
|
||||
timeCreated: 1690108898
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using VOID.Generic.Objects.Abstract;
|
||||
using VOID.UserInterface;
|
||||
using VOID.UserInterface.Game;
|
||||
using VOID.UserInterface.Game.Party;
|
||||
using VOID.UserInterface.Game.Util;
|
||||
using VOID.ScriptableObjects;
|
||||
using VOID.ScriptableObjects.Abilities;
|
||||
|
||||
namespace VOID.Generic.Player.Util
|
||||
{
|
||||
public class SelectUtilResult
|
||||
{
|
||||
public bool hit { get; private set; }
|
||||
public bool onUI { get; private set; }
|
||||
|
||||
// UI Component directly under cursor - only one of these
|
||||
public readonly SlotUI slotUI;
|
||||
public readonly UnitPortraitUI unitPortraitUI;
|
||||
public readonly StatusUI statusUI;
|
||||
|
||||
// All UI Components behind - usually one of these
|
||||
public AbilityBookUI abilityBookUI { get; private set; }
|
||||
public ActionBarSlotsUI actionBarSlotsUI { get; private set; }
|
||||
public BackpackUI backpackUI { get; private set; }
|
||||
public ContainerUI containerUI { get; private set; }
|
||||
public EquipmentUI equipmentUI { get; private set; }
|
||||
public OtherUnitBackpackUI otherUnitBackpackUI { get; private set; }
|
||||
public PartyUI partyUI { get; private set; }
|
||||
|
||||
// Clicked position or clicked object's position
|
||||
public readonly Vector3 position;
|
||||
|
||||
// Clicked object , ability or status
|
||||
public readonly AbstractObject selectObject;
|
||||
public readonly BasicAbility selectAbility;
|
||||
public readonly BasicStatus selectStatus;
|
||||
|
||||
public SelectUtilResult(Vector3 position)
|
||||
{
|
||||
hit = position != default;
|
||||
onUI = false;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public SelectUtilResult(Vector3 position, AbstractObject abstractObject)
|
||||
{
|
||||
hit = abstractObject;
|
||||
onUI = false;
|
||||
this.position = position;
|
||||
selectObject = abstractObject;
|
||||
}
|
||||
|
||||
public SelectUtilResult(SlotUI slotUI)
|
||||
{
|
||||
hit = slotUI.ability || slotUI.item;
|
||||
onUI = true;
|
||||
this.slotUI = slotUI;
|
||||
|
||||
// Position to select:
|
||||
// - in case of ItemObject, select its position
|
||||
// - in case of BasicAbility, select caster's position (player's active unit)
|
||||
if (slotUI.item) position = slotUI.item.transform.position;
|
||||
else if (PlayerController.current.activeUnit) position = PlayerController.current.activeUnit.transform.position;
|
||||
|
||||
if (slotUI.ability) selectAbility = slotUI.ability;
|
||||
if (slotUI.item) selectObject = slotUI.item;
|
||||
}
|
||||
|
||||
public SelectUtilResult(UnitPortraitUI unitPortraitUI)
|
||||
{
|
||||
hit = unitPortraitUI.unit;
|
||||
onUI = true;
|
||||
this.unitPortraitUI = unitPortraitUI;
|
||||
position = unitPortraitUI.unit.transform.position;
|
||||
selectObject = unitPortraitUI.unit;
|
||||
}
|
||||
|
||||
public SelectUtilResult(StatusUI statusUI)
|
||||
{
|
||||
hit = statusUI.status;
|
||||
onUI = true;
|
||||
this.statusUI = statusUI;
|
||||
selectStatus = statusUI.status;
|
||||
}
|
||||
|
||||
public SelectUtilResult()
|
||||
{
|
||||
onUI = false;
|
||||
hit = false;
|
||||
}
|
||||
|
||||
public SelectUtilResult WithUI(List<VisualElement> cachedElements = null)
|
||||
{
|
||||
if (!onUI) return this;
|
||||
abilityBookUI = GameUI.current.PickComponentUI<AbilityBookUI>(cachedElements);
|
||||
actionBarSlotsUI = GameUI.current.PickComponentUI<ActionBarSlotsUI>(cachedElements);
|
||||
backpackUI = GameUI.current.PickComponentUI<BackpackUI>(cachedElements);
|
||||
containerUI = GameUI.current.PickComponentUI<ContainerUI>(cachedElements);
|
||||
equipmentUI = GameUI.current.PickComponentUI<EquipmentUI>(cachedElements);
|
||||
otherUnitBackpackUI = GameUI.current.PickComponentUI<OtherUnitBackpackUI>(cachedElements);
|
||||
partyUI = GameUI.current.PickComponentUI<PartyUI>(cachedElements);
|
||||
onUI = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfe37d23a411470caeb669f4790d9b73
|
||||
timeCreated: 1690109079
|
||||
Reference in New Issue
Block a user