Exemplo n.º 1
0
    static IEnumerator Loading(Bitmap baseimage)
    {
        TextureInfo ti = null;
        FileInfo    fi = new FileInfo(baseimage.path);

        if (fi.Exists)
        {
            FileStream fs       = fi.OpenRead();
            var        filesize = fs.Length;
            byte[]     content  = new byte[filesize];

            var async = fs.BeginRead(content, 0, (int)filesize, null, null);
            while (!async.IsCompleted)
            {
                yield return(null);
            }

            //TextureFormat format = TextureFormat.RGB24;
            TextureFormat format = TextureFormat.DXT1;
            if (uEmuera.Utils.GetSuffix(baseimage.path).ToLower() == "png")
            {
                format = TextureFormat.DXT5;
            }
            //format = TextureFormat.ARGB32;

            var tex = new Texture2D(4, 4, format, false);
            if (tex.LoadImage(content))
            {
                ti = new TextureInfo(baseimage.filename, tex);
                texture_dict.Add(baseimage.filename, ti);

                baseimage.size.Width  = tex.width;
                baseimage.size.Height = tex.height;
            }
        }
        List <CallbackInfo> list = null;

        if (loading_set.TryGetValue(baseimage.filename, out list))
        {
            var          count = list.Count;
            CallbackInfo item  = null;
            for (int i = 0; i < count; ++i)
            {
                item = list[i];
                item.DoCallback(GetSpriteInfo(ti, item.src));
            }
            list.Clear();
            loading_set.Remove(baseimage.filename);
        }
    }
Exemplo n.º 2
0
    static IEnumerator Loading(Bitmap baseimage)
    {
        TextureInfo ti = null;
        FileInfo    fi = new FileInfo(baseimage.path);

        if (fi.Exists)
        {
            FileStream fs       = fi.OpenRead();
            var        filesize = fs.Length;
            byte[]     content  = new byte[filesize];

            var async = fs.BeginRead(content, 0, (int)filesize, null, null);
            while (!async.IsCompleted)
            {
                yield return(null);
            }

            TextureFormat format = TextureFormat.DXT1;

            var extname = uEmuera.Utils.GetSuffix(baseimage.path).ToLower();
            if (extname == "png")
            {
                format = TextureFormat.DXT5;
            }

            if (extname == "webp")
            {
                var tex = Texture2DExt.CreateTexture2DFromWebP(content, false, false,
                                                               out Error err);
                if (err != Error.Success)
                {
                    Debug.LogWarning($"{baseimage.path} {err.ToString()}");
                    yield break;
                }
                ti = new TextureInfo(baseimage.filename, tex);
                texture_dict.Add(baseimage.filename, ti);

                baseimage.size.Width  = tex.width;
                baseimage.size.Height = tex.height;
            }
            else
            {
                var tex = new Texture2D(4, 4, format, false);
                if (tex.LoadImage(content))
                {
                    ti = new TextureInfo(baseimage.filename, tex);
                    texture_dict.Add(baseimage.filename, ti);

                    baseimage.size.Width  = tex.width;
                    baseimage.size.Height = tex.height;
                }
            }
        }
        List <CallbackInfo> list = null;

        if (loading_set.TryGetValue(baseimage.filename, out list))
        {
            var          count = list.Count;
            CallbackInfo item  = null;
            for (int i = 0; i < count; ++i)
            {
                item = list[i];
                item.DoCallback(GetSpriteInfo(ti, item.src));
            }
            list.Clear();
            loading_set.Remove(baseimage.filename);
        }
    }