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 CameraManager 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(); if (selectable == null) selectable = raycastHit.transform.gameObject.GetComponentInChildren(); if (selectable == null && raycastHit.transform.parent != null) selectable = raycastHit.transform.parent.gameObject.GetComponent(); if (selectable == null && raycastHit.transform.parent != null) selectable = raycastHit.transform.parent.gameObject.GetComponent(); if (selectable == null && raycastHit.transform.parent != null && raycastHit.transform.parent.parent != null) selectable = raycastHit.transform.parent.parent.gameObject.GetComponent(); 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(); 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; } } } }