Esempio n. 1
0
        public void ImportToResPanel()
        {
            TypeEventSystem.Send(new ClearRescoursePanel());
            var dict = getResConfig(DirTools.GetRestoredPNGDir());

            foreach (KeyValuePair <string, Dictionary <string, string> > kv in dict)
            {
                var properties = kv.Value;
                var Name       = properties["Name"];
                var MD5        = properties["MD5"];
                var Extension  = properties["Extension"];
                var fileinfo   = new FilePathInfo()
                {
                    FilePath  = DirTools.GetRestoredPNGDir() + "/" + MD5 + Extension,
                    FileName  = Name + Extension,
                    Extension = Extension,
                    MD5       = MD5
                };
                TypeEventSystem.Send(fileinfo);
                TypeEventSystem.Send(new SetBlockProperties()
                {
                    MD5        = MD5,
                    properties = properties
                });
            }
            UIMgr.ClosePanel("UIUploadPanel");
        }
Esempio n. 2
0
        //从大图中裁剪出小图,并还原到原始大小(恢复其四周被裁剪的透明像素)
        public static void Restore(Texture2D bigTexture, Frame frame)
        {
            int sampleWidth  = frame.size.width;
            int sampleHeight = frame.size.height;
            int destWidth    = frame.sourceSize.width;
            int destHeight   = frame.sourceSize.height;

            //换算偏移值(不受旋转影响)
            int offsetLX = frame.offset.x + frame.sourceSize.width / 2 - frame.size.width / 2;
            int offsetBY = -(-frame.offset.y + frame.size.height / 2 - frame.sourceSize.height / 2);

            Texture2D destTexture = new Texture2D(destWidth, destHeight);

            if (frame.isRotated)
            {
                sampleWidth  = frame.size.height;
                sampleHeight = frame.size.width;
            }

            //起始位置(Y轴需变换,且受旋转影响)。
            int startPosX = frame.startPos.x;
            int startPosY = bigTexture.height - (frame.startPos.y + sampleHeight);

            Color[] colors = bigTexture.GetPixels(startPosX, startPosY, sampleWidth, sampleHeight);

            //设置像素(将采样像素放到目标图中去)
            for (int w = 0; w < destWidth; w++)
            {
                for (int h = 0; h < destHeight; h++)
                {
                    if (w >= offsetLX && w < frame.size.width + offsetLX && h >= offsetBY && h < frame.size.height + offsetBY)
                    {
                        if (frame.isRotated)
                        {
                            //旋转时,目标图中的坐标(w, h),对应的采样区坐标为(h-offsetTY, sampleHeight-1-(w-offsetLX))
                            int index = (sampleHeight - 1 - (w - offsetLX)) * sampleWidth + (h - offsetBY);
                            destTexture.SetPixel(w, h, colors[index]);
                        }
                        else
                        {
                            //没有旋转时,目标图中的坐标(w, h),对应的采样区坐标为(w-offsetLX, h-offsetTY)
                            int index = (h - offsetBY) * sampleWidth + (w - offsetLX);
                            destTexture.SetPixel(w, h, colors[index]);
                        }
                    }
                    else
                    {
                        //四周颜色(透明)
                        destTexture.SetPixel(w, h, new Color(0, 0, 0, 0));
                    }
                }
            }

            destTexture.Apply();
            byte[] bytes = destTexture.EncodeToPNG();
            Save(DirTools.GetRestoredPNGDir(), frame.textureName, bytes);
            Texture2D.Destroy(destTexture);
            destTexture = null;
        }
Esempio n. 3
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);
        }