It took five years. Only five years, that is, for people to change their expectations of how displays are supposed to work.
Case in point: at the Scientifica, our booth had several slideshows running on iMacs – obviously without any keyboards or mice around to interact with. So far, so normal. But then, something funny happened.
That’s gonna be a short post, because all you need to know is over on Robert’s1blog:
Say you’re making a Unity game that takes place in a large landscape dotted with windmills, and some of these windmills have tunnels that lead underground. But in Unity, the terrain collider is generated from heightmap data: it’s essentially one giant bumpy plane. You can’t punch holes in it.
Since I happen to be ranked somewhat high when it comes to mentioning Unity 3D and XML, and some of the posts1 happen to be outdated by now since I learned stuff2. But most of all, I intend to learn even more.
That’s why I choose to release those two projects into the wild and publish them on github.
GUIs are not exactly easy to program in Unity 3D, since there is only one method available (OnGUI()) that obviously has to take up everything.
This becomes a problem as soon you try to create different menu screens that have to be switched out. One way to do it would probably be to use different scenes (which would be cumbersome); another way to use a switch, which would be just as cumbersome.
Since I’m currently cleaning up my code to hand it in with my project, I figured I could write some of the stuff down I learned during my work on our game.
All of it applies, of course, to C#, and was used in Unity 3D.
Checking for a type
Using the is keyword, you can easily check whether a certain object is of a desired type. Also, you should be aware of the as keyword, that allows you to cast an object as something else (given that this is possible).
Writing Serialised Data to a String Instead of a File in C#
Instead of writing the serialised data to a file, which can be done using using (Stream s = File.Create("foo.xml")), you might want to have just the string – maybe because you want to send it to a server? You can use the StringWriter class to do so:
string data;
using (StringWriter stream = new StringWriter()) {
xs.Serialize (stream, foo);
data = stream.ToString();
}
Iterating over a dictionary in order to change its values will not work; the program will throw an exception because the dictionary has been modified while iterating over it (which was, frankly, the purpose, but I digress). I can see that this could be problematic. Workaround: copy the dictionary into another temporary one, iterate over that to change the original dictionary. Or create a new dictionary using the iteration.