Skip to content

Commit 55716f5

Browse files
committed
一些关于Unity编辑器拓展的小测试
1 parent 18621a7 commit 55716f5

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#if UNITY_EDITOR
2+
using UnityEngine;
3+
using System.Collections;
4+
using UnityEngine.UI;
5+
public class DebugUILine : MonoBehaviour
6+
{
7+
static Vector3[] fourCorners = new Vector3[4];
8+
void OnDrawGizmos()
9+
{
10+
foreach (MaskableGraphic g in GameObject.FindObjectsOfType<MaskableGraphic>())
11+
{
12+
if (g.raycastTarget)
13+
{
14+
RectTransform rectTransform = g.transform as RectTransform;
15+
rectTransform.GetWorldCorners(fourCorners);
16+
Gizmos.color = Color.blue;
17+
for (int i = 0; i < 4; i++)
18+
Gizmos.DrawLine(fourCorners[i], fourCorners[(i + 1) % 4]);
19+
}
20+
}
21+
}
22+
}
23+
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
using UnityEditor;
4+
5+
public class MenuOptionOverwrite
6+
{
7+
8+
[MenuItem("GameObject/UI/Image")]
9+
static void CreateImage()
10+
{
11+
if (Selection.activeTransform)
12+
{
13+
if (Selection.activeTransform.GetComponentInParent<Canvas>())
14+
{
15+
GameObject go = new GameObject("image", typeof(Image));
16+
go.GetComponent<Image>().raycastTarget = false;
17+
go.transform.SetParent(Selection.activeTransform);
18+
}
19+
}
20+
}
21+
22+
[MenuItem("GameObject/UI/Text")]
23+
static void CreateText()
24+
{
25+
if (Selection.activeTransform)
26+
{
27+
if (Selection.activeTransform.GetComponentInParent<Canvas>())
28+
{
29+
GameObject go = new GameObject("text", typeof(Text));
30+
go.GetComponent<Text>().raycastTarget = false;
31+
go.transform.SetParent(Selection.activeTransform);
32+
}
33+
}
34+
}
35+
36+
}

0 commit comments

Comments
 (0)