public IEnumerator OnSingleImageCached(byte[] bytes, string id, bool isAnimated, Action <EnhancedImageInfo> Finally = null, int forcedHeight = -1) { if (bytes.Length == 0) { Finally(null); yield break; } Sprite sprite = null; int spriteWidth = 0, spriteHeight = 0; AnimationControllerData animControllerData = null; if (isAnimated) { AnimationLoader.Process(AnimationType.GIF, bytes, (tex, atlas, delays, width, height) => { animControllerData = AnimationController.instance.Register(id, tex, atlas, delays); sprite = animControllerData.sprite; spriteWidth = width; spriteHeight = height; }); yield return(new WaitUntil(() => animControllerData != null)); } else { try { sprite = GraphicUtils.LoadSpriteRaw(bytes); spriteWidth = sprite.texture.width; spriteHeight = sprite.texture.height; } catch (Exception ex) { Logger.log.Error(ex); sprite = null; } } EnhancedImageInfo ret = null; if (sprite != null) { if (forcedHeight != -1) { SetImageHeight(ref spriteWidth, ref spriteHeight, forcedHeight); } ret = new EnhancedImageInfo() { ImageId = id, Sprite = sprite, Width = spriteWidth, Height = spriteHeight, AnimControllerData = animControllerData }; _cachedImageInfo[id] = ret; } Finally?.Invoke(ret); }
public IEnumerator OnSingleImageCached(byte[] bytes, string id, ESCAnimationType animatedType, Action <EnhancedImageInfo> Finally = null, int forcedHeight = -1) { if (bytes.Length == 0) { Finally(null); yield break; } Sprite sprite = null; int spriteWidth = 0, spriteHeight = 0; AnimationControllerData animControllerData = null; switch (animatedType) { case ESCAnimationType.GIF: AnimationLoader.Process(AnimationType.GIF, bytes, (tex, atlas, delays, width, height) => { animControllerData = AnimationController.instance.Register(id, tex, atlas, delays); sprite = animControllerData.sprite; spriteWidth = width; spriteHeight = height; }); yield return(new WaitUntil(() => animControllerData != null)); break; case ESCAnimationType.APNG: AnimationLoader.Process(AnimationType.APNG, bytes, (tex, atlas, delays, width, height) => { animControllerData = AnimationController.instance.Register(id, tex, atlas, delays); sprite = animControllerData.sprite; spriteWidth = width; spriteHeight = height; }); yield return(new WaitUntil(() => animControllerData != null)); break; case ESCAnimationType.MAYBE_GIF: if (6 <= bytes.Length && (this.ContainBytePattern(bytes, s_animattedGIF89aPattern) || this.ContainBytePattern(bytes, s_animattedGIF87aPattern))) { AnimationLoader.Process(AnimationType.GIF, bytes, (tex, atlas, delays, width, height) => { animControllerData = AnimationController.instance.Register(id, tex, atlas, delays); sprite = animControllerData.sprite; spriteWidth = width; spriteHeight = height; }); yield return(new WaitUntil(() => animControllerData != null)); } else { try { sprite = GraphicUtils.LoadSpriteRaw(bytes); spriteWidth = sprite.texture.width; spriteHeight = sprite.texture.height; } catch (Exception ex) { Logger.Error(ex); sprite = null; } } break; case ESCAnimationType.WEBP: case ESCAnimationType.NONE: default: try { sprite = GraphicUtils.LoadSpriteRaw(bytes); spriteWidth = sprite.texture.width; spriteHeight = sprite.texture.height; } catch (Exception ex) { Logger.Error(ex); sprite = null; } break; } var ret = this._imageInfoContaner.Spawn(); if (sprite != null) { if (forcedHeight != -1) { this.SetImageHeight(ref spriteWidth, ref spriteHeight, forcedHeight); } ret.ImageId = id; ret.Sprite = sprite; ret.Width = spriteWidth; ret.Height = spriteHeight; ret.AnimControllerData = animControllerData; this.CachedImageInfo.TryAdd(id, ret); } else { this._imageInfoContaner.Despawn(ret); } Finally?.Invoke(ret); }