Hello everyone, thank you so much in advance for your help.
Context:
I have a texture that I download from a php file using UnityWebRequest
and Texture2D.LoadImage(byte[ ] bytes).
Problem:
I am able to use this texture in the UI of my game, but I would like to modify the import settings like how I usually do from the inspector in my project. (I mainly want to set Compression → None)
I know about the AssetPostprocessor but I don’t know how to apply it to a texture which I don’t have a path to in my project folder.
Here is my code:
// results as byte array
byte[] bytes = www.downloadHandler.data;
//Create texture2D
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(bytes);
//Change Import Settings
UnityEditor.AssetPostprocessor assetPostprocessor = new UnityEditor.AssetPostprocessor();
UnityEditor.TextureImporter importer = assetPostprocessor.assetImporter as
UnityEditor.TextureImporter;
importer.textureCompression = UnityEditor.TextureImporterCompression.Uncompressed;
//...To do: Apply importer settings to texture
//Can I even do this from monobehaviour?
//Create sprite (to be placed in UI)
Sprite sprite = Sprite.Create(texture, new Rect(0,0, texture.width, texture.height), new
Vector2(0.5f,0.5f));
callback(sprite);
If anyone has any leads or suggestions I would be truly grateful.
Best regards