ImgQuoteUIWindow
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
namespace Daemo
{
class ImgQuoteUIWindow : EditorWindow
{
[MenuItem("Tools/UI RES/Img Quote UI %#E")]
private static void ShowWindow()
{
ImgQuoteUIWindow cw = (ImgQuoteUIWindow)EditorWindow.GetWindow(typeof(ImgQuoteUIWindow));
cw.minSize = new Vector2(800, 700);
cw.title = "ImgQuoteUI";
}
public int showType = 0;
private List<GameObject> allPrefabs = new List<GameObject>();
private Dictionary<GameObject, List<Texture2D>> allPrefabsTexture2Ds = new Dictionary<GameObject, List<Texture2D>>();
public void Awake()
{
this.UpdateAllPrefabs();
this.UpdateMsg();
}
private void UpdateAllPrefabs() {
this.allPrefabs = EDCheckPrefabRef.GetAllUIPrefabs();
this.allPrefabsTexture2Ds.Clear();
for (int i = 0; i < this.allPrefabs.Count; i++) {
GameObject nowObj = this.allPrefabs[i];
Image[] imgs = nowObj.GetComponentsInChildren<Image>(true);
List<Texture2D> textures = new List<Texture2D>();
for (int j = 0; j < imgs.Length; j++) {
Image img = imgs[j];
if(img.sprite !=null && img.sprite.texture != null)
{
textures.Add(img.sprite.texture);
}
}
this.allPrefabsTexture2Ds[nowObj] = textures;
}
}
private void UpdateMsg()
{
imgQuoteUI.Clear();
noQuoteImg.Clear();
useImageMsg = string.Empty;
UnityEngine.Object[] ps = GetSelectedPrefabs();
for (int i = 0; i < ps.Length; i++)
{
if (i == 0)
{
useImageMsg += "选中Imgs:";
}
Texture2D img = ps[i] as Texture2D;
if (i < ps.Length - 1)
{
useImageMsg += img.name + ",";
}
else {
useImageMsg += img.name;
}
bool isUse = false;
foreach (GameObject key in this.allPrefabsTexture2Ds.Keys) {
List<Texture2D> cValue = this.allPrefabsTexture2Ds[key];
for (int j = 0; j < cValue.Count; j++) {
if (img.name == cValue[j].name) {
List<GameObject> imgQuoteUI_UIs = null;
if (imgQuoteUI.ContainsKey(img))
{
imgQuoteUI_UIs = imgQuoteUI[img];
}
else {
imgQuoteUI_UIs = new List<GameObject>();
imgQuoteUI[img] = imgQuoteUI_UIs;
}
imgQuoteUI_UIs.Add(key);
if (!isUse) {
isUse = true;
}
break;
}
}
}
if (!isUse)
{
noQuoteImg.Add(img);
}
}
}
private Dictionary<Texture2D,List<GameObject>> imgQuoteUI = new Dictionary<Texture2D, List<GameObject>>();
private List<Texture2D> noQuoteImg = new List<Texture2D>();
private Vector2 scrollPos ;
private Vector2 scrollPos1;
private GameObject prefabObj = null;
private Texture2D noUseImg = null;
private string useImageMsg = string.Empty;
private void OnGUI()
{
GUILayout.Space(10);
if (GUILayout.Button("更新"))
{
this.UpdateMsg();
}
GUILayout.Space(10);
GUILayout.Label("功能说明:展示选中Img组被那些UI Prefab使用");
GUILayout.Space(10);
GUILayout.Label("使用说明:选中需要检查的图片组点击更新即可。");
GUILayout.Space(10);
GUILayout.Label(useImageMsg);
GUILayout.Space(10);
EditorGUILayout.BeginHorizontal();
scrollPos =
EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(800), GUILayout.Height(400));
foreach (Texture2D key in this.imgQuoteUI.Keys) {
List<GameObject> cValue = imgQuoteUI[key];
for (int i = 0; i < cValue.Count; i++) {
EditorGUILayout.BeginHorizontal();
GUILayout.Label("("+ key.name + ")被(" + cValue[i].name + ")引用:");
prefabObj = cValue[i];
prefabObj = (GameObject)EditorGUILayout.ObjectField(prefabObj, typeof(GameObject), false, GUILayout.MinWidth(200f));
EditorGUILayout.EndHorizontal();
}
}
EditorGUILayout.EndScrollView();
EditorGUILayout.EndHorizontal();
if (this.noQuoteImg.Count > 0) {
GUILayout.Space(10);
GUILayout.Label("未被UI使用图片组:"+ noQuoteImg.Count);
scrollPos1 =
EditorGUILayout.BeginScrollView(scrollPos1, GUILayout.Width(800), GUILayout.Height(200));
for (int i = 0; i < noQuoteImg.Count; i++)
{
EditorGUILayout.BeginHorizontal();
noUseImg = noQuoteImg[i];
noUseImg = (Texture2D)EditorGUILayout.ObjectField(noUseImg, typeof(Texture2D), false, GUILayout.MinWidth(200f));
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
}
}
private UnityEngine.Object[] GetSelectedPrefabs()
{
return Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
}
}
}
ImgQuoteUIWindow的更多相关文章
随机推荐
- 51Nod 1212 无向图最小生成树 (路径压缩)
N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树. Input 第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量.(2 <= N <= 1000, 1 &l ...
- mysql数据库介绍
一.数据库概述 二.MySql安装和基本管理 三.mysql基本语句 四.库的操作 五.表的操作 六.数据类型 七.数据类型二 八.完整性约束 九.外键的变种 三种关系 十.数据的增删改 十一.多表查 ...
- 关于Android Camera2 API 的自动对焦的坑
https://www.jianshu.com/p/280e5301b7b9 一.使用.关于Camera2的API使用,参考Google官方的例子: Camera2Basic Camera2Raw C ...
- 四轴飞行器1.7 NRF24L01P无线通讯和改进型环形缓冲(转)
源: 四轴飞行器1.7 NRF24L01P无线通讯和改进型环形缓冲
- NGINX转发代理情况下,获取客户单真实IP
编译时加上http_realip_module 模块 realip模块生效的前提是:直接连接nginx的ip是在set_real_ip_from中指定的. 原机配置: set_real_ip_from ...
- git小技巧--如何从其他分支merge个别文件或文件夹
在实际工作中,一个大型的项目或版本迭代可能不是一次上线,可能会分好几次上线,这时候就会涉及创建多个分支,进行分别开发. 创建分支 功能分为2个分支,分别为A.B. A上面有个列表页功能 B上面有个详情 ...
- python的os模块中的os.walk()函数
os.walk('path')函数对于每个目录返回一个三元组,(dirpath, dirnames, filenames), 第一个是路径,第二个是路径下面的目录,第三个是路径下面的文件 如果加参数t ...
- Centos7.3+uwsgi+Nginx部署Django程序
1. 安装Python,这里我用的是阿里云的centos7.3,自带python2,所以,此步略过,具体安装Python可Google. 2. 安装uwsgi,如果安装失败的话首先,我的Python解 ...
- tp5 中使用自定义扩展类和函数
如果是要引用其它控制器里定义的方法参考:https://www.cnblogs.com/efyefy/p/8796014.html 如果在extend定义的类和函数默认是在全局命名空间下的 new \ ...
- Codeforces Round #466 (Div. 2) Solution
从这里开始 题目列表 小结 Problem A Points on the line Problem B Our Tanya is Crying Out Loud Problem C Phone Nu ...