NGUI UI资源管理工具

本文介绍了一款用于管理Unity项目的UI资源工具,旨在解决资源换版后冗余问题。该工具提供可视化界面,可查找资源在图集的位置,显示预制体引用,以及资源大小、预览和路径信息,帮助优化和梳理UI资源。
摘要由CSDN通过智能技术生成

写在前面:

    项目开发迭代过程中,UI资源的换版,会造成很多旧资源的冗余,而人工删除资源麻烦在于无法区分这个资源是不是还有地方再用,此工具的目的是提供一个可视化的界面,根据资源名称确定其所在图集,并且列出预制体对于改资源的引用,同时显示图片的大小,预览,路径等信息。为UI资源的梳理提供便利。

布局如下:



代码如下:

/*
图集资源管理器
	1:查询UI资源
	2:图集查重
	3:资源引用处理
	4:资源删除
author: tianrujie
date  : 2018/5/5
*/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using ExcelDataReader;
using UnityEditor;
using excel2json;
using System.Text;
using System.Diagnostics;

public class UIAssetTool : EditorWindow  {

	//图集存放位置
	private string AtlasWorkSpace = "Assets/AssetBundles/UI/Prefab/Atlas/";

	//图集小图资源存放位置
	private string AtlasAssetpath = "Assets/UI/UITexture/";

	//UI预制体资源位置
	private string PrefabAssetpath = "Assets/AssetBundles/UI/Prefab/";

	public enum OperateType
	{
		atlasFilter = 1,			//图集资源查重
		assetReferenceFind = 2,		//资源引用查询
	}

	[MenuItem("Tools/UIAssetTool")]
	static void RunTool()
	{
		Rect re = new Rect(0, 0, 1000, 500);
		UIAssetTool window = (UIAssetTool)EditorWindow.GetWindowWithRect(typeof(UIAssetTool), re, true, "UI资源管理");
		window.Show();
		window.InitData ();
	}

	//图集搜索文本
	private string searchAtlas = string.Empty;

	//资源搜索文本
	private string searchSprite = string.Empty;

	//当前选中图集
	private string selecitionAtlas = string.Empty;

	//当前选中资源
	private string selecitionSprite = string.Empty;

	//当前选中引用
	private string selectionRef = string.Empty;

	//图集列表
	private List<string> AtlasList = new List<string>();

	//图集资源容器
	private Dictionary<string,List<string>> AtlasAssetDic = new Dictionary<string, List<string>>();

	//<图片名称---图集>字典
	private Dictionary<string,List<string>> SpriteLinkDic = new Dictionary<string, List<string>>();

	//图片的引用
	private Dictionary<string,List<string>> SpriteReference = new Dictionary<string, List<string>>();



	/// <summary>
	/// 初始化数据
	/// </summary>
	/// <returns><c>true</c>, if data was inited, <c>false</c> otherwise.</returns>
	bool InitData()
	{
		AtlasList.Clear ();
		AtlasAssetDic.Clear ();

		DirectoryInfo dic = new DirectoryInfo (AtlasWorkSpace);
		FileInfo[] atlases = dic.GetFiles ();

		if (atlases == null)
			return false;

		for (int i = 0; i < atlases.Length; i++)
		{
			if (atlases [i].Name.Contains ("meta"))
				continue;

			AtlasList.Add (atlases[i].Name);
			if (!AtlasAssetDic.ContainsKey (atlases [i].Name))
			{
				UIAtlas atlas = AssetDatabase.LoadAssetAtPath<UIAtlas>(AtlasWorkSpace + atlases [i].Name
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值