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的更多相关文章
随机推荐
- js相关(easyUI),触发器,ant,jbpm,hibernate二级缓存ehcache,Javamail,Lucene,jqplot,WebService,regex,struts2,oracle表空间
*********************************************js相关********************************************* // 在指 ...
- httpclient get post
https://www.cnblogs.com/wutongin/p/7778996.html post请求方法和get请求方法 package com.xkeshi.paymentweb.contr ...
- .NET 常用ORM之iBatis
ibatis 一词来源于“internet”和“abatis”的组合,是一个由Clinton Begin在2001年发起的开放源代码项目,到后面发展的版本叫MyBatis但都是指的同一个东西.最初侧重 ...
- (2018干货系列四)最新Python学习路线整合
怎么学Python Python是一种面向对象的解释型计算机程序设计语言,纯粹的自由软件,常被昵称为胶水语言,能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起. Python初级开 ...
- 介绍python中运算符优先级
下面这个表给出Python的运算符优先级,从最低的优先级(最松散地结合)到最高的优先级(最紧密地结合).这意味着在一个表达式中,Python会首先计算表中较下面的运算符,然后在计算列在表上部的运算符. ...
- JQuery ajax请求返回(parsererror)异常处理
目前在学习一个Java应用的框架,反编译后在执行时一直报错,界面上显示”parsererror”,经过JavaScript调试后发现更详细的错误提示信息是 Unexpected token ' in ...
- Maven笔记 #01# 入门
索引 Maven是干什么的? 用Maven的好处 Maven与命令行 Maven与IntelliJ IDEA 一.Maven是干什么的? 我相信只要你写过足够多的代码,就... 肯定有思考过写一个脚本 ...
- EDK II之USB主控制器(EHCI)驱动的实现框架
本文简要介绍一下UEFI中EHCI驱动的代码实现框架: 下图是HCDI: 上图是Host驱动程序向上层驱动提供的接口图: 1.大部分接口的最后动作都是去操作主控制器寄存器,ECHI的spec:< ...
- Java axis2.jar包详解及缺少jar包错误分析
Java axis2.jar包详解及缺少jar包错误分析 一.最小开发jar集 axis2 开发最小jar包集: activation-1.1.jar axiom-api-1.2.13.jar ax ...
- 01:saltstack 基本使用
1.1 准备实验环境: 安装系统 1)硬件配置如下 2) 先把光标放到”install CentOS 7”,按 Tab键编辑内核参数,添加 (net.ifnames=0 biosdevname=0) ...