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);
}
}
}
UIUseImgWindow的更多相关文章
随机推荐
- mongodb 批量修改
db.getCollection(').find({}).forEach( function(item) { item.date = item.date.replace("2018-11-2 ...
- jenkins2
创建工程 Eclipse创建工程:注意工程的路径,不是/home/svn,这个是svn的根目录. 是工程上传的路径,Apple直接下面有pom文件. 创建工程,创建一个任务就是创建一个工程. 需要注意 ...
- WTL CHyperLink类的使用(超链接)
1.包含atlctrlx.h头文件: 2.声明一个CHyperLink类的变量: CHyperLink m_linkIntro; 3.在OnInitDialog函数里: m_linkIn ...
- Aria2 使用手札(简易部署 + 快速进阶)
没错,又是受够了迅雷.旋风的各种奇葩减速(哥哥我还买了了VIP!),IDM 对协议支持又太少还有事没事提示你不是正版三天两头闹着要更新.于是我想起来之前看到过的 Aria2,虽然之前也只是略有耳闻,但 ...
- php 数字变汉字
//数字变汉字 function getTheWord($num) { $arr_n = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九', ...
- Golang两种执行流程以及区别
Go语言的执行方式有两种,一种是编译后再执行,另一种直接go run执行. 一.先编译后执行 .go文件(源代码)--->go build指令把源代码编译(如果是windows下会编译出一个.e ...
- js通过 URL下载文件
页面上一个button,点击之后触发一个function去请求数据,返回 pdf/epub 的URL,然后下载这个文件. 本来是直接用 a 写的,href里放资源地址,target设为'_blank' ...
- bzoj 1818 [CQOI 2010] 内部白点 - 扫描线 - 树状数组
题目传送门 快速的列车 慢速的列车 题目大意 一个无限大的方格图内有$n$个黑点.问有多少个位置上下左右至少有一个黑点或本来是黑点. 扫描线是显然的. 考虑一下横着的线段,取它两个端点,横坐标小的地方 ...
- 使用TortoiseGit从GitHub下拉上传代码配置
转载:http://baijiahao.baidu.com/s?id=1579466751803515477&wfr=spider&for=pc 转载:https://blog.csd ...
- Spring 学习——Spring IOC概念
Spring IOC 接口及面向接口编程 接口 定义及理解:接口是一个类的抽象声明,用于由内部操作分离出外部沟通的方式,使其内部进行修改而不影响其外部连接沟通的一种交互方式.不对外公开逻辑处理,只是返 ...