Exemplo n.º 1
0
 /// <summary>
 /// Finished UniGif.GetTextureList or UniGif.GetTextureListCoroutine
 /// </summary>
 private void FinishedGetTextureList(int loop, int w, int h, bool autoPlay)
 {
     m_loading = false;
     loopCount = loop;
     width = w;
     height = h;
     state = State.Ready;
     if (m_rotateOnLoading)
     {
         transform.localEulerAngles = Vector3.zero;
     }
     if (autoPlay)
     {
         // Start GIF animation
         StartCoroutine(GifLoopCoroutine());
     }
     // fix aspect ratio
     m_imgAspectCtrl.FixAspectRatio(width, height);
 }
Exemplo n.º 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 (string.IsNullOrEmpty(url))
            {
                Debug.LogError("URL is nothing.");
                yield break;
            }

            if (nowState == State.Loading)
            {
                Debug.LogWarning("Already loading.");
                yield break;
            }
            nowState = State.Loading;

            string path;

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

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

                if (string.IsNullOrEmpty(www.error) == false)
                {
                    Debug.LogError("File load error.\n" + www.error);
                    nowState = State.None;
                    yield break;
                }

                Clear();
                nowState = State.Loading;

                // Get GIF textures
                www.downloadHandler = new DownloadHandlerBuffer();
                yield return(www.SendWebRequest());

                yield return(StartCoroutine(UniGif.GetTextureListCoroutine(www.downloadHandler.data, (gifTexList, loopCount, width, height) =>
                {
                    if (gifTexList != null)
                    {
                        m_gifTextureList = gifTexList;
                        this.loopCount = loopCount;
                        this.width = width;
                        this.height = height;
                        nowState = State.Ready;

                        m_imgAspectCtrl.FixAspectRatio(width, height);

                        if (m_rotateOnLoading)
                        {
                            transform.localEulerAngles = Vector3.zero;
                        }

                        if (autoPlay)
                        {
                            Play();
                        }
                    }
                    else
                    {
                        Debug.LogError("Gif texture get error.");
                        nowState = State.None;
                    }
                },
                                                                           m_filterMode, m_wrapMode, m_outputDebugLog)));
            }
        }