void Unpacker(string plistFilePath, string pngFilePath) { DirTools.DeleteFilesAndFolders(DirTools.GetRestoredPNGDir()); var loader = NRatel.TextureUnpacker.Loader.LookingForLoader(plistFilePath); if (loader != null) { var plist = loader.LoadPlist(plistFilePath); var bigTexture = loader.LoadTexture(pngFilePath, plist.metadata); int total = plist.frames.Count; int count = 0; foreach (var frame in plist.frames) { try { Core.Restore(bigTexture, frame); count += 1; } catch { } } } }
public TexturePackageDone TexturePackage(List <ResourceInfo> totalInfo) { DirTools.DeleteFilesAndFolders(DirTools.GetTobePackedTexuresPath()); var textureInfo = TotalResInfo = totalInfo.Where((info) => { return(info.Tag == ResourceTag.TexturePackage || (info.Tag == ResourceTag.CocosStudio && info.Extension == ".png")); }).ToList(); if (!isCanFit()) { return(new TexturePackageDone() { Ret = false, Reason = "图片总面积超过了2048*2048,建议把背景图标记为不合图。\n下个版本会支持拆分为多个plist,感谢支持!" }); } else if (textureInfo.Count == 0) { return(new TexturePackageDone() { Ret = true, Reason = "合图完成", PlistsName = new List <string>(), Files = new List <string>(), }); } else { var tobePackedPath = DirTools.GetTobePackedTexuresPath(); textureInfo.ForEach((info) => { var filePath = tobePackedPath + "/" + info.MD5 + info.Extension; File.Copy(info.FileFullName, filePath, true); }); TexturePackageCommand(tobePackedPath, tobePackedPath, PlistName); return(new TexturePackageDone() { Ret = true, Reason = "合图完成", PlistsName = new List <string>() { PlistName }, Files = new List <string>() { tobePackedPath + "/" + PlistName + ".png", tobePackedPath + "/" + PlistName + ".plist", } }); } }
void ImportZip(string path) { var tempPath = DirTools.GetTempPath(); var unzipPath = tempPath + "/unzip"; if (Directory.Exists(unzipPath)) { DirTools.DeleteFilesAndFolders(unzipPath); } ZipUtil.UnZipFile(path, unzipPath); var isExist = File.Exists(unzipPath + "/ResConfig.json"); var ret = false; if (isExist) { StreamReader sr = new StreamReader(unzipPath + "/ResConfig.json"); if (sr == null) { return; } string json = sr.ReadToEnd(); sr.Close(); var configTemplate = JsonConvert.DeserializeObject <ConfigTemplate>(json); if (configTemplate.resource != null) { ret = true; } } if (ret) { StreamReader sr = new StreamReader(unzipPath + "/ResConfig.json"); if (sr == null) { return; } string json = sr.ReadToEnd(); sr.Close(); var configTemplate = JsonConvert.DeserializeObject <ConfigTemplate>(json); configTemplate.resource.Where((item) => { return(item.Value.Tag != ResourceTag.TagsMap[ResourceTag.TexturePackage]); }).ForEach((item) => { var tag = ResourceTag.TagsMap.Where((tagItem) => { return(tagItem.Value == item.Value.Tag); }) .First().Key; string filepath = ""; if (tag == ResourceTag.None) { filepath = unzipPath + "/none/" + item.Value.Name; } else if (tag == ResourceTag.CocosStudio) { filepath = unzipPath + "/" + item.Value.Name; } Debug.Log(string.Format("从zip导入文件路径{0} 文件Tag{1}", filepath, tag)); TypeEventSystem.Send(new FileDragIn() { Path = filepath, Tag = tag }); }); if (configTemplate.plist != null) { configTemplate.plist.ForEach((name) => { var plistPath = unzipPath + "/plist/" + name + ".plist"; var pngPath = unzipPath + "/plist/" + name + ".png"; Unpacker(plistPath, pngPath); }); configTemplate.resource.Where((item) => { return(item.Value.Tag == ResourceTag.TagsMap[ResourceTag.TexturePackage]); }).ForEach((item) => { var md5 = item.Value.Md5; string imagePath = DirTools.GetRestoredPNGDir() + "/" + md5 + item.Value.Extension; Debug.Log(imagePath); if (File.Exists(imagePath)) { File.Move(imagePath, DirTools.GetRestoredPNGDir() + "/" + item.Value.Name); TypeEventSystem.Send(new FileDragIn() { Path = DirTools.GetRestoredPNGDir() + "/" + item.Value.Name, Tag = ResourceTag.TexturePackage }); } else { Debug.Log("bububu"); } }); } } else { Directory.GetFiles(unzipPath, "*").ForEach((file) => { var extension = System.IO.Path.GetExtension(file); if (extension != ".plist") { TypeEventSystem.Send(new FileDragIn() { Path = file, Tag = ResourceTag.Default }); } else { var pathName = System.IO.Path.GetDirectoryName(file); var fileName = System.IO.Path.GetFileNameWithoutExtension(file); var plistPath = file; var pngPath = pathName + '/' + fileName + ".png"; Unpacker(plistPath, pngPath); var RestoredPath = DirTools.GetRestoredPNGDir(); Directory.GetFiles(RestoredPath, "*").ForEach((filePath) => { TypeEventSystem.Send(new FileDragIn() { Path = filePath, Tag = ResourceTag.Default }); }); } }); } }