I know that Asset Bundles exist, and I'm already taking a look at them. But I'm still interested in this particular approach:
I am interested in downloading a .png image from the Web, and then "consolidate" it as a Sprite asset. After doing so, I can display this sprite in my game in the future without ever downloading that image again.
I was able to download the image and use its texture to create a Sprite
object and use it for my SpriteRenderer
:
WWW request = new WWW("www.example.com/image.png");
yield return request;
if (request.isDone) {
((SpriteRenderer)renderer).sprite = Sprite.Create(request.texture, new Rect(0,0,request.texture.width,request.texture.height), new Vector2(0.5f,0.5f));
}
Is it possible to grab this texture and generate a Sprite asset? With all the properties like pivot, pixels per unit, packing tag, etc?
UPDATE
Alright, so turns out that Sprite.Create
let's me set the pivot and pixels to units properties. No packing tag, though, but I guess that makes sense since packing should be done during development and not during runtime.
Given this, I suppose one could serialize the generated Sprite class.