Exemple #1
0
        private IEnumerator Animate(Gif gif, int index)
        {
            var texture = gif.Frames[index].Texture;

            GetComponent <Image>().sprite = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f);

            if (gif.Frames.Count == 1)
            {
                yield break;
            }

            var delay = gif.Frames[index].Delay;

            if (delay < 0.02f)             // Chrome browser behaviour
            {
                delay = 0.1f;
            }

            yield return(new WaitForSeconds(delay));

            if (++index == gif.Frames.Count)
            {
                index = 0;
            }

            StartCoroutine(Animate(gif, index));
        }
 /// <summary>
 /// Convert PowerGif.Gif to SimpleGif.Gif.
 /// </summary>
 public static SimpleGif.Gif Convert(Gif gif)
 {
     return(new SimpleGif.Gif(Converter.ConvertFrames(gif.Frames)));
 }
Exemple #3
0
 /// <summary>
 /// Play GIF.
 /// </summary>
 public void Play(Gif gif)
 {
     Gif = gif;
     StartCoroutine(Animate(Gif, 0));
 }
Exemple #4
0
 public IEnumerator ExPlay(Gif gif)
 {
     Gif = gif;
     StopAllCoroutines();
     yield return(StartCoroutine(Animate(Gif, 0)));
 }