- Home /
How can I set texture import properties at runtime? Must work in Web Player.
I have a PNG texture sheet that I'm generating, and it's not rendering in my NGUI atlas properly because the import properties are just the simple default settings. If I save the texture, import it into Unity, and modify its import settings, it renders properly. Now I need to figure out how to do this at runtime in such a way that works from the web player.
Texture2D has a few properties on it that look like they do at least some of what I'm looking for, but they don't seem to make much of a difference. Here is how I'm generating the texture sheet:
List<Texture2D> textures = CreateTextures(parsed);
Texture2D packedTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
var coordinates = packedTexture.PackTextures(textures.ToArray(), 1, 4096);
packedTexture.filterMode = FilterMode.Point;
File.WriteAllBytes(Application.persistentDataPath + "/Tester/output.png", packedTexture.EncodeToPNG());
When I run that, it outputs the texture to that provided directory, and when I load that into Unity, its import settings are still the default (for example the filter mode is bilinear).
How can I, in code, set the texture's import properties, from the default (on the left in the below picture) to more advanced settings (on the right):
http://i.imgur.com/4Q4GJfV.png
Remember, this has to work from the web player, so anything in UnityEditor is out.
Thank you.
@pateras did you find the solution to it?
I have the same code as yours and I have to update Import property read/Write enabled on the fly! also This texture is overwritten (re-created; by drawing more on the previously saved texture from the previous iteration ) in every iteration!
Answer by Graham-Dunnett · Jun 27, 2013 at 03:54 PM
The webplayer has zero access to the file system of the machine where it is running. To procedurally generate a texture you'll need to do it entirely using Unity API calls. So that basically means setting pixels using `SetPixels`.
I don't see what SetPixels gets me. I'm already creating the texture, I just need to set its properties so that it's rendered properly (e.g. filter mode).
Your answer
Follow this Question
Related Questions
How to keep texture resolution from blender? 1 Answer
How to import textures from photoshop to unity perfectly? 1 Answer
Texture color is not right after import 0 Answers
Compressing a texture imported with www class 0 Answers
Cannot enable mip map generation in advanced import settings for any texture/sprite? 2 Answers