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的更多相关文章

随机推荐

  1. 一个Java系统测试

    实验感受: 本次实验最大的感受,就是不要改代码,自己写,代码改起来真的没完没了,不知道会出现什么问题.还有就是一定要清楚自己要怎么去写,流程很重要,一个个功能去实现. 主界面 数据库 主页面代码 &l ...

  2. Python学习路线人工智能线性代数知识点汇总

    人工智能和数据分析相关的线性代数知识.比如什么是矢量,什么是矩阵,矩阵的加减乘除.矩阵对角化,三角化,秩,QR法,最小二法.等等 矢量: 高中数学中都学过复数,负数表达式是: a+bi 复数实际上和二 ...

  3. Django框架----ORM数据库操作注意事项

    1.多对多的正向查询 class Class(models.Model): name = models.CharField(max_length=32,verbose_name="班级名&q ...

  4. The Little Prince-11/28

    The Little Prince-11/28 Today I find some beautiful words from the book. You know -- one loves the s ...

  5. mxnet设置动态学习率(learning rate)

    https://blog.csdn.net/xiaotao_1/article/details/78874336 如果learning rate很大,算法会在局部最优点附近来回跳动,不会收敛: 如果l ...

  6. 余额表前后台操作和对应sql

    发生额的含义:产生于账行表. gl_je_lines账行表——>借贷(会产生额度,即发生额) —————————————————————————— gl_balances余额表: 余额   =  ...

  7. Eloquent JavaScript #12# Handling Events

    索引 Notes onclick removeEventListener Event objects stopPropagation event.target Default actions Key ...

  8. Java笔记 #03# HtmlUnit爬虫

    存档留用 (= 存档留着备用) 爬的是一个开放的自动回复机器人 API 网站 http://i.itpk.cn/. 结构 大致如下: 我做的事情就是[输入文字,点击按钮,爬取内容],如上图所示. pa ...

  9. SQL介绍

    SQL,即structured query language,结构化查询语言,是一种对关系型数据库中的数据进行管理和操作的语言方法,SQL包括6个部分 DQL:数据查询语言,最常用的为select,其 ...

  10. 获取RadioButton选中的值

    1.RadioButtonList的RepeatDirection="Horizontal"可以设置按扭选项横对齐: 2.获取选中的RadioButton值; $("#& ...