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);
}
}

}

UIUseImgWindow的更多相关文章

随机推荐

  1. websocket 群聊单聊

    websocket 介绍 介绍引自 https://segmentfault.com/a/1190000012709475 群聊 from flask import Flask, request, r ...

  2. LCA 最近公共祖先 (模板)

    #include <iostream> #include <stdio.h> #include <cstring> #include <vector> ...

  3. 发布webservice服务

    1,定义一个接口 public interface HaiService { //定义一个方法 String speak(String str); } 2,编写一个实现类 import javax.j ...

  4. Kattis之旅——Prime Path

    The ministers of the cabinet were quite upset by the message from the Chief of Security stating that ...

  5. 纯CSS打造萌萌哒大白

    HTML部分: <body> <div id="baymax"> <!-- 定义头部,包括两个眼睛.嘴 --> <div id=" ...

  6. TCP之 TIME_WAIT和CLOSE_WAIT 状态 的原因分析和处理

    转自:http://blog.csdn.net/shootyou/article/details/6622226 昨天解决了一个HttpClient调用错误导致的服务器异常,具体过程如下: http: ...

  7. ORA-00600: internal error code, arguments: [13030], [20]一例解决

    两年没有接触oracle了,中午,一环境update from的时候出现ORA-00600: internal error code, arguments: [13030], [20]异常,经查,官网 ...

  8. 20145208 蔡野 《网络对抗》Exp6 信息搜集与漏洞扫描

    20145208 蔡野 <网络对抗>Exp6 信息搜集与漏洞扫描 本实践的目标是掌握信息搜集的最基础技能.具体有(1)各种搜索技巧的应用(2)DNS IP注册信息的查询 (3)基本的扫描技 ...

  9. vc++读取文件属性的详细信息描述 通过读取QQ的注册表和EXE路径两种方式

    转载:http://www.cnblogs.com/pythonschool/archive/2012/10/18/2729872.html // File: GetFileVersion.cpp / ...

  10. PID算法控制简单理解

    1 传统的位式控制算法 用户期望值Sv(设定值)经控制算法输出一个输出信号OUT,输出信号加载到执行部件上(像MOS管等)对控制对象进行控制(步进电机.加热器等),控制对象的当前值(Pv)如速度通过传 ...