Thinking about rewriting Textmesh, please talk me out of it!

I am using EzGUI but I need a really good text entry component. EZGUI has a text-field but it isn’t good enough. I need one that has caret support and can clip the visual of the entered text to a 2d box. Also I have frequent issues where I need to know how wide the text will be.

As I write this an idea occurs to me that may work so I don’t have to rewrite the out of the box textmesh. I could use 2 3d Text objects, on of them being off-screen. I would use the off-screen one to get the bounds of the text or substrings of the text. When I move the caret (right or left arrow or mouse click) I can increase or decrease the number of characters in the off-screen 3d Text and use renderer.bounds to get the actual bounds. This should give me a good indication of where to put a blinking caret on-screen.

I can use two strings one being the shown string and one being the actual entry string to keep the 3d Text clipped visually within a 2d box area. As the caret moves I adjust the shown string to only have characters that would be within the bounding area
(Using the off-screen 3D text to test this). This wouldn’t be as cool as being able to clip textmesh itself but its plenty functional enough for a text-field entry.

A potential gotcha would be if changing the text for textmesh doesn’t immediately adjust its textmesh.renderer.bounds value. If I have to wait an update frame then that could be very tricky to extract the boundary data (text width) as I expand and contract the off-screen 3d text.

Well thanks for listening to me think out loud. Any other potential gotchas?

Encountered a same troubling thought / issue heh.

While i was thinking about this…
http://forum.unity3d.com/viewtopic.php?t=59744

I think the real end-all solution is to make a proper text tool for unity :confused:

Currently the project i’m working on doesnt require dynamically-placed text; it’ll all be known at edit time so I dont care about how it wraps per-frame i’ll just pre-calculate it in editor mode. But yea I was going to use the 2-strings method.

Let me know if you want to give a shot at rewriting TextMesh. Actually if you know a decent way to access the TTF data itself thru Unity without manually parsing the file w/ a streamreader please let me know and I’ll write the Mesh generation part of our new TextMesh2.0 for you :slight_smile:

I think Mich is right, I’ve been trying to work with their font system and more than that the custom font system of Unity. I learned many things included that almost everything is hidden and even with reflection it is impossible to modify properties.

Also, after some discussion with Unity programmer, they told me that the Custom Font system was written at the beginning of Unity, so if they’re going to modify it they will probably rewrite it entirely.

I ended up writing my own custom font system. Unfortunately, because of my current position I cannot give you the code. But basically you just have to do a system that draws your own meshes and binds your Vertices with UVs coords.

It can get complicated depending on what kind of Font you are working on, but at least you’ll have full control on it.