Exemple #1
0
        IEnumerator BackupConfig(AttachmentsConfig config, string type)
        {
            var             url        = string.Format("http://gate-static.97kid.com/{0}", config.attachments.uri);
            UnityWebRequest webRequest = UnityWebRequest.Get(url);

            yield return(webRequest.SendWebRequest());

            if (webRequest.isNetworkError)
            {
                Debug.Log(": Error: " + webRequest.error);
            }
            else
            {
                DateTime date    = DateTime.Now;
                var      dateStr = date.ToString("yyyyMMdd-HH时mm分ss秒");
                var      zipPath = DirTools.GetBackupDir() + "/" + dateStr + "." + config.attachments.ext_name;
                Debug.Log(zipPath);
                var data = webRequest.downloadHandler.data;
                File.WriteAllBytes(zipPath, data);
                if (type == "replace")
                {
                    StartCoroutine(UploadConfig(config));
                }
                else if (type == "restore")
                {
                    DirTools.DeleteFolder(DirTools.GetUnZipDir());
                    ZipUtil.UnZipFile(zipPath, DirTools.GetUnZipDir());
                    StartCoroutine(Unpacker(DirTools.GetUnZipDir() + "/default.plist", DirTools.GetUnZipDir() + "/default.png"));
                }
            }
        }
Exemple #2
0
        IEnumerator Unpacker(string plistFilePath, string pngFilePath)
        {
            DirTools.DeleteFolder(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
                    {
                    }
                }
            }
            DirectoryInfo dir = new DirectoryInfo(DirTools.GetUnZipDir());

            FileInfo[] finfo = dir.GetFiles();
            for (int i = 0; i < finfo.Length; i++)
            {
                var file = finfo[i];
                if (file.Name.IndexOf("plist") > -1 || file.Name.IndexOf("png") > -1)
                {
                }
                else
                {
                    File.Copy(file.FullName, DirTools.GetRestoredPNGDir() + "/" + file.Name, true);
                }
            }
            ImportToResPanel();
            yield return(null);
        }
Exemple #3
0
        protected override void OnInit(QFramework.IUIData uiData)
        {
            mData = uiData as UIResourcePanelData ?? new UIResourcePanelData();
            // please add init code here
            var activity = mData.activityIndex;
            var id       = mData.id;

            TextLabel.text = "ResArea-" + activity;
            var version = PlayerPrefs.GetString("Version");

            gameObject.AddComponent <FileDragAndDrop>();
            DirTools.ActivityIndex = activity;
            DirTools.Version       = version;
            TypeEventSystem.Register <ResBlockNameChanged>(NameChanged);
            Export.onClick.AddListener(ExportRes);
            Clear.onClick.AddListener(ClearRes);
            God.onClick.AddListener(() =>
            {
                UIMgr.OpenPanel("UIUploadPanel", UILevel.Common, new UIUploadPanelData()
                {
                    ActivityIndex = activity,
                    id            = id
                });
            });
            TypeEventSystem.Register <RemoveBlock>((tmp) => {
                var md5 = tmp.MD5;

                ResMap.Remove(md5);
                string resDir   = DirTools.GetTmpResDir();
                string filepath = Path.Combine(resDir, md5 + tmp.Extension);
                if (File.Exists(filepath))
                {
                    File.Delete(filepath);
                }
                else
                {
                    Debug.LogError("资源不存在!!!");
                }
            });
            TypeEventSystem.Register <SetBlockProperties>((tmp) => {
                var md5        = tmp.MD5;
                var properties = tmp.properties;
                var ResBlock   = ResMap[md5];
                ResBlock.GetComponent <ResBlockScript>().Properties = properties;
            });
            TypeEventSystem.Register <ClearRescoursePanel>((tmp) => {
                ResMap.Clear();
                var lst = new List <Transform>();
                foreach (Transform child in Content)
                {
                    lst.Add(child);
                }
                for (int i = 0; i < lst.Count; i++)
                {
                    Destroy(lst[i].gameObject);
                }
                DirTools.DeleteFolder(DirTools.GetTmpResDir());
            });

            TypeEventSystem.Register <FilePathInfo>((file) =>
            {
                if (ResMap.ContainsKey(file.MD5))
                {
                    return;
                }
                else if (file.Extension == ".zip")
                {
                    MessageBoxV2.AddMessage("暂不支持拖入zip", 3);
                }
                else
                {
                    var BlockImage = Instantiate(ResBlockPrefab, Content);
                    BlockImage.GetComponent <ResBlockScript>().SetImage(file);
                    DirTools.CopyDropFileToTmpResDir(file);
                    ResMap.Add(file.MD5, BlockImage);
                }
            });
            DirTools.CleanUpDir();
            ResMap.Clear();
#if UNITY_EDITOR
            Invoke("Test", 3.0f);
#endif
        }