2025-02-12 08:43:33 +08:00

49 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/********************************************************************************
*Create By CG
*Function RaycastTarget管理(此处如果完全用不到交互可以将GraphicRaycaster脚本去掉)
*********************************************************************************/
namespace ZXK.UTility
{
public class RaycastTargetManager : MonoBehaviour
{
void OnDrawGizmos()
{
Vector3[] s_fourCorners = new Vector3[4];
foreach (MaskableGraphic g in GameObject.FindObjectsOfType<MaskableGraphic>())
{
if (g.raycastTarget)
{
RectTransform rectTransform = g.transform as RectTransform;
rectTransform.GetWorldCorners(s_fourCorners);
Gizmos.color = Color.red;
for (int i = 0; i < 4; i++)
Gizmos.DrawLine(s_fourCorners[i], s_fourCorners[(i + 1) % 4]);
}
}
}
[ContextMenu("关闭所有射线接收")]
public void RaycastTargetAllCallOff()
{
foreach (MaskableGraphic g in GameObject.FindObjectsOfType<MaskableGraphic>())
{
g.raycastTarget = false;
}
}
[ContextMenu("打开所有射线接收")]
public void RaycastTargetAllCallOn()
{
foreach (MaskableGraphic g in GameObject.FindObjectsOfType<MaskableGraphic>())
{
g.raycastTarget = true;
}
}
}
}
#endif