Nov23

C# Snippet: ColoredMaterialCache reduces memory load

This C# Snippet allows you to create, cache and retrieve instances of materials you need color-variations of. This is great if you want to have the same objects in different colors.

Normally, changing “renderer.material.color” will create an instance of the material for each object you create. If you use ColoredMaterialCache.GetVariationOnMaterial() all materials will be cached and you will end up with one material instance per color instead of one material instance per object. 

Get it here as a Gist:

https://gist.github.com/1389369

Nov16
My first submission to the Unity Asset Store went out today.
It’s an Editor Extension which allows to create scripts based on (multi-file) templates in a wizard-style window. The system uses the Visual Studio 2008/10 Template definition format – templates can easily be imported in Visual Studio.
Now Available for 20 USD on the Unity Asset Store:
http://u3d.as/content/andreas-zeitler/advanced-c-templates

My first submission to the Unity Asset Store went out today.

It’s an Editor Extension which allows to create scripts based on (multi-file) templates in a wizard-style window. The system uses the Visual Studio 2008/10 Template definition format – templates can easily be imported in Visual Studio.

Now Available for 20 USD on the Unity Asset Store:

http://u3d.as/content/andreas-zeitler/advanced-c-templates

Nov13

C# Snippet: Create Deep-Copy method for Class

This C# Snippets generates the code for a method which deep-copies any class  from a source to a target instance. This is useful to copy components field-wise (and, optionally, property-wise) in Unity 3D. A test for the Transform component is included.

Get it here as a Gist:

https://gist.github.com/1361488

Jul20

A Note on Partial Classes and Unity

Recently I have discovered partial classes in C# for the use in Unity. They are a good way to split classes into a Library-part, which never changes from project to project, and an custom part which can be custom for each project.

Unity does handle this effortlessly as long as you remember to keep code file names unique.

For my purposes I use a simple .-syntax like this:

LayerManager.cs // this is the base class included in my collection of extensions

LayerManager.Custom.cs // this is the custom extension which adds game-specific functionality to the LayerManager class

Mar5

Delegates and UI Programming

or: a perfect match.

I am using Delegates to define UI content in functions. Switching UI windows is as easy as changing the delegate assignments. My previous system used a MonoBehavior-Derived component for each UI Window, which gave me around 30 components to handle. Now I have one component and one static class, that holds all the window content code. Drawing is handled by a single GameObject with the main UI component attached.

This approach uses less GameObject and Component and therefore is faster than a GameObject-based handling of different UI windows.

Jan14
Jan12