- Home /
Is it possible to get the atlas for a font texture?
Using the PackTextures method returns an array of indexes of all the different textures in a given texture atlas, apparently. That's hugely useful, and I assume that with the font textures Unity is doing something similar so that it can effectively render text in a given font when given a string as input.
My question is: can I get access to that array (and also the characters that map to each array index)? It seems pretty definite that Unity has that information internally, and normally I wouldn't need it, but I want to be able to get at the font texture and then use GetPixels to extract a single character at a time out, and then composite those into another texture.
My goal is just to composite some drawn fonts onto custom textures of my choosing. RenderTextures can't have a transparent background, to my knowledge, and they seem awkward and troublesome in general. But I am using Unity Pro, so I have access to that if absolutely necessary.
Answer by jonas-echterhoff · Sep 24, 2010 at 02:29 PM
Unfortunately, there is currently no way to access that information from a font at runtime. With some work, you could extract that information in the editor using the SerializedProperty class, and then store it somewhere for processing at runtime, though that will not work for Unity 3.0 dynamic fonts, as the character placement information is not static.
Though, probably, using RenderTextures would be a simpler solution for your problem. What do you mean by "RenderTextures can't have a transparent background", and what makes them awkward?
That's what I feared -- thanks for the info, at any rate.
Regarding RenderTextures, from reading around here, and my own experiments, it seems that I can't have a transparent background color onto which I composite something (like text) to then save it. The suggestions were to use hot pink or something that could then be cropped out, but when it comes to doing nicely antialiased font borders, that of course would keep remnants of the pink.
$$anonymous$$ore comments in a sec.
Admittedly, though, I didn't get too far with the render textures because actually I was finding that they always rendered a blank texture when I was trying to use a temporary rendertexture and setting it to rendertexture.active. Or, at least, ReadPixels was just giving me blankness. I wasn't able to find any good tutorials on the subject, and a day or so of experimentation led to nothing, so I went with a different route.