Exemple #1
0
    IEnumerator GifSetterCoroutine(string url, int orderInLayer = 0)
    {
        m_gifIsLoaded = false;

        m_gifSpriteList.Clear();

        if (GifPreLoader.instance.MustPreload())
        {
            List <GifSprite> currentGifSprite = GifPreLoader.instance.GetSpriteList(url);

            if (currentGifSprite != null)
            {
                m_gifSpriteList = currentGifSprite;
            }
        }

        if (m_gifSpriteList.Count == 0)
        {
            List <UniGif.GifTexture> gifTextureList = new List <UniGif.GifTexture> ();

            int loop;
            int width;
            int height;

            Debug.Log("Gif URL: " + url);
#if UNITY_WEBGL
            WWW www = new WWW(url);
#else
            WWW www = new WWW(/*"file:///" +*/ url);
#endif

            while (!www.isDone)
            {
                yield return(null);
            }

            if (www.error != null)
            {
                GenericLog.Log(www.error);
            }

            gifTextureList = UniGif.GetTextureList(www.bytes, out loop, out width, out height, FilterMode.Bilinear);

            //List<GifSprite> gifSpriteList = new List<GifSprite>();

            foreach (UniGif.GifTexture gifTexture in gifTextureList)
            {
                GifSprite currentGifSprite = new GifSprite();

                Rect rect = new Rect();
                rect.center = new Vector2(0, 0);
                rect.height = height;
                rect.width  = width;

                currentGifSprite.delaySec = gifTexture.delaySec;
                currentGifSprite.sprite   = Sprite.Create(gifTexture.texture2d, rect, new Vector2(0.5f, 0.5f), 1.0f);
                //currentGifSprite.orderInLayer = orderInLayer;
                if (m_url.Contains(LAYER_STRING))
                {
                    Debug.Log("LAYER " + m_url.Substring(m_url.IndexOf(LAYER_STRING) + LAYER_STRING.Length, 1));
                    int order = int.Parse(m_url.Substring(m_url.IndexOf(LAYER_STRING) + LAYER_STRING.Length, 1));
                    currentGifSprite.orderInLayer = order;
                }
                else
                {
                    currentGifSprite.orderInLayer = gifOrderInLayer;
                    gifOrderInLayer++;
                }



                m_gifSpriteList.Add(currentGifSprite);

                yield return(null);
            }

            if (GifPreLoader.instance.MustPreload())
            {
                GifPreLoader.instance.SetNewGifSpriteList(url, m_gifSpriteList);
            }
        }

        m_isSpriteStopList.Clear();

        for (int i = 0; i < m_gifSpriteList.Count; ++i)
        {
            m_isSpriteStopList.Add(false);
        }

        //	UnableClickByClick();

        m_gifIsLoaded = true;
    }
Exemple #2
0
    /// <summary>
    /// Set GIF texture from url
    /// </summary>
    /// <param name="url">GIF image url (WEB or StreamingAssets path)</param>
    /// <param name="autoPlay">Auto play after decode</param>
    /// <returns>IEnumerator</returns>
    public IEnumerator SetGifFromUrlCoroutine(string url, bool autoPlay = true)
    {
        if (gifTextAsset != null)
        {
            if (gifTexList.Count != 0 && rawImage != null)
            {
                rawImage.texture = gifTexList[0].texture2d;
            }

            yield return(StartCoroutine(UniGif.GetTextureListCoroutine(this, gifTextAsset.bytes, gifTextAsset.GetInstanceID(), gifTexList, (gtList, loop, w, h) =>
            {
                gifTexList = gtList;
                FinishedGetTextureList(loop, w, h, autoPlay);
            }, filterMode, wrapMode, outputDebugLog)));

            yield break;
        }

        if (string.IsNullOrEmpty(url))
        {
            Debug.LogError("URL is nothing.");
            yield break;
        }

        loading = true;

        string path;

        if (url.StartsWith("http"))
        {
            // from WEB
            path = url;
        }
        else
        {
            // from StreamingAssets
            path = System.IO.Path.Combine("file:///" + Application.streamingAssetsPath, url);
        }

        // Load file
        using (WWW www = new WWW(path)) {
            yield return(www);

            if (string.IsNullOrEmpty(www.error) == false)
            {
                Debug.LogError("File load error.\n" + www.error);
            }
            else
            {
                gifTexList.Clear();

                // Get GIF textures
                if (useCoroutineGetTexture)
                {
                    // use coroutine (avoid lock up but more slow)
                    yield return(StartCoroutine(UniGif.GetTextureListCoroutine(this, www.bytes, (gtList, loop, w, h) => {
                        gifTexList = gtList;
                        FinishedGetTextureList(loop, w, h, autoPlay);
                    }, filterMode, wrapMode, outputDebugLog)));
                }
                else
                {
                    // dont use coroutine (there is a possibility of lock up)
                    int loop, w, h;
                    gifTexList = UniGif.GetTextureList(www.bytes, out loop, out w, out h, filterMode, wrapMode, outputDebugLog);
                    FinishedGetTextureList(loop, w, h, autoPlay);
                }
            }
        }
    }
    /// <summary>
    /// Set GIF texture from url
    /// </summary>
    /// <param name="url">GIF image url (WEB or StreamingAssets path)</param>
    /// <param name="autoPlay">Auto play after decode</param>
    /// <returns>IEnumerator</returns>
    public IEnumerator SetGifFromUrlCoroutine(string url, bool autoPlay = true)
    {
        if (string.IsNullOrEmpty(url))
        {
            Debug.LogError("URL is nothing.");
            yield break;
        }

        loading = true;

        string path;

        if (url.StartsWith("http"))
        {
            // from WEB
            path = url;
        }
        else
        {
            // from StreamingAssets
            path =
#if true
#if UNITY_ANDROID && !UNITY_EDITOR
                System.IO.Path.Combine(Application.streamingAssetsPath, url);
            //"jar:file://" + Application.dataPath + "!/assets/" + flodername + "/";
#elif UNITY_IPHONE && !UNITY_EDITOR
                System.IO.Path.Combine("file://" + Application.streamingAssetsPath, url);
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR
                System.IO.Path.Combine("file:///" + Application.streamingAssetsPath, url);
#else
                string.Empty;
#endif
#endif
        }

        // Load file
        using (WWW www = new WWW(path)) {
            yield return(www);

            if (string.IsNullOrEmpty(www.error) == false)
            {
                Debug.LogError("File load error.\n" + www.error);
            }
            else
            {
                gifTexList.Clear();

                // Get GIF textures
                if (useCoroutineGetTexture)
                {
                    // use coroutine (avoid lock up but more slow)
                    yield return(StartCoroutine(UniGif.GetTextureListCoroutine(this, www.bytes, (gtList, loop, w, h) => {
                        gifTexList = gtList;
                        FinishedGetTextureList(loop, w, h, autoPlay);
                    }, filterMode, wrapMode, outputDebugLog)));
                }
                else
                {
                    // dont use coroutine (there is a possibility of lock up)
                    int loop, w, h;
                    gifTexList = UniGif.GetTextureList(www.bytes, out loop, out w, out h, filterMode, wrapMode, outputDebugLog);
                    FinishedGetTextureList(loop, w, h, autoPlay);
                }
            }
        }
    }