zoukankan      html  css  js  c++  java
  • 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);
    }
    }

    }

  • 相关阅读:
    find指令使用手册
    IP封包协议头/TCP协议头/TCP3次握手/TCP4次挥手/UDP协议头/ICMP协议头/HTTP协议(请求报文和响应报文)/IP地址/子网掩码(划分子网)/路由概念/MAC封包格式
    Vmare虚拟机中的3种网络连接方式
    Windows10下Apache2.4配置Django
    网站配色
    js 图片轮播
    Window10下Apache2.4的安装和运行
    sqlite数据库转换为mysql数据库
    windows10 安装 mysql 5.6 教程
    win10 nginx + django +flup 配置
  • 原文地址:https://www.cnblogs.com/rexzhao/p/7243146.html
Copyright © 2011-2022 走看看