• 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);
    }
    }

    }

  • 相关阅读:
    21.算法实战---栈
    初见Gnuplot——时间序列的描述
    MATLAB连接MySQL数据库
    用python做些有意思的事——分析QQ聊天记录——私人订制
    遇见蒙特卡洛
    层次分析模型(AHP)及其MATLAB实现
    CPP,MATLAB实现牛顿插值
    CPP&MATLAB实现拉格朗日插值法
    python3爬虫再探之豆瓣影评数据抓取
    R——启程——豆瓣影评分析
  • 原文地址:https://www.cnblogs.com/rexzhao/p/7243146.html
Copyright © 2020-2023  润新知