118 lines
4.1 KiB
C#
118 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using UnityEditor.Experimental.SceneManagement;
|
|
|
|
namespace BFEditor.Resource
|
|
{
|
|
public class CheckRaycastTargetWindow : EditorWindow
|
|
{
|
|
ShowRaycast raycastHelper;
|
|
RectTransform rt;
|
|
Vector2 scrollPos;
|
|
|
|
CheckRaycastTargetWindow()
|
|
{
|
|
this.titleContent = new GUIContent("检查RaycastTarget");
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
PrefabStage currentPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
|
Transform tran;
|
|
if (currentPrefabStage == null)
|
|
tran = Selection.activeTransform;
|
|
else
|
|
tran = currentPrefabStage.prefabContentsRoot.transform;
|
|
if (tran != null)
|
|
rt = tran.GetComponent<RectTransform>();
|
|
if (rt != null)
|
|
{
|
|
raycastHelper = rt.GetComponent<ShowRaycast>();
|
|
if (raycastHelper == null)
|
|
raycastHelper = rt.gameObject.AddComponent<ShowRaycast>();
|
|
raycastHelper.SetEditorWindowMode(true);
|
|
}
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
GUILayout.BeginVertical();
|
|
EditorGUI.BeginChangeCheck();
|
|
rt = (RectTransform)EditorGUILayout.ObjectField("", rt, typeof(RectTransform), true, GUILayout.Width(200));
|
|
GUILayout.Space(6);
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
if (raycastHelper != null)
|
|
DestroyImmediate(raycastHelper);
|
|
if (rt != null)
|
|
{
|
|
raycastHelper = rt.GetComponent<ShowRaycast>();
|
|
if (raycastHelper == null)
|
|
raycastHelper = rt.gameObject.AddComponent<ShowRaycast>();
|
|
raycastHelper.SetEditorWindowMode(true);
|
|
}
|
|
}
|
|
if (raycastHelper != null)
|
|
{
|
|
GUILayout.Label(string.Format("raycastTarget组件一共有 {0} 个", raycastHelper.GetTotalCount()));
|
|
GUILayout.Label("(红色)image " + raycastHelper.GetImageCount() +
|
|
" (绿色)text " + raycastHelper.GetTextCount());
|
|
GUILayout.Label("(黄色)emptyRaycast " + raycastHelper.GetEmptyCount() +
|
|
" (蓝色)rawImage " + raycastHelper.GetRawImageCount());
|
|
GUILayout.Space(6);
|
|
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(400), GUILayout.Height(270));
|
|
List<string> pathList = raycastHelper.GetImagePathList();
|
|
int i = 0;
|
|
if (pathList.Count > 0)
|
|
{
|
|
GUILayout.Label("image路径:");
|
|
for (; i < pathList.Count; i++)
|
|
GUILayout.Label(pathList[i]);
|
|
}
|
|
pathList = raycastHelper.GetTextPathList();
|
|
i = 0;
|
|
if (pathList.Count > 0)
|
|
{
|
|
GUILayout.Label("text路径:");
|
|
for (; i < pathList.Count; i++)
|
|
GUILayout.Label(pathList[i]);
|
|
}
|
|
pathList = raycastHelper.GetEmptyPathList();
|
|
i = 0;
|
|
if (pathList.Count > 0)
|
|
{
|
|
GUILayout.Label("emptyRaycast路径:");
|
|
for (; i < pathList.Count; i++)
|
|
GUILayout.Label(pathList[i]);
|
|
}
|
|
pathList = raycastHelper.GetRawImagePathList();
|
|
i = 0;
|
|
if (pathList.Count > 0)
|
|
{
|
|
GUILayout.Label("rawImage路径:");
|
|
for (; i < pathList.Count; i++)
|
|
GUILayout.Label(pathList[i]);
|
|
}
|
|
GUILayout.EndScrollView();
|
|
}
|
|
GUILayout.EndVertical();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
if (raycastHelper != null)
|
|
DestroyImmediate(raycastHelper);
|
|
}
|
|
|
|
//[MenuItem("资源工具/资源检查/检查RaycastTarget", false, 401)]
|
|
public static void OpenWindow()
|
|
{
|
|
CheckRaycastTargetWindow window = (CheckRaycastTargetWindow)GetWindowWithRect(typeof(CheckRaycastTargetWindow),
|
|
new Rect(Screen.width / 2, Screen.height / 2, 400, 400), true);
|
|
window.Show();
|
|
}
|
|
}
|
|
}
|