1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 using UnityEngine.UI; 5 6 public class RaycastTargetGizmos : MonoBehaviour 7 { 8 #if UNITY_EDITOR 9 static Vector3[] fourCorners = new Vector3[4]; 10 void OnDrawGizmos() 11 { 12 foreach (MaskableGraphic g in GameObject.FindObjectsOfType<MaskableGraphic>()) 13 { 14 if (g.raycastTarget) 15 { 16 RectTransform rectTransform = g.transform as RectTransform; 17 rectTransform.GetWorldCorners(fourCorners); 18 Gizmos.color = Color.blue; 19 for (int i = 0; i < 4; i++) 20 Gizmos.DrawLine(fourCorners[i], fourCorners[(i + 1) % 4]); 21 22 } 23 } 24 } 25 #endif 26 }
使用方法,在场景中随意一个对象加上这个脚本,然后使用Gizmos开关这个脚本即可