#if UNITY_EDITOR using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using BF; namespace BFEditor { [ExecuteInEditMode] public class ShowRaycast : MonoBehaviour { Text[] texts; Image[] images; EmptyRaycast[] emptys; RawImage[] rawImages; int imageCount; int textCount; int emptyCount; int rawImageCount; List imagePathList = new List(); List textPathList = new List(); List emptyPathList = new List(); List rawImagePathList = new List(); Vector3[] vector3s = new Vector3[4]; bool editorWindowMode = false; public void SetEditorWindowMode(bool flag) { editorWindowMode = flag; } public int GetTotalCount() { return imageCount + textCount + emptyCount + rawImageCount; } public int GetImageCount() { return imageCount; } public int GetTextCount() { return textCount; } public int GetRawImageCount() { return rawImageCount; } public int GetEmptyCount() { return emptyCount; } public List GetImagePathList() { return imagePathList; } public List GetTextPathList() { return textPathList; } public List GetEmptyPathList() { return emptyPathList; } public List GetRawImagePathList() { return rawImagePathList; } void Clear() { imageCount = 0; textCount = 0; emptyCount = 0; rawImageCount = 0; imagePathList.Clear(); textPathList.Clear(); emptyPathList.Clear(); rawImagePathList.Clear(); } void OnDrawGizmos() { if (editorWindowMode) Clear(); texts = transform.GetComponentsInChildren(true); images = transform.GetComponentsInChildren(true); emptys = transform.GetComponentsInChildren(true); rawImages = transform.GetComponentsInChildren(true); GameObject tempGo = new GameObject("temp"); RectTransform newRt = tempGo.AddComponent(); Action drawAction = (RectTransform rt, Color color) => { if (rt == null) return; rt.GetWorldCorners(vector3s); Gizmos.color = color; Gizmos.DrawLine(vector3s[0], vector3s[1]); Gizmos.DrawLine(vector3s[1], vector3s[2]); Gizmos.DrawLine(vector3s[2], vector3s[3]); Gizmos.DrawLine(vector3s[3], vector3s[0]); newRt.SetParent(rt.parent); newRt.localPosition = rt.localPosition; newRt.localRotation = rt.localRotation; newRt.localScale = rt.localScale; newRt.sizeDelta = new Vector2(rt.sizeDelta.x + 1.0f, rt.sizeDelta.y + 1.0f); newRt.GetWorldCorners(vector3s); Gizmos.DrawLine(vector3s[0], vector3s[1]); Gizmos.DrawLine(vector3s[1], vector3s[2]); Gizmos.DrawLine(vector3s[2], vector3s[3]); Gizmos.DrawLine(vector3s[3], vector3s[0]); }; int i = 0; for (; i < images.Length; i++) if (images[i].raycastTarget) { drawAction(images[i].GetComponent(), Color.red); if (editorWindowMode) { imageCount++; string path = ""; BF.Utils.GetTransformPath(images[i].transform, transform, ref path); imagePathList.Add(path); } } i = 0; for (; i < texts.Length; i++) if (texts[i].raycastTarget) { drawAction(texts[i].GetComponent(), Color.green); if (editorWindowMode) { textCount++; string path = ""; BF.Utils.GetTransformPath(texts[i].transform, transform, ref path); textPathList.Add(path); } } i = 0; for (; i < emptys.Length; i++) if (emptys[i].raycastTarget) { drawAction(emptys[i].GetComponent(), Color.yellow); if (editorWindowMode) { emptyCount++; string path = ""; BF.Utils.GetTransformPath(emptys[i].transform, transform, ref path); emptyPathList.Add(path); } } i = 0; for (; i < rawImages.Length; i++) if (rawImages[i].raycastTarget) { drawAction(rawImages[i].GetComponent(), Color.blue); if (editorWindowMode) { rawImageCount++; string path = ""; BF.Utils.GetTransformPath(rawImages[i].transform, transform, ref path); rawImagePathList.Add(path); } } DestroyImmediate(tempGo); } } } #endif