Java Enums, besides being Iterable, have the nice feature of being able to store properties and methods for each enum:
for (Planet p : Planet.values()) {
System.out.println(p+" "+p.gravity)
}
C# Enums do not appear to have properties. It seems you do it with Extensions.
Is this correct or is there a better way? IIs this safe in Unity3?
That’s one way to do it and it should work in Unity 3. What methods are you trying to create?
A list of Orders (Walk, Run, Hide) each with properties like Color displayColor and float fatigueModifier that vary for each enum.
A guess at how I might do it, I haven’t actually run this though:
namespace GameClasses {
public enum Orders { Walk, Run }
public static class Extensions
{
//this is ugly, is there a better way to get the length of the enum?
public static Color[] displayColors = new Color[Enum.GetNames(Orders).getLength()];
//can I init this in a static context here?
Color[Orders.Walk] = new Color(0,1,0);
Color[Orders.Run] = new Color(1,0,0);
public static DisplayColor(this Orders order)
{
return displayColors[order];
}
}
}
//then I could later do this:
Color drawColor = myorder.DisplayColor()