123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using KairoEngine.Core;
- namespace KairoEngine.UI
- {
- [RequireComponent(typeof(EventTrigger))]
- public class MouseInputUIBlocker : MonoBehaviour
- {
- public static bool BlockedByUI;
- private EventTrigger eventTrigger;
- private void Start()
- {
- eventTrigger = GetComponent<EventTrigger>();
- if (eventTrigger != null)
- {
- EventTrigger.Entry enterUIEntry = new EventTrigger.Entry();
- // Pointer Enter
- enterUIEntry.eventID = EventTriggerType.PointerEnter;
- enterUIEntry.callback.AddListener((eventData) => { EnterUI(); });
- eventTrigger.triggers.Add(enterUIEntry);
- //Pointer Exit
- EventTrigger.Entry exitUIEntry = new EventTrigger.Entry();
- exitUIEntry.eventID = EventTriggerType.PointerExit;
- exitUIEntry.callback.AddListener((eventData) => { ExitUI(); });
- eventTrigger.triggers.Add(exitUIEntry);
- }
- EventManager.request.Bind("IsPointerBlockedByUI", IsBlockedByUI);
- }
- private void OnDisable()
- {
- BlockedByUI = false;
- }
- public void EnterUI()
- {
- BlockedByUI = true;
- }
- public void ExitUI()
- {
- BlockedByUI = false;
- }
- public bool IsBlockedByUI() => BlockedByUI;
- }
- }
|