123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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
- {
- /// <summary>
- /// Trigger for an ISelectableOnject. This component needs to be placed with a collider component.
- /// </summary>
- 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<Outlinable>();
- if(outlinable == null) outlinable = GetComponentInParent<Outlinable>();
- if(outlinable == null) outlinable = GetComponentInChildren<Outlinable>();
- 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<ISelectableObject>();
- if(selectableObject == null) gameObject.transform.parent.GetComponentInChildren<ISelectableObject>();
- }
- 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;
- }
- }
- }
|