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):

Remember, this has to work from the web player, so anything in UnityEditor is out.

Thank you.

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.