Example #1
0
        public void TexturePackage()
        {
            var resDir = DirTools.GetTmpResDir();

            string[] files     = System.IO.Directory.GetFiles(resDir);
            var      outputDir = DirTools.GetTmpOutPutDir();

            var isOn = ToggleTexturePackage.isOn;

            if (isOn)
            {
                string name    = "default";
                var    command = Application.streamingAssetsPath + "/bin/TexturePacker.exe";
                var    argu    = string.Format(@"{0} --sheet {1}/{2}.png --data {1}/{2}.plist --allow-free-size --no-trim --max-size 2048 --format cocos2d", resDir, outputDir, name);
                Utils.processCommand(command, argu);

                // Copy the files and overwrite destination files if they already exist.
                foreach (string s in files)
                {
                    // Use static Path methods to extract only the file name from the path.
                    if (System.IO.Path.GetExtension(s) != ".png")
                    {
                        var fileName = System.IO.Path.GetFileName(s);
                        var destFile = System.IO.Path.Combine(outputDir, fileName);
                        System.IO.File.Copy(s, destFile, true);
                    }
                }
            }
            else
            {
                foreach (string s in files)
                {
                    var fileName = System.IO.Path.GetFileName(s);
                    var destFile = System.IO.Path.Combine(outputDir, fileName);
                    System.IO.File.Copy(s, destFile, true);
                }
            }
        }
Example #2
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
        }