I have a ScriptableObject "Character" and I have a created an instance of it. It has a field for a Sprite but I don't want to reference it before starting the game.
public Class Character : ScriptableObject {
public Sprite mySprite;
}
Now I have a specific folder where the players should put the custom image file (.jpg, .png), say "My Documents/My Game/My Pictures". When the players press a button in the UI then all the image files will be shown and then the user can click an image and then that sprite would be referenced in an instance of Character ScriptableObject.
I would also like to add some requirements like the image should be 200x200 in dimensions.
There's 3 parts needed here:
Texture2D
Sprite
from the texture(1) you can look up yourself, reading bytes from a file is trivial.
(2) is this method
(3) uses Sprite.Create()
Your final code will look like this:
File f = //...step 1
Texture2D t = //...step 2
Rect size = new Rect(0, 0, t.width, t.height); //the part of the image to use; whole image
int PIXELS_PER_UNIT = 100; //whatever your other sprites use
Sprite s = Sprite.Create(t, size, Vector2.zero, PIXELS_PER_UNIT, 0, SpriteMeshType.FullRect);