So we all know that text in Unity used to be a right pain in the rear. At least doing it without a gazillion draw calls using OnGUI. Things have changed slightly with all the current 2D solutions and Unity’s text mesh but I feel like each one fails at something, even be it a small thing. Through investigating a “read to me” system for my wife’s new game, Notespace Beat, I have taken a good hard look at some of the best solutions out there and am giving you a quick run down. Before we get into it, I had a very specific set of text requirements that I needed to satisfy. I need to be able to change size easily, change the style of the font (bold, italic), change the line spacing and pretty much everything you can do with in a text area in photoshop. It needs to be light and I need to get to the positional data of the text so I can find out if a user tapped a word.
First up, Unity Text Mesh.
I have never really played with Text Mesh before this project because I was always under the assumption that it would not work with my current work flow and 2D solutions. I was wrong about that and there are a lot of things to write home about here. First off, the dynamic font generation is pretty dope. Not having to make new font maps every time I change my font or its…
I have been using C# for many years now in game dev and I love it. Most hardcore C++ guys have always given me grief but I still think the language is beautiful! Yes yes, its memory managed but thats a whole beast unto its self. At least I don’t have to spend a week looking for an illusive overwrite or leak. But each unto their own, we all make games and in todays world, fast to market is a big deal, especially with little to no budget.
One of the great things in C# is Lists. For those of you who don’t know them, they are basically dynamic arrays with a whole host of special functions. They are wonderful things, especially for inventory systems. There is a lot of debate about if they are significantly slower than arrays but the general rule is don’t add to them in a critical update loop. Besides being able to add and remove items dynamically, you can also just bake the list to an array using ToArray(). This way you can have a list that you use to manage your stack and once you are done, you can just bake it out.
So what I want to chat about here is Linq, which is C#’s look up language for lists. I always stayed away from it, erring and my years for “Doing things the right way” but Linq used in the right way can save you a lot of time. I have started using it for my data structure look…