12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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(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;
- }
- }
- }
|