UIUseImgWindow

using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;

namespace Daemo
{
class UIUseImgWindow : EditorWindow
{
[MenuItem("Tools/UI RES/UI Use Images %#Q")]
private static void ShowWindow()
{
UIUseImgWindow cw = (UIUseImgWindow)EditorWindow.GetWindow(typeof(UIUseImgWindow));
cw.minSize = new Vector2(500, 300);
cw.title = "UIUseImg";
}
public int showType = 0;
public void Awake()
{
this.UpdateMsg();
}

private void UpdateMsg()
{
uiUseImages.Clear();
useImageMsg = string.Empty;
UnityEngine.Object[] ps = GetSelectedPrefabs();
for (int i = 0; i < ps.Length; i++)
{
if (i == 0)
{
useImageMsg += "选中Prefabs:";
}
useImageMsg += (ps[i] as GameObject).name + ",";
Image[] images = (ps[i] as GameObject).GetComponentsInChildren<Image>(true);
for (int j = 0; j < images.Length; j++)
{
if (images[j].sprite != null)
{
Texture2D tt = images[j].sprite.texture;
if (tt != null)
{
if (uiUseImages.IndexOf(tt) < 0)
{
uiUseImages.Add(tt);
}
}
}
}

}
if (uiUseImages.Count > 0) {
useImageMsg = useImageMsg.Substring(0, useImageMsg.Length - 1);
useImageMsg += "使用图片数量" + uiUseImages.Count;
}
}
public void UpdateSceneMsg() {
uiUseImages.Clear();
useImageMsg = string.Empty;
UnityEngine.Object[] ps = UnityEditor.Selection.gameObjects;
for (int i = 0; i < ps.Length; i++)
{
if (i == 0)
{
useImageMsg += "选中Prefabs:";
}
useImageMsg += (ps[i] as GameObject).name + ",";
Image[] images = (ps[i] as GameObject).GetComponentsInChildren<Image>(true);
for (int j = 0; j < images.Length; j++)
{
if (images[j].sprite != null)
{
Texture2D tt = images[j].sprite.texture;
if (tt != null)
{
if (uiUseImages.IndexOf(tt) < 0)
{
uiUseImages.Add(tt);
}
}
}
}

}
if (uiUseImages.Count > 0)
{
useImageMsg = useImageMsg.Substring(0, useImageMsg.Length - 1);
useImageMsg += "使用图片数量" + uiUseImages.Count;
}

}
private List<Texture2D> uiUseImages = new List<Texture2D>();
private Vector2 scrollPos ;
private Texture2D img = null;
private string useImageMsg = string.Empty;
private void OnGUI()
{
GUILayout.Space(10);
if (GUILayout.Button("更新"))
{
this.UpdateMsg();
}
GUILayout.Space(10);
if (GUILayout.Button("更新ACTIVE"))
{
this.UpdateSceneMsg();
}
GUILayout.Space(10);
GUILayout.Label("功能说明:展示选中UI Prefab组所有使用过的Img");
GUILayout.Space(10);
GUILayout.Label("使用说明:选中需要检查的UI Prefab组点击更新即可。");
GUILayout.Space(10);
GUILayout.Label(useImageMsg);
GUILayout.Space(10);
EditorGUILayout.BeginHorizontal();
scrollPos =
EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(300), GUILayout.Height(400));
for (int i = 0; i < uiUseImages.Count; i++)
{
img = uiUseImages[i];
img = (Texture2D)EditorGUILayout.ObjectField(img, typeof(Texture2D), false, GUILayout.MinWidth(200f));
}
EditorGUILayout.EndScrollView();

EditorGUILayout.EndHorizontal();

}
private UnityEngine.Object[] GetSelectedPrefabs()
{
return Selection.GetFiltered(typeof(GameObject), SelectionMode.DeepAssets);
}
}

}

上一篇:[转]这13个开源GIS软件,你了解几个?


下一篇:ibatis 中 $与#的区别