MouseInputUIBlocker.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using KairoEngine.Core;
  6. namespace KairoEngine.UI
  7. {
  8. [RequireComponent(typeof(EventTrigger))]
  9. public class MouseInputUIBlocker : MonoBehaviour
  10. {
  11. public static bool BlockedByUI;
  12. private EventTrigger eventTrigger;
  13. private void Start()
  14. {
  15. eventTrigger = GetComponent<EventTrigger>();
  16. if (eventTrigger != null)
  17. {
  18. EventTrigger.Entry enterUIEntry = new EventTrigger.Entry();
  19. // Pointer Enter
  20. enterUIEntry.eventID = EventTriggerType.PointerEnter;
  21. enterUIEntry.callback.AddListener((eventData) => { EnterUI(); });
  22. eventTrigger.triggers.Add(enterUIEntry);
  23. //Pointer Exit
  24. EventTrigger.Entry exitUIEntry = new EventTrigger.Entry();
  25. exitUIEntry.eventID = EventTriggerType.PointerExit;
  26. exitUIEntry.callback.AddListener((eventData) => { ExitUI(); });
  27. eventTrigger.triggers.Add(exitUIEntry);
  28. }
  29. EventManager.request.Bind("IsPointerBlockedByUI", IsBlockedByUI);
  30. }
  31. private void OnDisable()
  32. {
  33. BlockedByUI = false;
  34. }
  35. public void EnterUI()
  36. {
  37. BlockedByUI = true;
  38. }
  39. public void ExitUI()
  40. {
  41. BlockedByUI = false;
  42. }
  43. public bool IsBlockedByUI() => BlockedByUI;
  44. }
  45. }