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

Jun15
Advanced Visual Studio Unity Templates
Collection of Visual Studio Templates to make development with Unity easier. Provides templates for all important Unity base classes: MonoBehavior, ScriptableObject, ScriptableWizard, Editor, EditorWindow. There are also a few more advanced templates to create a new MonoBehavior including a Custom Inspector and a class holding Editor functionality for it (kind of adhering to the MVC design pattern). The screen is taken from the German Visual Studio, the templates are in English, however, and can be used in any Visual Studio Edition (2008 and 2010).
Download (UnityAdvancedVSTemplates.zip ~100KB)
Check in on the Unity Board and give me feedback!

Advanced Visual Studio Unity Templates

Collection of Visual Studio Templates to make development with Unity easier. Provides templates for all important Unity base classes: MonoBehavior, ScriptableObject, ScriptableWizard, Editor, EditorWindow. There are also a few more advanced templates to create a new MonoBehavior including a Custom Inspector and a class holding Editor functionality for it (kind of adhering to the MVC design pattern). The screen is taken from the German Visual Studio, the templates are in English, however, and can be used in any Visual Studio Edition (2008 and 2010).

Download (UnityAdvancedVSTemplates.zip ~100KB)

Check in on the Unity Board and give me feedback!

May7
Sep28

Unity 3 Custom Icon

Unity 3 was released yesterday. I pre-purchased it weeks ago, including the iPhone Advanced license.

I need to keep Unity 2.6.1 in service for support purposes (old client work) - and from time to time I have to work with both versions parallel. That’s not a problem - the guys at Unity Technologies kept that possibility in mind. The only problem is that both versions use the same Icon, so it’s hard to tell both programs apart while running.

I put together this custom icon to get rid of this little inconvenience.

Here’s the Mac icon version of it: Icns-Container File

Here’s the PNG version of it: PNG File

Tagged: gamedev unity3d dev
Aug6

Track Mobile App Usage with GoogleAnalytics

A few days ago I came across a topic on the Unity3D Board. Someone implemented tracking with GoogleAnalytics for a Unity3D-based game. You can find the original post here.

This immediately caught my attention as GoogleAnalytics is the most powerful - yet free - tracking tool out there. Adapting it to track mobile games and apps or even desktop or web games just makes sense.

The original code released by user Almar is written in C# for .Net 2.0. I immediately adapted it for .Net 1.1 (code here) and am now porting it to Objective-C for use in native iOS apps.

Update:

As a few people asked me how this is done, here is the basic technical background:

The script uses the server-side tracking module Google provides (Urching Tracking Monitor, short utm). The data is combined into parameters and then posted as a normal request to the URL provided by Google.

Apr21

Unity 3D: OBJ-Export and Cinema 4D troubles

And yet again I had to spend a whole day to work out a bug in my Unity3D-to-Cinema4D-Pipeline. Well, after all, I am constantly jumping a whole dimension here (yeah, I did a bad play on product names).

The situation: I use the OBJ Exporter found on the Unity Wiki (ObjExporter) to export each of my levels to OBJ. I then import those OBJ-files in Cinema and bake the shadows for it. The shadowmaps are then used for basic lighting of the levels. Well, this is pretty straightforward up to here.

After doing some asset optimizations last week, the exported OBJ file I wanted to use today for shadow baking was not displayed correctly any more in Cinema. Viewing the OBJ file in a text editor, however, I could not find anything wrong with it. In the past I had to deal with some formatting issues within the OBJ-Export-Script (decimals need to be seperated by ‘.’ and not ‘,’) so I suspected the problem to be that sort of thing again and usually a quick look at the ASCII source of the file made the problem obvious.

After playing around with number formatting for a while, I found out, that Unity creates an empty zero-length array of normals for a mesh if the import settings are set to not import normals and tangents. When exporting a mesh without normals the OBJ-Export-Script does not write any normals for the mesh - which is what causes the problem.

Solution: Basically you need to give the mesh an array of normals before you export it. A simple array of zero-vectors will do.

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.

Jan12
Jan10
Nov6

Unity: New C# Templates for Visual Studio

I extended and improved my original collection of Visual Studio C# templates to include ScriptableWizard, Editor and EditorWindow.

See the original post for install instructions.

Download [VSUnityTemplates_v200.zip]

Tagged: gamedev dev unity3d