You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
4.0 KiB
C#
102 lines
4.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using SiegeSong;
|
|
|
|
namespace SiegeSong
|
|
{
|
|
public class Selector : MonoBehaviour
|
|
{
|
|
public Selectable Target;
|
|
|
|
public InventoryManager Inventory;
|
|
|
|
public Text TightSelectorText;
|
|
public Image TightSelectorIcon;
|
|
public Text LooseSelectorText;
|
|
public Image LooseSelectorIcon;
|
|
public GameObject LooseSelector;
|
|
public PlayerCameraManager CameraManager;
|
|
public Sprite DefaultIcon;
|
|
public bool InteractInputNewState;
|
|
|
|
private Color dangerColor = Color.red;
|
|
private Color defaultColor = Color.white;
|
|
private float tightSelectorMaxDistance = 2.0f;
|
|
private bool interacting;
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
var cameraObject = CameraManager.ActiveCamera;
|
|
if (Physics.Raycast(cameraObject.transform.position, cameraObject.transform.forward, out RaycastHit raycastHit))
|
|
{
|
|
if (Vector3.Distance(cameraObject.transform.position, raycastHit.point) < tightSelectorMaxDistance)
|
|
{
|
|
var selectable = raycastHit.transform.gameObject.GetComponent<Selectable>();
|
|
if (selectable == null)
|
|
selectable = raycastHit.transform.gameObject.GetComponentInChildren<Selectable>();
|
|
if (selectable == null && raycastHit.transform.parent != null)
|
|
selectable = raycastHit.transform.parent.gameObject.GetComponent<Selectable>();
|
|
if (selectable == null && raycastHit.transform.parent != null)
|
|
selectable = raycastHit.transform.parent.gameObject.GetComponent<Selectable>();
|
|
if (selectable == null && raycastHit.transform.parent != null && raycastHit.transform.parent.parent != null)
|
|
selectable = raycastHit.transform.parent.parent.gameObject.GetComponent<Selectable>();
|
|
if (selectable == null && raycastHit.transform.parent != null && raycastHit.transform.parent.parent != null && raycastHit.transform.parent.parent != null)
|
|
selectable = raycastHit.transform.parent.parent.parent.gameObject.GetComponent<Selectable>();
|
|
|
|
if (selectable != null && selectable.enabled)
|
|
{
|
|
Target = selectable;
|
|
TightSelectorText.text = $"{selectable.Interaction} {selectable.Name}";
|
|
TightSelectorIcon.sprite = selectable.Icon;
|
|
if (selectable.Danger)
|
|
{
|
|
TightSelectorText.color = dangerColor;
|
|
}
|
|
else
|
|
{
|
|
TightSelectorText.color = defaultColor;
|
|
}
|
|
if (InteractInputNewState)
|
|
{
|
|
if (!interacting)
|
|
{
|
|
interacting = true;
|
|
selectable.Activate(Inventory);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
interacting = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Target = null;
|
|
TightSelectorText.text = $"";
|
|
TightSelectorIcon.sprite = DefaultIcon;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Target = null;
|
|
TightSelectorText.text = $"";
|
|
TightSelectorIcon.sprite = DefaultIcon;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Target = null;
|
|
TightSelectorText.text = $"";
|
|
TightSelectorIcon.sprite = DefaultIcon;
|
|
}
|
|
}
|
|
}
|
|
}
|