using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using EPOOutline; using KairoEngine.GameTools.InteractionTools; using KairoEngine.UI; namespace KairoEngine.GameTools.Selectables { /// /// Trigger for an ISelectableOnject. This component needs to be placed with a collider component. /// public class SelectableObjectTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { private InteractionToolsManager toolsManager; public Outlinable outlinable; public ISelectableObject selectableObject; public bool isSelected = false; private void Start() { toolsManager = InteractionToolsManager.instance; if(outlinable == null) outlinable = GetComponent(); if(outlinable == null) outlinable = GetComponentInParent(); if(outlinable == null) outlinable = GetComponentInChildren(); if(outlinable == null) Debug.LogError($"Could not find Outlinable component in {gameObject.name} hierarchy", this.gameObject); if(outlinable != null) outlinable.enabled = false; if(selectableObject == null) gameObject.transform.parent.GetComponent(); if(selectableObject == null) gameObject.transform.parent.GetComponentInChildren(); } public void Select() { if(MouseInputUIBlocker.BlockedByUI) return; isSelected = true; ShowOutline(); } public void Deselect() { isSelected = false; HideOutline(); } public void OnPointerEnter(PointerEventData eventData) => ShowOutline(); public void OnPointerExit(PointerEventData eventData) => HideOutline(); public void OnMouseEnter() => ShowOutline(); public void OnMouseExit() => HideOutline(); private void ShowOutline() { bool hasTool = toolsManager.currentTools == 0 || toolsManager.currentTools == 2; if(hasTool && !MouseInputUIBlocker.BlockedByUI) { outlinable.enabled = true; if(toolsManager.currentTools == 2) { outlinable.OutlineParameters.Color = Color.red; } else { outlinable.OutlineParameters.Color = Color.white; } } } private void HideOutline() { if(!isSelected) outlinable.enabled = false; } } }