Files
MVP1/Assets/Scripts/Modules/Core.Unity/UIBlocker.cs
T

25 lines
977 B
C#
Raw Normal View History

using UnityEngine;
using UnityEngine.EventSystems;
// Проверка "палец/мышь сейчас над UI?".
// Нужна, чтобы клик по кнопке панели НЕ проходил насквозь в мир:
// не собирал ресурсы со здания под панелью, не улучшал Ратушу, не двигал камеру.
public static class UIBlocker
{
public static bool IsPointerOverUI()
{
if (EventSystem.current == null) return false;
// мышь (редактор/ПК) и новый Input System
if (EventSystem.current.IsPointerOverGameObject()) return true;
// тач на телефоне (старый input module требует id пальца)
for (int i = 0; i < Input.touchCount; i++)
{
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(i).fingerId))
return true;
}
return false;
}
}