Improve sprite b64 handling
This commit is contained in:
@@ -34,30 +34,16 @@ public static class Tools
|
||||
statusText.color = color;
|
||||
}
|
||||
|
||||
public static void RenderFromBase64(string base64, Image targetImage)
|
||||
public static Sprite GetSpriteFromBase64(string base64)
|
||||
{
|
||||
byte[] imageData = Convert.FromBase64String(base64);
|
||||
Texture2D tex = new(2, 2, TextureFormat.ARGB32, false);
|
||||
if (!tex.LoadImage(imageData)) return;
|
||||
if (!tex.LoadImage(imageData)) return null;
|
||||
|
||||
tex.filterMode = FilterMode.Point;
|
||||
tex.Apply(false, false);
|
||||
|
||||
Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new UnityEngine.Vector2(0.5f, 0.5f));
|
||||
targetImage.sprite = sprite;
|
||||
}
|
||||
|
||||
public static void RenderFromBase64(string base64, SpriteRenderer targetImage)
|
||||
{
|
||||
byte[] imageData = Convert.FromBase64String(base64);
|
||||
Texture2D tex = new(2, 2, TextureFormat.ARGB32, false);
|
||||
if (!tex.LoadImage(imageData)) return;
|
||||
|
||||
tex.filterMode = FilterMode.Point;
|
||||
tex.Apply(false, false);
|
||||
|
||||
Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new UnityEngine.Vector2(0.5f, 0.5f));
|
||||
targetImage.sprite = sprite;
|
||||
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new UnityEngine.Vector2(0.5f, 0.5f));
|
||||
}
|
||||
|
||||
public static void RefreshHierarchy(GameObject root)
|
||||
|
||||
Reference in New Issue
Block a user