private static void ProcessingCardPicture(PictureResource pic)
    {
        if (loadedList.ContainsKey(hashPic(pic.code, pic.type)))
        {
            return;
        }

        bool EightEdition;
        var  data = getPicture(pic, out EightEdition);

        if (data.Length > 0)
        {
            pic.data = data;
            loadedList.Add(hashPic(pic.code, pic.type), pic);
        }
        else
        {
            if (pic.code > 0)
            {
                pic.u_data = unknown;
            }
            else
            {
                pic.u_data = myBack;
            }
            loadedList.Add(hashPic(pic.code, pic.type), pic);
        }
    }
 private static void ProcessingVerticleDrawing(PictureResource pic)
 {
     try
     {
         string path = "picture/closeup/" + pic.code.ToString() + ".png";
         if (!File.Exists(path))
         {
             path = "picture/card/" + pic.code.ToString() + ".png";
             if (!File.Exists(path))
             {
                 path = "picture/card/" + pic.code.ToString() + ".jpg";
             }
             bool Iam8 = false;
             if (!File.Exists(path))
             {
                 Iam8 = true;
                 path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
             }
             if (!File.Exists(path))
             {
                 Iam8 = true;
                 path = "expansions/pics/" + pic.code.ToString() + ".jpg";
             }
             LoadCloseupFromCardPicture(pic, path, Iam8);
         }
         else
         {
             LoadCloseupPicture(pic, path);
         }
     }
     catch (Exception e)
     {
         Debug.Log("e 3" + e.ToString());
     }
 }
    private static void LoadCloseupFromCardPicture(PictureResource pic, string path, bool Iam8)
    {
        try
        {
            if (!File.Exists(path))
            {
                path = "picture/null.png";
            }
            if (!File.Exists(path))
            {
                path = "texture/duel/unknown.jpg";
            }
            pic.hashed_data = getCuttedPic(path, pic.pCard, Iam8);
            softVtype(pic, 0.5f);
            pic.k = 1;
            //pic.autoMade = true;

            if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
            {
                loadedList.Add(hashPic(pic.code, pic.type), pic);
            }
        }
        catch
        {
        }
    }
示例#4
0
 private static void ProcessingCardPicture(PictureResource pic)
 {
     try
     {
         int[]  OT   = { 1, 2, 3 };//对应: OCG、TCG、OCG&TCG
         string path = "picture/card/" + pic.code.ToString() + ".png";
         if (!File.Exists(path))
         {
             path = "picture/card/" + pic.code.ToString() + ".jpg";
         }
         if (!File.Exists(path))
         {
             path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
         }
         if (!File.Exists(path))
         {
             path = "expansions/pics/" + pic.code.ToString() + ".jpg";
         }
         if (!File.Exists(path) && pic.code != 0 && OT.Contains(YGOSharp.CardsManager.Get((int)pic.code).Ot))
         {
             //YGOMobile-JP (177x254)
             df.Download("http://api.ygo2020.xyz/ygopro/pics/" + pic.code.ToString() + ".jpg", "expansions/pics/" + pic.code.ToString() + ".jpg");
             path = "expansions/pics/" + pic.code.ToString() + ".jpg";
         }
         LoadCardPicture(pic, path);
     }
     catch (Exception e)
     {
         Debug.Log("e 2" + e.ToString());
     }
 }
示例#5
0
        public void DrawPictureToPictureBuffer(PictureResource resource, bool overlay)
        {
            PictureRenderer    renderer    = new PictureRenderer(this.PictureBuffer);
            PictureInterpreter interpreter = new PictureInterpreter();

            if (!overlay)
            {
                renderer.Clear();
            }

            interpreter.Execute(resource, renderer);
        }
    private static byte[] getPicture(PictureResource pic, out bool EightEdition)
    {
        EightEdition = false;
        string code = pic.code.ToString();

        foreach (ZipFile zip in GameZipManager.Zips)
        {
            if (zip.Name.ToLower().EndsWith("script.zip"))
            {
                continue;
            }
            foreach (string file in zip.EntryFileNames)
            {
                if (Regex.IsMatch(file.ToLower(), "pics/" + code + "\\.(jpg|png)$"))
                {
                    MemoryStream ms = new MemoryStream();
                    ZipEntry     e  = zip[file];
                    e.Extract(ms);
                    return(ms.ToArray());
                }
            }
        }
        string path = "picture/card/" + code + ".png";

        if (!File.Exists(path))
        {
            path = "picture/card/" + code + ".jpg";
        }
        if (!File.Exists(path))
        {
            EightEdition = true;
            path         = "picture/cardIn8thEdition/" + code + ".png";
        }
        if (!File.Exists(path))
        {
            EightEdition = true;
            path         = "picture/cardIn8thEdition/" + code + ".jpg";
        }
        if (File.Exists(path))
        {
            using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                file.Seek(0, SeekOrigin.Begin);
                var data = new byte[file.Length];
                file.Read(data, 0, (int)file.Length);
                return(data);
            }
        }
        return(new byte[0]);
    }
示例#7
0
    private static void ProcessingCardPicture(PictureResource pic)
    {
        string path = "picture\\card\\" + pic.code.ToString() + ".png";

        if (!File.Exists(path))
        {
            path = "picture\\card\\" + pic.code.ToString() + ".jpg";
        }
        if (!File.Exists(path))
        {
            path = "picture\\cardIn8thEdition\\" + pic.code.ToString() + ".jpg";
        }
        if (!File.Exists(path))
        {
            if (pic.code > 0)
            {
                pic.u_data = unknown;
            }
            else
            {
                pic.u_data = myBack;
            }
            if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
            {
                loadedList.Add(hashPic(pic.code, pic.type), pic);
            }
        }
        else
        {
            byte[] data;
            using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                file.Seek(0, SeekOrigin.Begin);
                data = new byte[file.Length];
                file.Read(data, 0, (int)file.Length);
            }
            pic.data = data;
            if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
            {
                loadedList.Add(hashPic(pic.code, pic.type), pic);
            }
        }
    }
 private static void LoadCloseupFromCardPicture(PictureResource pic, string path, bool Iam8)
 {
     try
     {
         if (!File.Exists(path))
         {
             path = "Assets/essential/picture/null.png";
         }
         pic.hashed_data = getCuttedPic(path, pic.pCard, Iam8);
         softVtype(pic, 0.5f);
         pic.k = 1;
         if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
         {
             loadedList.Add(hashPic(pic.code, pic.type), pic);
         }
     }
     catch
     {
     }
 }
        public JsonResult UploadPic(int index)
        {
            var picFile = Request.Files["Pic" + index];

            byte[] buffer = new byte[picFile.ContentLength];
            picFile.InputStream.Read(buffer, 0, picFile.ContentLength);
            var pic = new PictureResource()
            {
                OriginName = Path.GetFileName(picFile.FileName),
                Content    = buffer,
            };

            pic.Name = GetHashName(pic.OriginName);
            pic.Path = MakeCoverPicPath(0);
            NewsContentPictureService.Create(pic);
            return(new JsonResult()
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new { success = true, path = Path.Combine(ftp, pic.Path, pic.Name), name = pic.OriginName }
            });
        }
 private static void LoadCardPicture(PictureResource pic, string path)
 {
     try
     {
         if (!File.Exists(path))
         {
             if (pic.code > 0)
             {
                 pic.u_data = unknown;
             }
             else
             {
                 pic.u_data = myBack;
             }
             if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
             {
                 loadedList.Add(hashPic(pic.code, pic.type), pic);
             }
         }
         else
         {
             byte[] data;
             using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
             {
                 file.Seek(0, SeekOrigin.Begin);
                 data = new byte[file.Length];
                 file.Read(data, 0, (int)file.Length);
             }
             pic.data = data;
             if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
             {
                 loadedList.Add(hashPic(pic.code, pic.type), pic);
             }
         }
     }
     catch (Exception e)
     {
         Debug.Log("e 2" + e.ToString());
     }
 }
    private static BitmapHelper getCloseup(PictureResource pic)
    {
        BitmapHelper bitmap = null;
        bool         found  = false;
        string       code   = pic.code.ToString();

        foreach (ZipFile zip in GameZipManager.Zips)
        {
            if (zip.Name.ToLower().EndsWith("script.zip"))
            {
                continue;
            }
            foreach (string file in zip.EntryFileNames)
            {
                if (Regex.IsMatch(file.ToLower(), "closeup/" + code + "\\.png$"))
                {
                    MemoryStream ms = new MemoryStream();
                    ZipEntry     e  = zip[file];
                    e.Extract(ms);
                    bitmap = new BitmapHelper(ms);
                    found  = true;
                    break;
                }
            }
            if (found)
            {
                break;
            }
        }
        if (!found)
        {
            string path = "picture/closeup/" + code + ".png";
            if (File.Exists(path))
            {
                bitmap = new BitmapHelper(path);
            }
        }
        return(bitmap);
    }
示例#12
0
        public JsonResult CreatePic()
        {
            var             resources = GetUploadResource();
            PictureResource pic       = resources.Select(item => new PictureResource(item)).FirstOrDefault();

            pic.Path = MakePath(pic);
            pic.Name = GetHashName(pic.OriginName);
            ResourcePictureService.Create(pic);
            Service.Create(pic);
            return(new JsonResult()
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new
                {
                    success = true,
                    resourceID = pic.ID,
                    name = pic.OriginName,
                    path = System.IO.Path.Combine(ftp, pic.Path, GetName(pic, ItemSize)),
                    size = pic.Size
                },
            });
        }
示例#13
0
 private static void ProcessingCardPicture(PictureResource pic)
 {
     try
     {
         string path = "picture/card/" + pic.code.ToString() + ".png";
         if (!File.Exists(path))
         {
             path = "picture/card/" + pic.code.ToString() + ".jpg";
         }
         if (!File.Exists(path))
         {
             path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
         }
         if (!File.Exists(path))
         {
             path = "expansions/pics/" + pic.code.ToString() + ".jpg";
         }
         LoadCardPicture(pic, path);
     }
     catch (Exception e)
     {
         Debug.Log("e 2" + e.ToString());
     }
 }
示例#14
0
    private static void ProcessingCardFeature(PictureResource pic)
    {
        if (File.Exists("picture\\closeup\\" + pic.code.ToString() + ".png"))
        {
            string       path   = "picture\\closeup\\" + pic.code.ToString() + ".png";
            BitmapHelper bitmap = new BitmapHelper(path);
            int          left;
            int          right;
            int          up;
            int          down;
            CutTop(bitmap, out left, out right, out up, out down);
            up    = CutLeft(bitmap, up);
            down  = CutRight(bitmap, down);
            right = CutButton(bitmap, right);
            int width  = right - left;
            int height = down - up;
            pic.hashed_data = new float[width, height, 4];
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    System.Drawing.Color color = bitmap.GetPixel(left + w, up + h);
                    float a = (float)color.A / 255f;
                    if (w < 40)
                    {
                        if (a > (float)w / (float)40)
                        {
                            a = (float)w / (float)40;
                        }
                    }
                    if (w > (width - 40))
                    {
                        if (a > 1f - (float)(w - (width - 40)) / (float)40)
                        {
                            a = 1f - (float)(w - (width - 40)) / (float)40;
                        }
                    }
                    if (h < 40)
                    {
                        if (a > (float)h / (float)40)
                        {
                            a = (float)h / (float)40;
                        }
                    }
                    if (h > (height - 40))
                    {
                        if (a > 1f - (float)(h - (height - 40)) / (float)40)
                        {
                            a = 1f - (float)(h - (height - 40)) / (float)40;
                        }
                    }
                    pic.hashed_data[w, height - h - 1, 0] = (float)color.R / 255f;
                    pic.hashed_data[w, height - h - 1, 1] = (float)color.G / 255f;
                    pic.hashed_data[w, height - h - 1, 2] = (float)color.B / 255f;
                    pic.hashed_data[w, height - h - 1, 3] = a;
                }
            }
            caculateK(pic);

            if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
            {
                loadedList.Add(hashPic(pic.code, pic.type), pic);
            }
        }
        else
        {
            string path = "picture\\card\\" + pic.code.ToString() + ".png";
            if (!File.Exists(path))
            {
                path = "picture\\card\\" + pic.code.ToString() + ".jpg";
            }
            bool Iam8 = false;
            if (!File.Exists(path))
            {
                Iam8 = true;
                path = "picture\\cardIn8thEdition\\" + pic.code.ToString() + ".jpg";
            }
            if (!File.Exists(path))
            {
                pic.hashed_data = new float[10, 10, 4];
                for (int w = 0; w < 10; w++)
                {
                    for (int h = 0; h < 10; h++)
                    {
                        pic.hashed_data[w, h, 0] = 0;
                        pic.hashed_data[w, h, 1] = 0;
                        pic.hashed_data[w, h, 2] = 0;
                        pic.hashed_data[w, h, 3] = 0;
                    }
                }
                if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
                {
                    loadedList.Add(hashPic(pic.code, pic.type), pic);
                }
            }
            else
            {
                pic.hashed_data = getCuttedPic(path, pic.pCard, Iam8);
                int width     = pic.hashed_data.GetLength(0);
                int height    = pic.hashed_data.GetLength(1);
                int size      = (int)(height * 0.8);
                int empWidth  = (width - size) / 2;
                int empHeight = (height - size) / 2;
                int right     = width - empWidth;
                int buttom    = height - empHeight;
                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        float a = pic.hashed_data[w, h, 3];
                        if (w < empWidth)
                        {
                            if (a > ((float)w) / (float)empWidth)
                            {
                                a = ((float)w) / (float)empWidth;
                            }
                        }
                        if (h < empHeight)
                        {
                            if (a > ((float)h) / (float)empHeight)
                            {
                                a = ((float)h) / (float)empHeight;
                            }
                        }
                        if (w > right)
                        {
                            if (a > 1f - ((float)(w - right)) / (float)empWidth)
                            {
                                a = 1f - ((float)(w - right)) / (float)empWidth;
                            }
                        }
                        if (h > buttom)
                        {
                            if (a > 1f - ((float)(h - buttom)) / (float)empHeight)
                            {
                                a = 1f - ((float)(h - buttom)) / (float)empHeight;
                            }
                        }
                        pic.hashed_data[w, h, 3] = a * 0.7f;
                    }
                }
                if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
                {
                    loadedList.Add(hashPic(pic.code, pic.type), pic);
                }
            }
        }
    }
示例#15
0
    private static void caculateK(PictureResource pic)
    {
        //int width = pic.hashed_data.GetLength(0);
        //int height = pic.hashed_data.GetLength(1);
        //int left = 0;
        //int right = width;
        //if (width > height)
        //{
        //    left = (width - height) / 2;
        //    right = width - left;
        //}
        //int all = 0;
        //for (int h = 0; h < height; h++)
        //{
        //    for (int w = left; w < right; w++)
        //    {
        //        if (pic.hashed_data[w, h, 3] > 0.05f)
        //        {
        //            all += 1;
        //        }
        //    }
        //}
        //float result = ((float)all) / (((float)height) * ((float)(height)));
        //pic.k = result + 0.4f;
        //if (pic.k > 1)
        //{
        //    pic.k = 1f;
        //}
        //if (pic.k < 0)
        //{
        //    pic.k = 0.1f;
        //}

        int width  = pic.hashed_data.GetLength(0);
        int height = pic.hashed_data.GetLength(1);
        int h      = 0;

        for (h = height - 1; h > 0; h--)
        {
            int all = 0;
            for (int w = 0; w < width; w++)
            {
                if (pic.hashed_data[w, h, 3] > 0.05f)
                {
                    all += 1;
                }
            }
            if (all * 5 > width)
            {
                break;
            }
        }
        pic.k = ((float)h) / ((float)height);
        if (pic.k > 1)
        {
            pic.k = 1f;
        }
        if (pic.k < 0)
        {
            pic.k = 0.1f;
        }
    }
    private static void LoadCloseupPicture(PictureResource pic, string path)
    {
        try
        {
            BitmapHelper bitmap = new BitmapHelper(path);
            int          left;
            int          right;
            int          up;
            int          down;
            CutTop(bitmap, out left, out right, out up, out down);
            up    = CutLeft(bitmap, up);
            down  = CutRight(bitmap, down);
            right = CutButton(bitmap, right);
            int width  = right - left;
            int height = down - up;
            pic.hashed_data = new float[width, height, 4];
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    System.Drawing.Color color = bitmap.GetPixel(left + w, up + h);
                    pic.hashed_data[w, height - h - 1, 0] = (float)color.R / 255f;
                    pic.hashed_data[w, height - h - 1, 1] = (float)color.G / 255f;
                    pic.hashed_data[w, height - h - 1, 2] = (float)color.B / 255f;
                    pic.hashed_data[w, height - h - 1, 3] = (float)color.A / 255f;
                }
            }
            float wholeUNalpha = 0;
            for (int w = 0; w < width; w++)
            {
                if (pic.hashed_data[w, 0, 3] > 0.1f)
                {
                    wholeUNalpha += ((float)Math.Abs(w - width / 2)) / ((float)(width / 2));
                }
                if (pic.hashed_data[w, height - 1, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
            }
            for (int h = 0; h < height; h++)
            {
                if (pic.hashed_data[0, h, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
                if (pic.hashed_data[width - 1, h, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
            }
            if (wholeUNalpha >= ((width + height) * 0.5f * 0.12f))
            {
                softVtype(pic, 0.7f);
            }
            caculateK(pic);

            if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
            {
                loadedList.Add(hashPic(pic.code, pic.type), pic);
            }
        }
        catch
        {
        }
    }
    private static void ProcessingVerticleDrawing(PictureResource pic)
    {
        try
        {
            string path = "picture/closeup/" + pic.code.ToString() + ".png";
            if (!File.Exists(path))
            {
#if UNITY_STANDALONE_WIN //编译器、Windows
                path = "picture/card/" + pic.code.ToString() + ".jpg";
                if (!File.Exists(path))
                {
                    path = "picture/card/" + pic.code.ToString() + ".png";
                }
                bool Iam8 = false;
                //if (!File.Exists(path))
                //{
                //    Iam8 = true;
                //    path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
                //}
                if (!File.Exists(path))
                {
                    Iam8 = true;
                    path = "expansions/pics/" + pic.code.ToString() + ".jpg";
                }
                if (!File.Exists(path))
                {
                    Iam8 = true;
                    path = "pics/" + pic.code.ToString() + ".jpg";
                }
                LoadCloseupFromCardPicture(pic, path, Iam8);
                //pic.autoMade = true;

                /*
                 *  以上处理其他平台无法正常使用
                 *  暂时只能直接贴图,以后再处理
                 */
#elif UNITY_EDITOR || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX //Android、iPhone
                if (!File.Exists(path))
                {
                    path = "picture/null.png";
                }

                byte[] data;
                using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    file.Seek(0, SeekOrigin.Begin);
                    data = new byte[file.Length];
                    file.Read(data, 0, (int)file.Length);
                }
                pic.data = data;
                if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
                {
                    loadedList.Add(hashPic(pic.code, pic.type), pic);
                }
#endif
            }
            else
            {
                LoadCloseupPicture(pic, path);
            }
        }
        catch (Exception e)
        {
            Debug.Log("e 3" + e.ToString());
        }
    }
    private static void ProcessingCardFeature(PictureResource pic)
    {
        if (loadedList.ContainsKey(hashPic(pic.code, pic.type)))
        {
            return;
        }
        bool         EightEdition = false;
        BitmapHelper bitmap       = getCloseup(pic);

        if (bitmap != null)
        {
            int left;
            int right;
            int up;
            int down;
            CutTop(bitmap, out left, out right, out up, out down);
            up    = CutLeft(bitmap, up);
            down  = CutRight(bitmap, down);
            right = CutButton(bitmap, right);
            int width  = right - left;
            int height = down - up;
            pic.hashed_data = new float[width, height, 4];
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    System.Drawing.Color color = bitmap.GetPixel(left + w, up + h);
                    float a = (float)color.A / 255f;
                    if (w < 40)
                    {
                        if (a > (float)w / (float)40)
                        {
                            a = (float)w / (float)40;
                        }
                    }
                    if (w > (width - 40))
                    {
                        if (a > 1f - (float)(w - (width - 40)) / (float)40)
                        {
                            a = 1f - (float)(w - (width - 40)) / (float)40;
                        }
                    }
                    if (h < 40)
                    {
                        if (a > (float)h / (float)40)
                        {
                            a = (float)h / (float)40;
                        }
                    }
                    if (h > (height - 40))
                    {
                        if (a > 1f - (float)(h - (height - 40)) / (float)40)
                        {
                            a = 1f - (float)(h - (height - 40)) / (float)40;
                        }
                    }
                    pic.hashed_data[w, height - h - 1, 0] = (float)color.R / 255f;
                    pic.hashed_data[w, height - h - 1, 1] = (float)color.G / 255f;
                    pic.hashed_data[w, height - h - 1, 2] = (float)color.B / 255f;
                    pic.hashed_data[w, height - h - 1, 3] = a;
                }
            }
            caculateK(pic);

            loadedList.Add(hashPic(pic.code, pic.type), pic);
        }
        else
        {
            var data = getPicture(pic, out EightEdition);
            if (data.Length == 0)
            {
                pic.hashed_data = new float[10, 10, 4];
                for (int w = 0; w < 10; w++)
                {
                    for (int h = 0; h < 10; h++)
                    {
                        pic.hashed_data[w, h, 0] = 0;
                        pic.hashed_data[w, h, 1] = 0;
                        pic.hashed_data[w, h, 2] = 0;
                        pic.hashed_data[w, h, 3] = 0;
                    }
                }
                loadedList.Add(hashPic(pic.code, pic.type), pic);
            }
            else
            {
                MemoryStream stream = new MemoryStream(data);
                bitmap          = new BitmapHelper(stream);
                pic.hashed_data = getCuttedPic(bitmap, pic.pCard, EightEdition);
                int width     = pic.hashed_data.GetLength(0);
                int height    = pic.hashed_data.GetLength(1);
                int size      = (int)(height * 0.8);
                int empWidth  = (width - size) / 2;
                int empHeight = (height - size) / 2;
                int right     = width - empWidth;
                int buttom    = height - empHeight;
                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        float a = pic.hashed_data[w, h, 3];
                        if (w < empWidth)
                        {
                            if (a > ((float)w) / (float)empWidth)
                            {
                                a = ((float)w) / (float)empWidth;
                            }
                        }
                        if (h < empHeight)
                        {
                            if (a > ((float)h) / (float)empHeight)
                            {
                                a = ((float)h) / (float)empHeight;
                            }
                        }
                        if (w > right)
                        {
                            if (a > 1f - ((float)(w - right)) / (float)empWidth)
                            {
                                a = 1f - ((float)(w - right)) / (float)empWidth;
                            }
                        }
                        if (h > buttom)
                        {
                            if (a > 1f - ((float)(h - buttom)) / (float)empHeight)
                            {
                                a = 1f - ((float)(h - buttom)) / (float)empHeight;
                            }
                        }
                        pic.hashed_data[w, h, 3] = a * 0.7f;
                    }
                }
                loadedList.Add(hashPic(pic.code, pic.type), pic);
            }
        }
    }
    private static void ProcessingCardPicture(PictureResource pic)
    {
        try
        {
            string path = "picture/card/" + pic.code.ToString() + ".jpg";
            if (!File.Exists(path))
            {
                path = "picture/card/" + pic.code.ToString() + ".png";
            }
            if (!File.Exists(path))
            {
                path = "expansions/pics/" + pic.code.ToString() + ".png";
            }
            if (!File.Exists(path))
            {
                path = "expansions/pics/" + pic.code.ToString() + ".jpg";
            }
            if (!File.Exists(path))
            {
                path = "pics/" + pic.code.ToString() + ".png";
            }
            if (!File.Exists(path))
            {
                path = "pics/" + pic.code.ToString() + ".jpg";
            }
#if UNITY_ANDROID || UNITY_IOS //Android、iPhone
            if (Program.I().setting != null)
            {
                switch (Program.I().setting.pictureDownloadVersion.value)
                {
                case "Series 10":
                {
                    path = "picture/card/" + pic.code.ToString() + ".jpg";
                    if (!File.Exists(path))
                    {
                        path = "picture/card/" + pic.code.ToString() + ".jpg";
                        if (AutoPicDownload && !File.Exists(path))
                        {
                            df.Download("https://rawcdn.githack.com/Kaiba-Corporation/ygopro-images/b8559b1/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                        }
                    }
                    break;
                }

                case "Series 10 HQ":
                {
                    path = "picture/card/" + pic.code.ToString() + ".jpg";
                    if (!File.Exists(path) && pic.code != 0 && AutoPicDownload)
                    {
                        df.Download("https://rawcdn.githack.com/Kaiba-Corporation/ygopro-images/b8559b1/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                    }
                    break;
                }

                default:
                {
                    path = "picture/card/" + pic.code.ToString() + ".jpg";
                    if (!File.Exists(path))
                    {
                        path = "picture/card/" + pic.code.ToString() + ".jpg";
                        if (AutoPicDownload && !File.Exists(path))
                        {
                            df.Download("https://rawcdn.githack.com/Kaiba-Corporation/ygopro-images/b8559b1/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                        }
                    }
                    break;
                }
                }
            }
            else
            {
                path = "picture/card/" + pic.code.ToString() + ".jpg";
                if (AutoPicDownload && !File.Exists(path))
                {
                    df.Download("https://rawcdn.githack.com/Kaiba-Corporation/ygopro-images/b8559b1/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                    path = "picture/card/" + pic.code.ToString() + ".jpg";
                }
            }

            if (!File.Exists(path) && pic.code != 0 && AutoPicDownload)
            {
                path = "picture/card/" + pic.code.ToString() + ".jpg";
                if (!File.Exists(path))
                {
                    df.Download("https://rawcdn.githack.com/Kaiba-Corporation/ygopro-images/b8559b1/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                }
            }
#endif
            if (!File.Exists(path) && pic.code != 0 && AutoPicDownload)
            {
                _basicBackgroundWorkerCardDownload.EnqueueWork(() =>
                {
                    df.Download("https://rawcdn.githack.com/Kaiba-Corporation/ygopro-images/b8559b1/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg", pic, false);
                });
                return;
            }
            LoadCardPicture(pic, path);
        }
        catch (Exception e)
        {
            Debug.Log("e 2" + e.ToString());
        }
    }
    private static void ProcessingVerticleDrawing(PictureResource pic)
    {
        if (loadedList.ContainsKey(hashPic(pic.code, pic.type)))
        {
            return;
        }
        var bitmap = getCloseup(pic);

        if (bitmap == null)
        {
            bool EightEdition;
            var  data = getPicture(pic, out EightEdition);
            if (data.Length == 0)
            {
                return;
            }
            MemoryStream stream = new MemoryStream(data);
            bitmap          = new BitmapHelper(stream);
            pic.hashed_data = getCuttedPic(bitmap, pic.pCard, EightEdition);
            softVtype(pic, 0.5f);
            pic.k = 1;
            //pic.autoMade = true;
        }
        else
        {
            int left;
            int right;
            int up;
            int down;
            CutTop(bitmap, out left, out right, out up, out down);
            up    = CutLeft(bitmap, up);
            down  = CutRight(bitmap, down);
            right = CutButton(bitmap, right);
            int width  = right - left;
            int height = down - up;
            pic.hashed_data = new float[width, height, 4];
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    System.Drawing.Color color = bitmap.GetPixel(left + w, up + h);
                    pic.hashed_data[w, height - h - 1, 0] = (float)color.R / 255f;
                    pic.hashed_data[w, height - h - 1, 1] = (float)color.G / 255f;
                    pic.hashed_data[w, height - h - 1, 2] = (float)color.B / 255f;
                    pic.hashed_data[w, height - h - 1, 3] = (float)color.A / 255f;
                }
            }
            float wholeUNalpha = 0;
            for (int w = 0; w < width; w++)
            {
                if (pic.hashed_data[w, 0, 3] > 0.1f)
                {
                    wholeUNalpha += ((float)Math.Abs(w - width / 2)) / ((float)(width / 2));
                }
                if (pic.hashed_data[w, height - 1, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
            }
            for (int h = 0; h < height; h++)
            {
                if (pic.hashed_data[0, h, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
                if (pic.hashed_data[width - 1, h, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
            }
            if (wholeUNalpha >= ((width + height) * 0.5f * 0.12f))
            {
                softVtype(pic, 0.7f);
            }
            caculateK(pic);
        }

        loadedList.Add(hashPic(pic.code, pic.type), pic);
    }
示例#21
0
    private static void ProcessingCardPicture(PictureResource pic)
    {
        try
        {
            string path = "picture/card/" + pic.code.ToString() + ".jpg";
            if (!File.Exists(path))
            {
                path = "picture/card/" + pic.code.ToString() + ".png";
            }
            if (!File.Exists(path))
            {
                path = "expansions/pics/" + pic.code.ToString() + ".png";
            }
            if (!File.Exists(path))
            {
                path = "expansions/pics/" + pic.code.ToString() + ".jpg";
            }
            if (!File.Exists(path))
            {
                path = "pics/" + pic.code.ToString() + ".png";
            }
            if (!File.Exists(path))
            {
                path = "pics/" + pic.code.ToString() + ".jpg";
            }
            //if (!File.Exists(path) && pic.code != 0)
            //{
            //    //下载卡图(177x254)
            //    //df.Download("http://android.ygopro.win/YGOMobile/pics/" + pic.code.ToString() + ".jpg", "expansions/pics/" + pic.code.ToString() + ".jpg");
            //   // path = "expansions/pics/" + pic.code.ToString() + ".jpg";
            //}
#if UNITY_ANDROID || UNITY_IOS //Android、iPhone
            if (Program.I().setting != null)
            {
                switch (Program.I().setting.pictureDownloadVersion.value)
                {
                case "Series 10":
                {
                    path = "picture/card/" + pic.code.ToString() + ".jpg";
                    if (!File.Exists(path))
                    {
                        path = "picture/card/" + pic.code.ToString() + ".jpg";
                        if (AutoPicDownload && !File.Exists(path))
                        {
                            df.Download("https://pictures.duelistsunite.org/hq/card/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                        }
                    }
                    break;
                }

                case "Anime":
                {
                    path = "picture/card-ani/" + pic.code.ToString() + ".jpg";
                    if (AutoPicDownload && !File.Exists(path))
                    {
                        df.Download("http://duelistsunite.org/picture/card-ani/" + pic.code.ToString() + ".jpg", "picture/card-ani/" + pic.code.ToString() + ".jpg");
                        if (!File.Exists(path))
                        {
                            path = "picture/card/" + pic.code.ToString() + ".jpg";
                            if (!File.Exists(path))
                            {
                                df.Download("https://pictures.duelistsunite.org/hq/card/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                            }
                        }
                    }

                    break;
                }

                case "Series 10 HQ":
                {
                    path = "picture/card/" + pic.code.ToString() + ".jpg";
                    if (!File.Exists(path) && pic.code != 0 && AutoPicDownload)
                    {
                        df.Download("https://pictures.duelistsunite.org/hq/card/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
            else
            {
                path = "picture/card/" + pic.code.ToString() + ".jpg";
                if (AutoPicDownload && !File.Exists(path))
                {
                    df.Download("https://pictures.duelistsunite.org/hq/card/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                    path = "picture/card/" + pic.code.ToString() + ".jpg";
                }
            }

            if (!File.Exists(path) && pic.code != 0 && AutoPicDownload)
            {
                path = "picture/card/" + pic.code.ToString() + ".jpg";
                if (!File.Exists(path))
                {
                    df.Download("https://pictures.duelistsunite.org/hq/card/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg");
                }
            }
#endif
            if (!File.Exists(path) && pic.code != 0 && AutoPicDownload)
            {
                _basicBackgroundWorkerCardDownload.EnqueueWork(() =>
                {
                    df.Download("https://pictures.duelistsunite.org/hq/card/" + pic.code.ToString() + ".jpg", "picture/card/" + pic.code.ToString() + ".jpg", pic, false);
                });
                return;
            }
            //if (!File.Exists(path) && pic.code != 0)
            //{
            //    //下载先行卡卡图(336x490)
            //    //df.Download("http://update.ygopro.win/ygopro2-data/expansions/pics/" + pic.code.ToString() + ".jpg", "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg");
            //    //path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
            //}
            LoadCardPicture(pic, path);
        }
        catch (Exception e)
        {
            Debug.Log("e 2" + e.ToString());
        }
    }
示例#22
0
    private static void LoadCloseupPicture(PictureResource pic, string path)
    {
        try
        {
#if UNITY_EDITOR || UNITY_STANDALONE_WIN //编译器、Windows
            BitmapHelper bitmap = new BitmapHelper(path);
            int          left;
            int          right;
            int          up;
            int          down;
            CutTop(bitmap, out left, out right, out up, out down);
            up    = CutLeft(bitmap, up);
            down  = CutRight(bitmap, down);
            right = CutButton(bitmap, right);
            int width  = right - left;
            int height = down - up;
            pic.hashed_data = new float[width, height, 4];
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    System.Drawing.Color color = bitmap.GetPixel(left + w, up + h);
                    pic.hashed_data[w, height - h - 1, 0] = (float)color.R / 255f;
                    pic.hashed_data[w, height - h - 1, 1] = (float)color.G / 255f;
                    pic.hashed_data[w, height - h - 1, 2] = (float)color.B / 255f;
                    pic.hashed_data[w, height - h - 1, 3] = (float)color.A / 255f;
                }
            }
            float wholeUNalpha = 0;
            for (int w = 0; w < width; w++)
            {
                if (pic.hashed_data[w, 0, 3] > 0.1f)
                {
                    wholeUNalpha += ((float)Math.Abs(w - width / 2)) / ((float)(width / 2));
                }
                if (pic.hashed_data[w, height - 1, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
            }
            for (int h = 0; h < height; h++)
            {
                if (pic.hashed_data[0, h, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
                if (pic.hashed_data[width - 1, h, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
            }
            if (wholeUNalpha >= ((width + height) * 0.5f * 0.12f))
            {
                softVtype(pic, 0.7f);
            }
            caculateK(pic);

            /*
             *  以上处理其他平台无法正常使用
             *  暂时只能直接贴图,以后再处理
             */
#elif UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX //Android、iPhone
            byte[] data;
            using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                file.Seek(0, SeekOrigin.Begin);
                data = new byte[file.Length];
                file.Read(data, 0, (int)file.Length);
            }
            pic.data = data;
#endif
            if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
            {
                loadedList.Add(hashPic(pic.code, pic.type), pic);
            }
        }
        catch
        {
        }
    }
        /// <summary>
        /// Execute the specified picture resource.
        /// </summary>
        /// <param name="resource">Picture to execute.</param>
        /// <param name="renderer">Picture renderer.</param>
        public void Execute(PictureResource resource, PictureRenderer renderer)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            this.Renderer = renderer ?? throw new ArgumentNullException(nameof(renderer));
            this.pattern  = 0;

            byte[] pictureData = resource.Data;
            int    offset      = 0;

            while (offset < pictureData.Length && pictureData[offset] != PictureCode.End)
            {
                byte instruction = pictureData[offset];
                offset++;

                switch (instruction)
                {
                case PictureCode.VisualEnabled:
                    this.Renderer.VisualEnabled = true;
                    this.Renderer.VisualColor   = pictureData[offset];
                    offset++;
                    break;

                case PictureCode.VisualDisabled:
                    this.Renderer.VisualEnabled = false;
                    break;

                case PictureCode.PriorityEnabled:
                    this.Renderer.PriorityEnabled = true;
                    this.Renderer.PriorityColor   = pictureData[offset];
                    offset++;
                    break;

                case PictureCode.PriorityDisabled:
                    this.Renderer.PriorityEnabled = false;
                    break;

                case PictureCode.YCorner:
                    offset = this.ReadYCorner(pictureData, offset);
                    break;

                case PictureCode.XCorner:
                    offset = this.ReadXCorner(pictureData, offset);
                    break;

                case PictureCode.AbsoluteLine:
                    offset = this.ReadAbsoluteLine(pictureData, offset);
                    break;

                case PictureCode.RelativeLine:
                    offset = this.ReadRelativeLine(pictureData, offset);
                    break;

                case PictureCode.Fill:
                    offset = this.ReadFill(pictureData, offset);
                    break;

                case PictureCode.Pattern:
                    this.pattern = pictureData[offset];
                    offset++;
                    break;

                case PictureCode.Brush:
                    offset = this.ReadBrush(pictureData, offset);
                    break;

                default:
                    break;
                }
            }
        }
示例#24
0
    private static void ProcessingVerticleDrawing(PictureResource pic)
    {
        string path = "picture\\closeup\\" + pic.code.ToString() + ".png";

        if (!File.Exists(path))
        {
            path = "picture\\card\\" + pic.code.ToString() + ".png";
            if (!File.Exists(path))
            {
                path = "picture\\card\\" + pic.code.ToString() + ".jpg";
            }
            bool Iam8 = false;
            if (!File.Exists(path))
            {
                Iam8 = true;
                path = "picture\\cardIn8thEdition\\" + pic.code.ToString() + ".jpg";
            }
            if (!File.Exists(path))
            {
                path = "texture/duel/unknown.jpg";
            }
            if (!File.Exists(path))
            {
                return;
            }
            pic.hashed_data = getCuttedPic(path, pic.pCard, Iam8);
            softVtype(pic, 0.5f);
            pic.k = 1;
            //pic.autoMade = true;
        }
        else
        {
            BitmapHelper bitmap = new BitmapHelper(path);
            int          left;
            int          right;
            int          up;
            int          down;
            CutTop(bitmap, out left, out right, out up, out down);
            up    = CutLeft(bitmap, up);
            down  = CutRight(bitmap, down);
            right = CutButton(bitmap, right);
            int width  = right - left;
            int height = down - up;
            pic.hashed_data = new float[width, height, 4];
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    System.Drawing.Color color = bitmap.GetPixel(left + w, up + h);
                    pic.hashed_data[w, height - h - 1, 0] = (float)color.R / 255f;
                    pic.hashed_data[w, height - h - 1, 1] = (float)color.G / 255f;
                    pic.hashed_data[w, height - h - 1, 2] = (float)color.B / 255f;
                    pic.hashed_data[w, height - h - 1, 3] = (float)color.A / 255f;
                }
            }
            float wholeUNalpha = 0;
            for (int w = 0; w < width; w++)
            {
                if (pic.hashed_data[w, 0, 3] > 0.1f)
                {
                    wholeUNalpha += ((float)Math.Abs(w - width / 2)) / ((float)(width / 2));
                }
                if (pic.hashed_data[w, height - 1, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
            }
            for (int h = 0; h < height; h++)
            {
                if (pic.hashed_data[0, h, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
                if (pic.hashed_data[width - 1, h, 3] > 0.1f)
                {
                    wholeUNalpha += 1;
                }
            }
            if (wholeUNalpha >= ((width + height) * 0.5f * 0.12f))
            {
                softVtype(pic, 0.7f);
            }
            caculateK(pic);
        }

        if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
        {
            loadedList.Add(hashPic(pic.code, pic.type), pic);
        }
    }
示例#25
0
    private static void softVtype(PictureResource pic, float si)
    {
        int   width     = pic.hashed_data.GetLength(0);
        int   height    = pic.hashed_data.GetLength(1);
        int   size      = (int)(height * si);
        int   empWidth  = (width - size) / 2;
        int   empHeight = (height - size) / 2;
        int   right     = width - empWidth;
        int   buttom    = height - empHeight;
        float dui       = (float)Math.Sqrt((width / 2) * (width / 2) + (height / 2) * (height / 2));

        for (int w = 0; w < width; w++)
        {
            for (int h = 0; h < height; h++)
            {
                float a = pic.hashed_data[w, h, 3];

                if (h < height / 2)
                {
                    float l = (float)Math.Sqrt((width / 2 - w) * (width / 2 - w) + (height / 2 - h) * (height / 2 - h));
                    l -= width * 0.3f;
                    if (l < 0)
                    {
                        l = 0;
                    }
                    float alpha = 1f - l / (0.6f * (dui - width * 0.3f));
                    if (alpha < 0)
                    {
                        alpha = 0;
                    }
                    if (a > alpha)
                    {
                        a = alpha;
                    }
                }

                if (w < empWidth)
                {
                    if (a > ((float)w) / (float)empWidth)
                    {
                        a = ((float)w) / (float)empWidth;
                    }
                }
                if (h < empHeight)
                {
                    if (a > ((float)h) / (float)empHeight)
                    {
                        a = ((float)h) / (float)empHeight;
                    }
                }
                if (w > right)
                {
                    if (a > 1f - ((float)(w - right)) / (float)empWidth)
                    {
                        a = 1f - ((float)(w - right)) / (float)empWidth;
                    }
                }
                if (h > buttom)
                {
                    if (a > 1f - ((float)(h - buttom)) / (float)empHeight)
                    {
                        a = 1f - ((float)(h - buttom)) / (float)empHeight;
                    }
                }
                pic.hashed_data[w, h, 3] = a;
            }
        }
    }
示例#26
0
    private static void ProcessingCardFeature(PictureResource pic)
    {
        try
        {
            if (File.Exists("picture/closeup/" + pic.code.ToString() + ".png"))
            {
                string path = "picture/closeup/" + pic.code.ToString() + ".png";
#if UNITY_EDITOR || UNITY_STANDALONE_WIN //编译器、Windows
                BitmapHelper bitmap = new BitmapHelper(path);
                int          left;
                int          right;
                int          up;
                int          down;
                CutTop(bitmap, out left, out right, out up, out down);
                up    = CutLeft(bitmap, up);
                down  = CutRight(bitmap, down);
                right = CutButton(bitmap, right);
                int width  = right - left;
                int height = down - up;
                pic.hashed_data = new float[width, height, 4];
                for (int w = 0; w < width; w++)
                {
                    for (int h = 0; h < height; h++)
                    {
                        System.Drawing.Color color = bitmap.GetPixel(left + w, up + h);
                        float a = (float)color.A / 255f;
                        if (w < 40)
                        {
                            if (a > (float)w / (float)40)
                            {
                                a = (float)w / (float)40;
                            }
                        }
                        if (w > (width - 40))
                        {
                            if (a > 1f - (float)(w - (width - 40)) / (float)40)
                            {
                                a = 1f - (float)(w - (width - 40)) / (float)40;
                            }
                        }
                        if (h < 40)
                        {
                            if (a > (float)h / (float)40)
                            {
                                a = (float)h / (float)40;
                            }
                        }
                        if (h > (height - 40))
                        {
                            if (a > 1f - (float)(h - (height - 40)) / (float)40)
                            {
                                a = 1f - (float)(h - (height - 40)) / (float)40;
                            }
                        }
                        pic.hashed_data[w, height - h - 1, 0] = (float)color.R / 255f;
                        pic.hashed_data[w, height - h - 1, 1] = (float)color.G / 255f;
                        pic.hashed_data[w, height - h - 1, 2] = (float)color.B / 255f;
                        pic.hashed_data[w, height - h - 1, 3] = a;
                    }
                }
                caculateK(pic);

                /*
                 *  以上处理其他平台无法正常使用
                 *  暂时只能直接贴图,以后再处理
                 */
#elif UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX//Android、iPhone
                byte[] data;
                using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    file.Seek(0, SeekOrigin.Begin);
                    data = new byte[file.Length];
                    file.Read(data, 0, (int)file.Length);
                }
                pic.data = data;
#endif

                if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
                {
                    loadedList.Add(hashPic(pic.code, pic.type), pic);
                }
            }
            else
            {
                string path = "picture/card/" + pic.code.ToString() + ".jpg";
                if (!File.Exists(path))
                {
                    path = "picture/card/" + pic.code.ToString() + ".png";
                }
                if (!File.Exists(path))
                {
                    path = "expansions/pics/" + pic.code.ToString() + ".jpg";
                }
                if (!File.Exists(path))
                {
                    path = "pics/" + pic.code.ToString() + ".jpg";
                }
                if (!File.Exists(path))
                {
                    pic.hashed_data = new float[10, 10, 4];
                    for (int w = 0; w < 10; w++)
                    {
                        for (int h = 0; h < 10; h++)
                        {
                            pic.hashed_data[w, h, 0] = 0;
                            pic.hashed_data[w, h, 1] = 0;
                            pic.hashed_data[w, h, 2] = 0;
                            pic.hashed_data[w, h, 3] = 0;
                        }
                    }
                    if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
                    {
                        loadedList.Add(hashPic(pic.code, pic.type), pic);
                    }
                }
                else
                {
                    pic.hashed_data = getCuttedPic(path, pic.pCard, false);
                    int width     = pic.hashed_data.GetLength(0);
                    int height    = pic.hashed_data.GetLength(1);
                    int size      = (int)(height * 0.8);
                    int empWidth  = (width - size) / 2;
                    int empHeight = (height - size) / 2;
                    int right     = width - empWidth;
                    int buttom    = height - empHeight;
                    for (int w = 0; w < width; w++)
                    {
                        for (int h = 0; h < height; h++)
                        {
                            float a = pic.hashed_data[w, h, 3];
                            if (w < empWidth)
                            {
                                if (a > ((float)w) / (float)empWidth)
                                {
                                    a = ((float)w) / (float)empWidth;
                                }
                            }
                            if (h < empHeight)
                            {
                                if (a > ((float)h) / (float)empHeight)
                                {
                                    a = ((float)h) / (float)empHeight;
                                }
                            }
                            if (w > right)
                            {
                                if (a > 1f - ((float)(w - right)) / (float)empWidth)
                                {
                                    a = 1f - ((float)(w - right)) / (float)empWidth;
                                }
                            }
                            if (h > buttom)
                            {
                                if (a > 1f - ((float)(h - buttom)) / (float)empHeight)
                                {
                                    a = 1f - ((float)(h - buttom)) / (float)empHeight;
                                }
                            }
                            pic.hashed_data[w, h, 3] = a * 0.7f;
                        }
                    }
                    if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
                    {
                        loadedList.Add(hashPic(pic.code, pic.type), pic);
                    }
                }
            }
        }
        catch (Exception e)
        {
            Debug.Log("e 1" + e.ToString());
        }
    }
示例#27
0
 public static Texture2D get(long code, GameTextureType type, Texture2D nullReturnValue = null)
 {
     try
     {
         PictureResource r;
         if (loadedList.TryGetValue(hashPic(code, type), out r))
         {
             Texture2D re = null;
             if (r.u_data != null)
             {
                 if (r.u_data == myBack)
                 {
                     return(nullReturnValue);
                 }
                 else
                 {
                     return(r.u_data);
                 }
             }
             if (r.data != null)
             {
                 re = new Texture2D(400, 600);
                 re.LoadImage(r.data);
                 r.u_data = re;
                 return(re);
             }
             if (r.hashed_data != null)
             {
                 int width  = r.hashed_data.GetLength(0);
                 int height = r.hashed_data.GetLength(1);
                 UnityEngine.Color[] cols = new UnityEngine.Color[width * height];
                 re = new Texture2D(width, height);
                 for (int h = 0; h < height; h++)
                 {
                     for (int w = 0; w < width; w++)
                     {
                         cols[h * width + w] = new UnityEngine.Color(r.hashed_data[w, h, 0], r.hashed_data[w, h, 1], r.hashed_data[w, h, 2], r.hashed_data[w, h, 3]);
                     }
                 }
                 re.SetPixels(0, 0, width, height, cols);
                 re.Apply();
                 r.u_data = re;
                 return(re);
             }
         }
         else
         {
             if (!addedMap.ContainsKey(hashPic(code, type)))
             {
                 PictureResource a = new PictureResource(type, code, nullReturnValue);
                 bLock = true;
                 waitLoadStack.Push(a);
                 bLock = false;
                 addedMap.Add((UInt64)type << 32 | (UInt64)code, true);
             }
         }
     }
     catch (Exception e)
     {
         Debug.Log("BIGERROR1:" + e.ToString());
     }
     return(null);
 }
示例#28
0
    private static void ProcessingVerticleDrawing(PictureResource pic)
    {
        try
        {
            string path = "picture/closeup/" + pic.code.ToString() + ".png";
#if UNITY_ANDROID || UNITY_IOS //Android、iPhone
            if (!File.Exists(path) && AutoPicDownload && Program.I().setting.pictureDownloadVersion.value != "Series 10 HQ")
            {
                df.Download("https://pictures.duelistsunite.org/lq/closeup/" + pic.code.ToString() + ".png", "picture/closeup/" + pic.code.ToString() + ".png");
            }
#endif
            if (!File.Exists(path) && AutoPicDownload)
            {
                _basicBackgroundWorkerCloseupDownload.EnqueueWork(() =>
                {
                    df.Download("https://pictures.duelistsunite.org/hq/closeup/" + pic.code.ToString() + ".png", "picture/closeup/" + pic.code.ToString() + ".png", pic, false);
                });
                return;
            }
            if (!File.Exists(path))
            {
#if UNITY_EDITOR || UNITY_STANDALONE_WIN //编译器、Windows
                path = "picture/card/" + pic.code.ToString() + ".jpg";
                if (!File.Exists(path))
                {
                    path = "picture/card/" + pic.code.ToString() + ".png";
                }
                bool Iam8 = false;
                //if (!File.Exists(path))
                //{
                //    Iam8 = true;
                //    path = "picture/cardIn8thEdition/" + pic.code.ToString() + ".jpg";
                //}
                if (!File.Exists(path))
                {
                    Iam8 = true;
                    path = "expansions/pics/" + pic.code.ToString() + ".jpg";
                }
                if (!File.Exists(path))
                {
                    Iam8 = true;
                    path = "pics/" + pic.code.ToString() + ".jpg";
                }
                LoadCloseupFromCardPicture(pic, path, Iam8);
                //pic.autoMade = true;

                /*
                 *  以上处理其他平台无法正常使用
                 *  暂时只能直接贴图,以后再处理
                 */
#elif UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX //Android、iPhone
                if (!File.Exists(path))
                {
                    path = "picture/null.png";
                }

                byte[] data;
                using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    file.Seek(0, SeekOrigin.Begin);
                    data = new byte[file.Length];
                    file.Read(data, 0, (int)file.Length);
                }
                pic.data = data;
                if (!loadedList.ContainsKey(hashPic(pic.code, pic.type)))
                {
                    loadedList.Add(hashPic(pic.code, pic.type), pic);
                }
#endif
            }
            else
            {
                LoadCloseupPicture(pic, path);
            }
        }
        catch (Exception e)
        {
            Debug.Log("e 3" + e.ToString());
        }
    }