I want to load texture with rendered font file with Resources.Load, so I access it later with GetPixels.
Texture2D fontTexture = Resources.Load("Fonts/arial2_0") as Texture2D;
But i get an exception
UnityException: Texture 'arial2_0' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
How can I make that texture accessible?
I tried next thing
Texture2D fontTexture = new Texture2D(512, 512);
TextAsset buffer = Resources.Load("Fonts/arial2_0.png") as TextAsset;
fontTexture.LoadImage(buffer.bytes);
But it is not working as well 
Is there a way to read binary file from resources folder into some byte[ ] buffer?
I even tried to reimport texture with such silly code
Texture2D bufferTexture = Resources.Load("Fonts/arial2_0") as Texture2D;
byte[] buffer = bufferTexture.EncodeToPNG();
Texture2D fontTexture = new Texture2D(512, 512);
fontTexture.LoadImage(buffer);
But it gives me same exception that texture isn’t readable. I’am now out of ideas.
Maybe I can include to the build file some zip full with textures (or download it in runtime), and then unpack it (mb with DotNetZip) and use?
It must work in webplayer. Any thoughts?
I doubt you can alter font image data managed from Unity.
If its just a normal image, recheck the import settings you likely didn’t flag it for dynamic modification
That texture with description XML file is generated by me with BMFont program. I want to use it to render some text on the other textures. So far I didn’t found unity built-in solution. So it is a normal 512x512 PNG file, and program works great with it. But I used FileStream class to read it and it doesnt work in webplayer.
I’m looking for solution other than creating object by hand in IDE which will hold references to the textures and XML descriptions.
you can export it through an own editur utility to the Unity Editor.
If you add it at runtime you can’t make the texture read-writeable.
:shock:
So there is no way to download prepared fonts from the web and use as I described?
Why then this works (not in webplayer, obviously)?
FileStream stream = new FileStream("Assets/Resources/Fonts/arial2_0.png", System.IO.FileMode.Open);
BinaryReader reader = new BinaryReader(stream);
byte[] buffer = reader.ReadBytes(10000000);
fontTexture.LoadImage(buffer);