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的更多相关文章
随机推荐
- SSMS登记密码清除
如图,此界面的登录密码如果要清除,可以找到%AppData%\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin,将SqlStud ...
- Service_name 和Sid的区别
Service_name:该参数是由oracle8i引进的.在8i以前,使用SID来表示标识数据库的一个实例,但是在Oracle的并行环境中,一个数据库对应多个实例,这样就需要多个网络服务名,设置繁琐 ...
- 【Selenium专题】元素定位之CssSelector
CssSelector是我最喜欢的元素定位方法,Selenium官网的Document里极力推荐使用CSS locator,而不是XPath来定位元素,原因是CSS locator比XPath loc ...
- v-text v-html等指令的使用
v-text:以纯文本方式显示数据: v-html:可以识别HTML标签: v-once:只渲染元素或组件一次: v-pre:不进行编译,直接显示内容: v-cloak:可以隐藏未编译的 Mustac ...
- fjwc2019 D3T2 送分题
#185. 「2019冬令营提高组」送分题 这是原题..... P3615 如厕计划 手推一推你发现,显然男性不能多于女性. 然后你或许可以发现一个神奇的性质. 对于每个序列,我们记$M$为$1$,$ ...
- bzoj4698 / P2463 [SDOI2008]Sandy的卡片
P2463 [SDOI2008]Sandy的卡片 直接二分长度暴力匹配....... 跑的还挺快 (正解是后缀数组的样子) #include<iostream> #include<c ...
- 运行android模拟器,emulator: ERROR: x86 emulation currently requires hardware acceleration!
运行android模拟器,emulator: ERROR: x86 emulation currently requires hardware acceleration! 问题: 运行android模 ...
- go 字符串反转(倒序)
似乎没什么好办法,string的话也得需要先转换成rune再反转再转成string package main import ( "fmt" ) func reverseString ...
- springboot 项目pom.xml文件基本配置
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven ...
- mysql 用存储过程插入11位 随机数
BEGIN #Routine body goes here... ; ); ); ); ); ); ); ); ); ); ); ); ); ) DEFAULT ''; ); ); WHILE row ...