Archive for April, 2015

Coroutine and Iterator Function Tricks

C# supports iterator functions with the yield keyword. Unity uses them to support coroutines. Unfortunately, both are poorly understood by many Unity programmers. Today’s article dives into iterator functions and coroutines to better understand how they work and what they can be used for. Read on to learn how to use iterator functions and coroutines for more effective asynchronous code!

Read the rest of this article »

6 Comments

SafeList: A Class To Eliminate Foreach Errors

Tags: ,

Today’s article shows a class that helps clean up your foreach loops when you want to call Add() or Remove() on the List you’re looping over. Normally you’d get an exception, but today’s class works around that problem so your code is less error-prone and easier to read. It also discusses some workarounds you can use even if you don’t use SafeList. Read on to learn how to make your foreach loops less error-prone! UPDATE: SafeList 2.0 is out!

Read the rest of this article »

6 Comments

WebCall: A Class to Make Web Calls Cleaner and Easier

Tags: ,

Today’s article is about WebCall, a class to make Unity’s WWW cleaner and easier to use. How could it be cleaner or easier than it already is? By adding C# events! Normally your web calls have lots of clutter around them, your logic gets split across functions, and handling the call is hard when the GameObject or MonoBehaviour get destroyed. WebCall solves all these problems so your web calls are clean, easy, and robust. Read on for the source code and examples!

Read the rest of this article »

5 Comments

String.Format() vs. Concatenation vs. String Builder

Tags: , ,

What’s the fastest way to build a string in C#? We have several options available to us. string.Format() is a function built right in to the string class., Concatenation ("a" + "b") is a feature of the language itself! The System.Text.StringBuilder class is a built in class with a name that makes it sound like it’s purpose-built for building strings. Today I pit these three against each other to find out just which one you should be using to build strings as quickly as possible.

Read the rest of this article »

17 Comments