Here's an example, from the Starward Rogue codebase:
public enum InventoryItemType
{
None,
Energy,
Keycard,
Missile,
Credit,
HealthShard,
ExperiencePoint,
Length
}
public static class InventoryItemTypeExtensionMethods
{
public static InventoryItemTypeData GetData( this InventoryItemType Type )
{
return InventoryItemTypeData.Lookup[(int)Type];
}
}
public class ArcenEnumIndexedArray_InventoryItemType<T>
{
#region Instance Fields
private readonly T[] internalArray = null;
#endregion
#region ctor
public ArcenEnumIndexedArray_InventoryItemType()
{
this.internalArray = new T[(int)InventoryItemType.Length];
}
#endregion
public T this[InventoryItemType key]
{
get
{
return this.internalArray[(int)key];
}
set
{
this.internalArray[(int)key] = value;
}
}
}
public class InventoryItemTypeData
{
public readonly InventoryItemType Type;
public string Name = string.Empty;
public IGameImage CannotPickUpBecauseFullIcon;
public IGameImage RecentTransactionListIcon;
public int Max = -1;
public int Default;
public bool UsesSimpleHUDDisplay;
public bool ShouldTrackPositiveChangesInTransactionLog;
public bool ShouldTrackNegativeChangesInTransactionLog;
public InventoryItemTypeData( InventoryItemType Type )
{
this.Type = Type;
string cannotPickUpBecauseFullIconName= string.Empty;
string recentTransactionListIconName = string.Empty;
string recentTransactionListAnimatorName = string.Empty;
int animDictWidth = 0;
int animSpriteWidth = 0;
int animFrames = 0;
switch ( this.Type )
{
case InventoryItemType.None:
case InventoryItemType.Length:
return;
case InventoryItemType.Energy:
this.Max = 100;
this.Default = 100;
this.UsesSimpleHUDDisplay = true;
break;
case InventoryItemType.Keycard:
cannotPickUpBecauseFullIconName = "FullIconKeyCard";
recentTransactionListIconName = "Items/PickupKeycard";
this.UsesSimpleHUDDisplay = true;
this.ShouldTrackPositiveChangesInTransactionLog = true;
this.ShouldTrackNegativeChangesInTransactionLog = true;
break;
case InventoryItemType.Missile:
this.Max = 10;
this.Default = 5;
cannotPickUpBecauseFullIconName = "FullIconMissiles";
recentTransactionListIconName = "Items/PickupMissile1";
this.UsesSimpleHUDDisplay = true;
this.ShouldTrackPositiveChangesInTransactionLog = true;
break;
case InventoryItemType.Credit:
this.Max = 255;
cannotPickUpBecauseFullIconName = "FullIconCredit";
recentTransactionListAnimatorName = "Items/PickupCredits1";
this.UsesSimpleHUDDisplay = true;
animDictWidth = 160;
animSpriteWidth = 32;
animFrames = 19;
this.ShouldTrackPositiveChangesInTransactionLog = true;
this.ShouldTrackNegativeChangesInTransactionLog = true;
break;
case InventoryItemType.HealthShard:
this.Max = 10000;
animDictWidth = 370;
animSpriteWidth = 74;
animFrames = 18;
recentTransactionListAnimatorName = "Items/PickupHealthShard";
this.ShouldTrackPositiveChangesInTransactionLog = true;
this.ShouldTrackNegativeChangesInTransactionLog = true;
break;
case InventoryItemType.ExperiencePoint:
recentTransactionListAnimatorName = "Items/PickupExperiencePoint";
animDictWidth = 96;
animSpriteWidth = 24;
animFrames = 12;
this.ShouldTrackPositiveChangesInTransactionLog = true;
this.ShouldTrackNegativeChangesInTransactionLog = true;
break;
default:
throw new Exception( "InventoryItemTypeData.ctor: no switch case defined for InventoryItemType '" + this.Type.ToString() + "'!" );
}
if ( cannotPickUpBecauseFullIconName.Length > 0 )
this.CannotPickUpBecauseFullIcon = Game.Instance.LoadImage( "Misc/GameUnitPopups/" + cannotPickUpBecauseFullIconName, 58, CompressionType.None, TextureWrapMode.Clamp, false );
if ( recentTransactionListIconName.Length > 0 )
this.RecentTransactionListIcon = Game.Instance.LoadImage( recentTransactionListIconName, 52, CompressionType.None, TextureWrapMode.Clamp, false );
else if ( recentTransactionListAnimatorName.Length > 0 )
{
OtherAnimator animator = OtherAnimator.Create( recentTransactionListAnimatorName, animFrames, CompressionType.None, TextureWrapMode.Clamp, animSpriteWidth, animDictWidth, 1, true );
this.RecentTransactionListIcon = animator.Images[0];
}
}
public static InventoryItemTypeData[] Lookup = new InventoryItemTypeData[(int)InventoryItemType.Length];
private static bool HasInitialized = false;
public static void Initialize()
{
if ( HasInitialized )
return;
HasInitialized = true;
for ( InventoryItemType i = InventoryItemType.None; i < InventoryItemType.Length; i++ )
{
InventoryItemTypeData typeData = Lookup[(int)i] = new InventoryItemTypeData( i );
}
LoadLoca();
}
public static void LoadLoca()
{
for ( InventoryItemType i = InventoryItemType.None + 1; i < InventoryItemType.Length; i++ )
i.GetData().InstanceLoadLoca();
}
private void InstanceLoadLoca()
{
this.Name = Language.Current.GetValue( "InventoryItemType_Name_" + this.Type );
}
}
Initialize is called during application startup logic, and individual references are serialized/deserialized as Int32 casts of the enum itself, and if you have a reference and want the data you do item.GetData().whatever .