Initial commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace BracerLib.Utility
|
||||
{
|
||||
[ExcludeFromCoverage]
|
||||
public static class UIUtility
|
||||
{
|
||||
private static bool performRefresh;
|
||||
private static PointerEventData eventBuffer = new PointerEventData(EventSystem.current);
|
||||
private static List<RaycastResult> raycastResultBuffer = new List<RaycastResult>(4);
|
||||
|
||||
static UIUtility()
|
||||
{
|
||||
SceneManager.activeSceneChanged += (before, after) => Refresh();
|
||||
}
|
||||
|
||||
public static bool IsMouseOverUI(Vector2 position, int uiLayer)
|
||||
{
|
||||
var eventSystem = EventSystem.current;
|
||||
eventBuffer.position = position;
|
||||
eventSystem.RaycastAll(eventBuffer, raycastResultBuffer);
|
||||
|
||||
for (var i = 0; i < raycastResultBuffer.Count; i++)
|
||||
{
|
||||
var raycastResult = raycastResultBuffer[i];
|
||||
|
||||
if (raycastResult.gameObject.layer == uiLayer)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void Refresh()
|
||||
{
|
||||
var current = EventSystem.current;
|
||||
|
||||
if (current == null)
|
||||
return;
|
||||
|
||||
eventBuffer = new PointerEventData(EventSystem.current);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user