ImgNoGoodWindow
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace Daemo
{
class ImgNoGoodWindow : EditorWindow
{
[MenuItem("Tools/UI RES/Assets Img No Good %#W")]
private static void ShowWindow()
{
ImgNoGoodWindow cw = (ImgNoGoodWindow)EditorWindow.GetWindow(typeof(ImgNoGoodWindow));
cw.minSize = new Vector2(500, 500);
}
private List<Texture2D> noGoodImages = new List<Texture2D>();
private List<Texture2D> goodImages = new List<Texture2D>();
private List<Texture2D> packImages = new List<Texture2D>();
private Vector2 scrollPos;
private Texture2D img = null;
private string[] btns = new string[] { "不规范图片组", "规范图片组","Pack图片组" };
private int selectIndex = 0;
public void Awake()
{
this.UpdateMsg();
}
private void UpdateMsg()
{
noGoodImages = EDCheckPrefabRef.GetNoGoodImgs();
noGoodImages.Sort(CompareSize);
goodImages = EDCheckPrefabRef.goodImgs;
goodImages.Sort(CompareSize);
packImages = EDCheckPrefabRef.packImgs;
packImages.Sort(CompareSize);
}
private int CompareSize(Texture2D t1, Texture2D t2) {
int t1Size = t1.width * t1.height;
int t2Size = t2.width * t2.height;
if (t1Size > t2Size)
{
return -1;
}
else if (t1Size == t2Size) {
return 0;
}
else
{
return 1;
}
}
private void OnGUI()
{
GUIContent title = new GUIContent();
title.text = "ImgNoGood";
this.titleContent = title;
GUILayout.Space(10);
if (GUILayout.Button("更新"))
{
this.UpdateMsg();
}
GUILayout.Space(10);
GUILayout.Label("功能说明:以下"+ noGoodImages.Count + "张图片尺寸不符合2的N次幂;"+goodImages.Count+ "张图片尺寸符合2的N次幂"+ packImages.Count+ "张Pack图片");
selectIndex = GUILayout.SelectionGrid(selectIndex, btns,3,GUILayout.MinWidth(100));
scrollPos =
EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(500), GUILayout.Height(400));
List<Texture2D> showList = selectIndex == 0 ? noGoodImages : (selectIndex==1?goodImages:packImages);
for (int i = 0; i < showList.Count; i++)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Label(showList[i].name + ":" + showList[i].width + "*" + showList[i].height + ":");
img = showList[i];
img = (Texture2D)EditorGUILayout.ObjectField(img, typeof(Texture2D), false, GUILayout.MinWidth(200f));
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
}
}
}