예제 #1
0
        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
                    {
                    }
                }
            }
        }
예제 #2
0
        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
                            });
                        });
                    }
                });
            }
        }