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(isSelected) return; if(MouseInputUIBlocker.BlockedByUI) return; isSelected = true; ShowOutline(); } public void Deselect() { if(!isSelected) return; 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() { var highlightInterface = toolsManager.toolInterfaces[toolsManager.currentTools] as IHighlightableObject; bool hasTool = highlightInterface != null; if(hasTool && !MouseInputUIBlocker.BlockedByUI && highlightInterface.ShowOutline()) { outlinable.enabled = true; outlinable.OutlineParameters.Color = highlightInterface.GetHighlightColor(); } } private void HideOutline() { if(!isSelected) outlinable.enabled = false; } } }