I have found a shader that displays the game scene as ASCII characters, including UIs. To do so, it divides the UV screen in equal slices and replaces each of these slices by a texture representing a char. For instance, a texture with a “&” on it will display “&” on objects with similar lighting.
The thing is, having to modify which textures are used is a pain right now. The textures’ names are hardcoded in the script to use Resources.Load to access them, and modifying them would require an external app like Photoshop.
What I would like to have is to assign strings directly in the Inpsector, then the code converts them into a texture2D with the same size as my previous textures. I have found a thread that explains how to convert a string to string64, then to a byte array, then to a Texture2D, but I couldn’t find anything that worked. I don’t think it would be possible to change the font either, so just the conversion would help me greatly.
When you say “convert” do you mean turn the string “R” into a graphic that looks like R ?
If so, then use TextMesh or TextMeshPRO and a RenderTexture to “strike” each glyph in whatever font you want, point a camera at it and “photograph” it with the RenderTexture, and keep that texture for later use.
Tons of RenderTexture examples out there, and they are used to basically capture what comes out of a camera.
Here’s a lotto scratcher example that uses RenderTextures:
Hello, and thank you for your help. Unfortunately, this is not what I’m looking for, since I already have textures representing the caracters I want. What I want is to be able to change any of these caracters on the fly (or at least once at startup) so that I don’t have to create a texture for each caracter I want in the game.
I do not want to use these textures directly, I want to write a char in the Inspector, then let the code convert it into a Texture2D, like in the code sample I provided.
It seems you’ve misunderstood what I am trying to achieve. What I want is to avoid having to setup any Texture from the Inspector or via Resources.Load (or any equivalent) altogether. The only Textures I want is from converting some chars into Textures. The reason for this is that I want to avoid having to use a texture atlas or to edit these textures in an external editor like Photoshop.
If that’s not possible, that’s fine, atlases will have to do, but I would like to implement if it is the case.
Alright, so I couldn’t get the resources to work at the link I provided. So instead of converting strings to textures, I found an ASCII spritesheet online and converted its sub-sprites instead. Not the result I expected, but at least I can use other symbols than just ASCII chars, so that’s fine by me.
The code :
private Texture LoadTexture(Sprite sprite)
{
Texture2D tex = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height);
Color[] pixels = sprite.texture.GetPixels((int)sprite.textureRect.x,
(int)sprite.textureRect.y,
(int)sprite.textureRect.width,
(int)sprite.textureRect.height);
tex.SetPixels(pixels);
tex.Apply();
// safety, if forgotten when we added them
tex.wrapMode = TextureWrapMode.Repeat;
tex.filterMode = FilterMode.Point;
tex.hideFlags = HideFlags.HideAndDontSave;
return tex;
}
I’ll still mark this thread as Resolved since I found a more effective way of doing the job, and I linked the other project in my previous comment in case anyone wants to try it.