In my game, I’d like players to be able to customize their profiles by loading “avatar” from HDD (which would be standard image file). However I don’t know how to do that, and couldn’t find anything in the docs.
I just cooked this up for something I’m working on - hope you find it useful.
public static Texture2D LoadPNG(string filePath) {
Texture2D tex = null;
byte[] fileData;
if (File.Exists(filePath)) {
fileData = File.ReadAllBytes(filePath);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
}
return tex;
}
Loading local file can also be done like this:
IEnumerator LoadTextureFromCache(string filePath)
{
if (!File.Exists(filePath))
{
yield break;
}
var www = UnityWebRequestTexture.GetTexture("file://" + filePath);
yield return www.SendWebRequest();
//texture loaded
var texture = DownloadHandlerTexture.GetContent(www);
}
How do you load a tif image from code? supposedly you can use them if you import them from the editor, but im trying to load preexisting mods for a different game that uses tif.
im currently working on a netstandard library for parsing tiff files from binary but id prefer not to do it myself if i dont have to