C# and Dot.Net

I am becoming a .Net/C# fan 😉

With it's reflection ability, you can do some nice things. For example output all public data values of an object onto your screen. A little minimal example for Unity debugging/tweaking purposes …

Let's say we have two classes with public data we are interested in

    class MyDataOne : Object
        public float AirDensityRo = 1.225f;
        public float LengthInMeters = 2156.33f;
        public float MetersPerSecond  = 2.0f;

    class MyDataTwo : Object
        public int Iteration = 0;
        public float Offset = 13.0f;
        public float Affinity  = 2.0f;

We then save both instances into a list

List<Object> DisplayedDataObjects = new List<Object>();

void Start()

   DisplayedDataObjects.AddRange(new Object[] { new MyDataOne() , new MyDataTwo () });


 And in the OnGUI context you can draw the values for example like this


        float yOffset = 15;
        foreach (Object obj in myDisplayedObjects)
            yOffset += 5;
            GUI.Label(new Rect(5, yOffset, 240, 20), "== " + obj.ToString() + " ==");
            yOffset += 15;
            FieldInfo[] fields = obj.GetType().GetFields();
            foreach (FieldInfo field in fields)

                if (field.GetValue(obj) != null)
                    GUI.Label(new Rect(1, yOffset, 240, 20), field.Name + ": " + field.GetValue(obj).ToString());
                yOffset += 15;

The nice thing is that you can rename (refactor) member names and classes without worries as changes will visible immediately. With the list you can also modify quite quickly in what objects you're actually interested in.

The reflection stuff is in "System.Reflection".

Just a little hint for new Unity users on the PC platform. The SciTe/Scintilla editor that comes with the PC version is probably a lot better than the smultron editor that comes for the Mac version. Still it's a complete different level if you use Visual Studio.

Visual C# Express 2008 is a free development environment and it's very good. Besides standards like Syntax-Highlighting it has good refactoring tools and a pretty good intellisense (intelligent auto-completion).

Visual C Sharp for Unity

In order to use Visual C# Express, you need to add references to the Unity DLLs inside a new project. On the PC you can grab them from the installation folder


The DLLs are


If you also add all other DLLs your code depends on, you can even compile your code for verification. If you don't copy your .cs file but use the same that is referenced by the unity project, then each time you save the file in Visual Express, Unity will notice the change and reload and compile it using Mono.

Visual Web Developer 2008 Express says that it has "JavaScript IntelliSense" – I haven't tried it but if you prefer JS than you should give it a try!

In January I started a little fun project to continue learning C#. Using MOGRE (Managed Ogre3D) and WinForms I started a little editor. It's really at a very, very early state and currently I am too busy to continue working on it, but I have to say, I enjoyed working on it so far.

C# and WinForms make things really a lot easier (I don't like MFC!). And I have touched only the top of the Iceberg so far. C++ is powerful and gives a lot of freedom. Lots of freedom = lots of choices = not always easy to make a choice. I enjoy having some "standard solutions" in C#, like delegates. Built-In Introspection/Reflection/RTTI is also really, really, really cool! 

As everything is also of type "object, I believe that node-based editors/programming should be much easier/faster to realize using Dot.Net/C#. Sure, if you need to be portable and if you have to squeeze out the most of the hardware, C++ is the choice. If you do some PC-only Sims or Viz and you don't mind wasting some CPU power, why not? There are not yet many 3D render engines available, but they start to appear (i.e. XNA based).

At work, I decided to implement a (non 3d) project in C#. There are a bunch of asynchonic ways of doing things, and for me it's not so transparent yet (what happens in what thread, what is threadsafe especially when things get layered). But I guess it's a matter of learning and understanding the framework.

Most of the time I am using Visual Studio 2008 Express and for a free tool it's impressive. It does now do lots of things too that previously was only possible using 3rd party Add-Ons like VisualAssist. Something I am missing is to be able to filter the intellisense drop-down list by type (Property/Event/Method). VisualAssist has some filtering buttons at the bottom and it's useful.


When I started to experiment a bit with Unity3D, I used JavaScript. Unity3D uses Dot.Net as "scripting" environment and supports C#, boo and JavaScript. JavaScript is the one I already used in the past thus it's what I went for.

But something that really put me off after a while was how inefficient coding was without a good editor with solid syntax highlighting and Intellisense. In Visual Studio C++ I am using Visual Assist now for many years and don't want to do any  coding with out it!

There is a webdeveloper edition of Visual Studio 2008 Express which has intellisense support for JS, but if you want good performance in Unity3D you better use the strong typing language modification Unity Technologies added. Which btw. looks like this

var myFloat : float = 1.23f;

JavaScript itself is a dynamic language with dynamic typing. In the past developing with such a type of languages was a bit old school (execute and observe: "print, print, print .. ah something wrong here"), because you didn't have an environment with syntax highlighting and debugging.  So I guess that web-developer VS Express release probably gives a nice boost there. 

Dynamic languages have their strong points! I like being able to open the maxscript console (F11) in 3ds max, type in some lines, select them and press Shift+Enter. It executes the code with instant results – fantastic for prototyping. When done, you simply drag'n drop the code onto your toolbar (as example) and dang, new button that calls your code. A very fast way to extend a tool.

Microsoft seems to be aware of this as in a video with the 4.0 C# design team, they talk about use-case. Looks like C# might become a choice for embedded "scripting" language in applications.

An alternative is thus to use Visual Studio C# Express 2008 which is a great C# editor for free. And so far it seems to have very good intellisense and refactoring tools built-in. Another benefit is, that you can compile in VS as a verification step. On the G4 it took nearly up to 10 seconds until Unity3D recognized the recently saved script file and finished the recompilation. Compared to Virtools where VSL compilation is a matter of a second, it felt pretty annoying. On the other hand VSL is a less complex and complete language. VSL code tends to be in most cases short and without many dependencies (at least for me).

As my G4 macbook doesn't have Parallels, I finally rigged up a home-network with Synergy – like many people on the Unity3D forum do suggest and it's really good as now I can use the PC for coding in C#. This brings not only the benefit of using a good Editor – which is the main point – but also the benefit of using familiar Keyboard-Layout. 😉
That G4 keyboard and the unfamiliar way of selecting words or rows in one via the keyboard was a real slow.

Although now I need to learn C#, it's worth in order to use a good development environment. Moreover it might be very interesting for other tasks too. Actually I will start with some C# stuff outside Unity3D first. So Unity3D will have to wait even some more …

Recently I did a little log-analyzer tool in MFC and it really feels old. Luckily due many available resources online, it's still ok to use and especially it doesn't need the dot.Net run-time, which was my major decision point: easy deployment. Just one .exe and go. But I am interested in WinForms.

I played a little bit with WPF and XAML but it adds an additional layer, so I will stick to WinForms first.