EnumeratedDelegate

A method to setup a quick and dirty Finite State Machine of sorts by means of generics, delegates and an enum.

Description
A C# generic class that takes an enum and a delegate as parameters and lightly emulates a finite state machine. Just provide an enum representing the different states, a delegate representing the type of function that all of the states will be represented by, and then one function for each member of the enum, matching the delegate signature.

Usage
(For this example, I am using a GUI navigation menu system)

First create an enum representing the different states (names and naming scheme are irrelevant, it's the order that's important):

Then create the delegate to which all your state functions match:

Next, declare the member variable representing the EnumeratedDelegate itself:

Meow, create all the functions that will represent the different states, making sure that they all have the same signature: (Meow, what is so damn funny?!)

At this point, you only need to instantiate the EnumeratedDelegate object: 'Note there are 4 different constructors for EnumeratedDelegate that take either the functions and/or the initial state. Initial state is the very first in the enum by default.'

Last but definitely not least, you must actually call the current state function of the EnumeratedDelegate from whereever you need it (this is usually in Update or OnGUI):

You can change the current state of the EnumeratedDelegate through its CurrentMode property.

public EnumeratedDelegate
Default Constructor. Reads in the names of the enum and stores them. Sets   to the first value declared in the enum (technically whatever value is assigned to zero).

Note: The state functions are still null at this point, so you will still need to set the   property like so:

public EnumeratedDelegate(int intialState)
Reads in the names of the enum and stores them. Sets   to the enum value specified by initialState (technically whatever value is assigned to initialState).

'Note: The state functions are still null at this point. See note above.

public EnumeratedDelegate(DelegateType[] arrFuncs)
Reads in the names of the enum and stores them. Sets   to the first value declared in the enum (technically whatever value is assigned to zero). Sets the state functions specified by arrFuncs.

public EnumeratedDelegate(DelegateType[] arrFuncs, int intialState)
Reads in the names of the enum and stores them. Sets   to the enum value specified by initialState (technically whatever value is assigned to initialState). Sets the state functions specified by arrFuncs.

EnumeratedDelegate.cs
Example usage as a GUI system for several different screens:

Coming Soon

 * State transition in/out support
 * More/better error checking