• UIUseImgWindow


    using System;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEditor;
    using System.Collections;
    using System.Collections.Generic;

    namespace Daemo
    {
    class UIUseImgWindow : EditorWindow
    {
    [MenuItem("Tools/UI RES/UI Use Images %#Q")]
    private static void ShowWindow()
    {
    UIUseImgWindow cw = (UIUseImgWindow)EditorWindow.GetWindow(typeof(UIUseImgWindow));
    cw.minSize = new Vector2(500, 300);
    cw.title = "UIUseImg";
    }
    public int showType = 0;
    public void Awake()
    {
    this.UpdateMsg();
    }

    private void UpdateMsg()
    {
    uiUseImages.Clear();
    useImageMsg = string.Empty;
    UnityEngine.Object[] ps = GetSelectedPrefabs();
    for (int i = 0; i < ps.Length; i++)
    {
    if (i == 0)
    {
    useImageMsg += "选中Prefabs:";
    }
    useImageMsg += (ps[i] as GameObject).name + ",";
    Image[] images = (ps[i] as GameObject).GetComponentsInChildren<Image>(true);
    for (int j = 0; j < images.Length; j++)
    {
    if (images[j].sprite != null)
    {
    Texture2D tt = images[j].sprite.texture;
    if (tt != null)
    {
    if (uiUseImages.IndexOf(tt) < 0)
    {
    uiUseImages.Add(tt);
    }
    }
    }
    }

    }
    if (uiUseImages.Count > 0) {
    useImageMsg = useImageMsg.Substring(0, useImageMsg.Length - 1);
    useImageMsg += "使用图片数量" + uiUseImages.Count;
    }
    }
    public void UpdateSceneMsg() {
    uiUseImages.Clear();
    useImageMsg = string.Empty;
    UnityEngine.Object[] ps = UnityEditor.Selection.gameObjects;
    for (int i = 0; i < ps.Length; i++)
    {
    if (i == 0)
    {
    useImageMsg += "选中Prefabs:";
    }
    useImageMsg += (ps[i] as GameObject).name + ",";
    Image[] images = (ps[i] as GameObject).GetComponentsInChildren<Image>(true);
    for (int j = 0; j < images.Length; j++)
    {
    if (images[j].sprite != null)
    {
    Texture2D tt = images[j].sprite.texture;
    if (tt != null)
    {
    if (uiUseImages.IndexOf(tt) < 0)
    {
    uiUseImages.Add(tt);
    }
    }
    }
    }

    }
    if (uiUseImages.Count > 0)
    {
    useImageMsg = useImageMsg.Substring(0, useImageMsg.Length - 1);
    useImageMsg += "使用图片数量" + uiUseImages.Count;
    }

    }
    private List<Texture2D> uiUseImages = new List<Texture2D>();
    private Vector2 scrollPos ;
    private Texture2D img = null;
    private string useImageMsg = string.Empty;
    private void OnGUI()
    {
    GUILayout.Space(10);
    if (GUILayout.Button("更新"))
    {
    this.UpdateMsg();
    }
    GUILayout.Space(10);
    if (GUILayout.Button("更新ACTIVE"))
    {
    this.UpdateSceneMsg();
    }
    GUILayout.Space(10);
    GUILayout.Label("功能说明:展示选中UI Prefab组所有使用过的Img");
    GUILayout.Space(10);
    GUILayout.Label("使用说明:选中需要检查的UI Prefab组点击更新即可。");
    GUILayout.Space(10);
    GUILayout.Label(useImageMsg);
    GUILayout.Space(10);
    EditorGUILayout.BeginHorizontal();
    scrollPos =
    EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(300), GUILayout.Height(400));
    for (int i = 0; i < uiUseImages.Count; i++)
    {
    img = uiUseImages[i];
    img = (Texture2D)EditorGUILayout.ObjectField(img, typeof(Texture2D), false, GUILayout.MinWidth(200f));
    }
    EditorGUILayout.EndScrollView();

    EditorGUILayout.EndHorizontal();

    }
    private UnityEngine.Object[] GetSelectedPrefabs()
    {
    return Selection.GetFiltered(typeof(GameObject), SelectionMode.DeepAssets);
    }
    }

    }

  • 相关阅读:
    laravel 使用 php artisan make:model到指定目录(controller同理)
    Mysql常见的优化策略
    laravel路由别名
    laravel whereNotIn where子查詢
    phpstorm界面不停的indexing,不停的闪烁
    Linux下Redis开机自启(Centos6)
    数据结构常用算法
    困惑的前置操作与后置操作
    SSH框架整合中Hibernate实现Dao层常用结构
    过滤器与拦截器区别
  • 原文地址:https://www.cnblogs.com/rexzhao/p/7243153.html
Copyright © 2020-2023  润新知