67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
|
|
#if UNITY_EDITOR
|
|||
|
|
using UnityEditor;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
/********************************************************************************
|
|||
|
|
*Create By CG
|
|||
|
|
*Function RaycastTarget管理(此处如果完全用不到交互,可以将GraphicRaycaster脚本去掉)
|
|||
|
|
*********************************************************************************/
|
|||
|
|
namespace CG.UTility
|
|||
|
|
{
|
|||
|
|
[CanEditMultipleObjects]
|
|||
|
|
[CustomEditor(typeof(RaycastTargetManager))]
|
|||
|
|
public class RaycastTargetManagerEditor : Editor
|
|||
|
|
{
|
|||
|
|
public override void OnInspectorGUI()
|
|||
|
|
{
|
|||
|
|
base.OnInspectorGUI();
|
|||
|
|
if (GUILayout.Button("取消场景中所有物体的Rct"))
|
|||
|
|
{
|
|||
|
|
RaycastTargetManager.RaycastTargetAllCallOff();
|
|||
|
|
}
|
|||
|
|
if (GUILayout.Button("勾选场景中所有物体的Rct"))
|
|||
|
|
{
|
|||
|
|
RaycastTargetManager.RaycastTargetAllCallOn();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
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]);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void RaycastTargetAllCallOff()
|
|||
|
|
{
|
|||
|
|
foreach (MaskableGraphic g in GameObject.FindObjectsOfType<MaskableGraphic>())
|
|||
|
|
{
|
|||
|
|
g.raycastTarget = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void RaycastTargetAllCallOn()
|
|||
|
|
{
|
|||
|
|
foreach (MaskableGraphic g in GameObject.FindObjectsOfType<MaskableGraphic>())
|
|||
|
|
{
|
|||
|
|
g.raycastTarget = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
|