Beispiel #1
0
        public Texture2D GetCachedTexture(string url)
        {
            string             key = CFileManager.GetMd5(url.ToLower());
            CCachedTextureInfo cachedTextureInfo = this.m_cachedTextureInfoSet.GetCachedTextureInfo(key);

            if (cachedTextureInfo != null)
            {
                TimeSpan span = (TimeSpan)(DateTime.Now - cachedTextureInfo.m_lastModifyTime);
                if (span.TotalDays < 2.0)
                {
                    string filePath = CFileManager.CombinePath(s_cachedTextureDirectory, key + ".bytes");
                    if (!CFileManager.IsFileExist(filePath))
                    {
                        return(null);
                    }
                    byte[] buffer = CFileManager.ReadFile(filePath);
                    if ((buffer == null) || (buffer.Length <= 0))
                    {
                        return(null);
                    }
                    Texture2D textured = null;
                    if (cachedTextureInfo.m_isGif)
                    {
                        using (MemoryStream stream = new MemoryStream(buffer))
                        {
                            return(GifHelper.GifToTexture(stream, 0));
                        }
                    }
                    textured = new Texture2D(cachedTextureInfo.m_width, cachedTextureInfo.m_height, TextureFormat.ARGB32, false);
                    textured.LoadImage(buffer);
                    return(textured);
                }
            }
            return(null);
        }
Beispiel #2
0
    void Start()
    {
        string path = @"F:\JoeWorkspace\UnityWorkspace\learn_wangzherongyao_code\Assets\Gif_moudle\tuzi.gif";

        byte[]    array     = File.ReadAllBytes(path);// CFileManager.ReadFile(path);
        Texture2D texture2D = null;

        using (MemoryStream memoryStream = new MemoryStream(array))
        {
            rawImage.texture = GifHelper.GifToTexture(memoryStream, 0);
        }
    }
Beispiel #3
0
        public Texture2D GetCachedTexture(string url, float validDays)
        {
            string             md = CFileManager.GetMd5(url.ToLower());
            CCachedTextureInfo cachedTextureInfo = this.m_cachedTextureInfoSet.GetCachedTextureInfo(md);

            if (cachedTextureInfo == null || (DateTime.get_Now() - cachedTextureInfo.m_lastModifyTime).get_TotalDays() >= (double)validDays)
            {
                return(null);
            }
            string text = CFileManager.CombinePath(CCachedTextureManager.s_cachedTextureDirectory, md + ".bytes");

            if (!CFileManager.IsFileExist(text))
            {
                return(null);
            }
            byte[] array = CFileManager.ReadFile(text);
            if (array == null || array.Length <= 0)
            {
                return(null);
            }
            Texture2D texture2D = null;

            if (cachedTextureInfo.m_isGif)
            {
                using (MemoryStream memoryStream = new MemoryStream(array))
                {
                    texture2D = GifHelper.GifToTexture(memoryStream, 0);
                }
            }
            else
            {
                texture2D = new Texture2D(cachedTextureInfo.m_width, cachedTextureInfo.m_height, TextureFormat.ARGB32, false);
                texture2D.LoadImage(array);
            }
            return(texture2D);
        }