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

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