/// <summary> /// On sprite sheet cached /// </summary> /// <param name="p_ID">ID of the sprite sheet</param> /// <param name="p_Texture">Result texture</param> /// <param name="p_Rect">Sheet rect</param> /// <param name="p_Finally">A callback that occurs after the resource is retrieved. This will always occur even if the resource is already cached.</param> /// <param name="p_ForcedHeight">Forced height</param> private void CacheSpriteSheetImage(string p_ID, Texture2D p_Texture, ImageRect p_Rect, Action <EnhancedImageInfo> p_Finally = null, int p_ForcedHeight = -1) { int l_SpriteWidth = p_Rect.width; int l_SpriteHeight = p_Rect.height; Sprite l_Sprite = Sprite.Create(p_Texture, new Rect(p_Rect.x, p_Texture.height - p_Rect.y - l_SpriteHeight, l_SpriteWidth, l_SpriteHeight), new Vector2(0, 0)); l_Sprite.texture.wrapMode = TextureWrapMode.Clamp; EnhancedImageInfo l_Result = null; if (l_Sprite != null) { if (p_ForcedHeight != -1) { ComputeImageSizeForHeight(ref l_SpriteWidth, ref l_SpriteHeight, p_ForcedHeight); } l_Result = new EnhancedImageInfo() { ImageID = p_ID, Sprite = l_Sprite, Width = l_SpriteWidth, Height = l_SpriteHeight, AnimControllerData = null }; m_CachedImageInfo[p_ID] = l_Result; } p_Finally?.Invoke(l_Result); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// <summary> /// On single image cached /// </summary> /// <param name="p_ID"></param> /// <param name="p_Bytes">Result bytes</param> /// <param name="p_IsAnimated">Is and animation image</param> /// <param name="p_Finally">A callback that occurs after the resource is retrieved. This will always occur even if the resource is already cached.</param> /// <param name="p_ForcedHeight">Forced height</param> /// <returns></returns> private IEnumerator OnSingleImageCached(string p_ID, byte[] p_Bytes, bool p_IsAnimated, Action <EnhancedImageInfo> p_Finally = null, int p_ForcedHeight = -1) { int l_SpriteWidth = 0; int l_SpriteHeight = 0; Sprite l_Sprite = null; AnimationControllerData l_AnimControllerData = null; if (p_IsAnimated) { AnimationLoader.Process(AnimationType.GIF, p_Bytes, (p_Texture, p_Atlas, p_Delays, p_Width, p_Height) => { l_AnimControllerData = AnimationController.instance.Register(p_ID, p_Texture, p_Atlas, p_Delays); l_Sprite = l_AnimControllerData.sprite; l_SpriteWidth = p_Width; l_SpriteHeight = p_Height; }); yield return(new WaitUntil(() => l_AnimControllerData != null)); } else { try { l_Sprite = BeatSaberPlus.Utils.UnityTexture.LoadSpriteRaw(p_Bytes); l_SpriteWidth = l_Sprite.texture.width; l_SpriteHeight = l_Sprite.texture.height; } catch (Exception p_Exception) { Logger.Instance.Error("Error in OnSingleImageCached"); Logger.Instance.Error(p_Exception); l_Sprite = null; } } EnhancedImageInfo l_Result = null; if (l_Sprite != null) { if (p_ForcedHeight != -1) { ComputeImageSizeForHeight(ref l_SpriteWidth, ref l_SpriteHeight, p_ForcedHeight); } l_Result = new EnhancedImageInfo() { ImageID = p_ID, Sprite = l_Sprite, Width = l_SpriteWidth, Height = l_SpriteHeight, AnimControllerData = l_AnimControllerData }; m_CachedImageInfo[p_ID] = l_Result; } p_Finally?.Invoke(l_Result); }