using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Xml;
using UnityEditor;
using UnityEngine;
/// <summary>
/// 获得所有文件的名字
/// </summary>
public class GainAllFileFullName
{
//各个包名的当前数值,当新打包的时候,该值加1;如果没有的话,就从零开始
public static Dictionary<string, int> FilesABNumberDic = new Dictionary<string, int>();
//CUBE,用于存储WKLuaTest下的一级目录(会有重复的名字)
public static List<string> AllFileName = new List<string>();
//最后一个名字cube.prefab
public static List<string> ObjName = new List<string>();
//文件的路径d:\SVNProject\Assets\Resources\WKLuaTest\CUBE
public static List<string> FileName = new List<string>();
//md5码//文件列表的MD5//Filexml
public static List<string> _MD5Arr = new List<string>();
//完整的路径
public static List<string> LongPath = new List<string>();
//包名,没有重复的名字CUBE,IMAGE
public static List<string> ABNameNoSame = new List<string>();
string outputPosition = "d:/SVNProject/Assets/Resources/WKLuaTest";
//上一个版本的包名(没有重复的)
public static List<string> OldABName = new List<string>();
/// <summary>
/// 获得所有物体的名字
/// </summary>
public static void GetObjName(string name)
{
// Debug.Log(name + "名字");
string str = Path.GetFileName(name);
// Debug.Log("物体的名字是/:" + str);
ObjName.Add(str);
string str1 = Path.GetDirectoryName(name);
// Debug.Log("文件的名字是/:" + str1);
FileName.Add(str1);
//创建一个MD5码
WKABBuilder.BuildMD5(name);
}
/// <summary>
/// 生成文件列表之后,调用,Cube0,Image0,Scene0.....
/// </summary>
public static void ABFilesNumber()
{
//键值对
//键是唯一的
//如果没有就直接添加
//如果有的话,就直接加1
for (int i = 0; i < ABNameNoSame.Count; i++)
{
if (FilesABNumberDic.ContainsKey(ABNameNoSame[i]))
{
FilesABNumberDic[ABNameNoSame[i]]++;
}
else
{
FilesABNumberDic.Add(ABNameNoSame[i], 0);
}
}
ModifyAttributeS(@"d:/AssetBundles" + "\\NameNumber.xml");
}
//把dict的内容添加到xml里边
public static void CreateNameNumberXML()
{
XmlDocument doc = new XmlDocument();
XmlElement e = doc.CreateElement("Root");
doc.AppendChild(e);
for (int i = 0; i < ABNameNoSame.Count; i++)
{
e.SetAttribute(ABNameNoSame[i], FilesABNumberDic[ABNameNoSame[i]].ToString());
Debug.Log("把字典里的内容添加到xml里边");
}
string pathfile = @"d:/AssetBundles" + "\\NameNumber.bytes";
doc.Save(pathfile);
pathfile = @"d:/AssetBundles" + "\\NameNumber.xml";
doc.Save(pathfile);
}
public static void ModifyAttributeS(string xmlPath)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlPath);
xmlDoc.RemoveAll();
XmlElement e = xmlDoc.CreateElement("Root");
xmlDoc.AppendChild(e);
for (int i = 0; i < ABNameNoSame.Count; i++)
{
e.SetAttribute(ABNameNoSame[i], FilesABNumberDic[ABNameNoSame[i]].ToString());
}
string pathfile = @"d:/AssetBundles" + "\\NameNumber.bytes";
xmlDoc.Save(pathfile);
pathfile = @"d:/AssetBundles" + "\\NameNumber.xml";
xmlDoc.Save(pathfile);
}
/// <summary>
/// 获得上一版本的信息
/// </summary>
public static void ReadNameNumberXML()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"d:/AssetBundles" + "\\NameNumber.xml");
XmlNode node = xmlDoc.SelectSingleNode("/Root");
Debug.Log(OldABName.Count + "上一版本的数量");
//清除所有
//foreach (KeyValuePair<string, int> ff in FilesABNumberDic)
//{
// FilesABNumberDic.Remove(ff.Key);
//}
FilesABNumberDic.Clear();
Debug.Log("测试字典的长度是" + FilesABNumberDic.Count);
if (node != null)
{
for (int i = 0; i < OldABName.Count; i++)
{ // 0 1 2 3 4 5
string name = OldABName[i];//C U B E _ 0
int index = name.IndexOf("_");
string ABName = name.Substring(0, index);
int number= (int.Parse)(name.Substring(index+1,name.Length-index-1));
if (FilesABNumberDic.ContainsKey(ABName))
{
FilesABNumberDic.Remove(ABName);
}
FilesABNumberDic.Add(ABName, number);
}
}
}
/// <summary>
///把文件夹名或者包名中重复的去掉
/// </summary>
public static void RemoveTheSameABName()
{
for (int a = 0; a < AllFileName.Count; a++)
{
if (!ABNameNoSame.Contains(AllFileName[a]))
{
ABNameNoSame.Add(AllFileName[a]);
Debug.Log(AllFileName[a]+"\\\\\\\\\\");
}
}
}
}
编辑器扩展(二)
最新推荐文章于 2022-07-07 18:34:01 发布