using System; using System.Collections.Generic; namespace MoonTools.ECS { public class TypeIndices { Dictionary TypeToIndex = new Dictionary(); int nextID = 0; public int Count => TypeToIndex.Count; public int GetIndex() where T : unmanaged { if (!TypeToIndex.ContainsKey(typeof(T))) { TypeToIndex.Add(typeof(T), nextID); nextID += 1; } return TypeToIndex[typeof(T)]; } public int GetIndex(Type type) { return TypeToIndex[type]; } #if DEBUG public Dictionary.KeyCollection Types => TypeToIndex.Keys; #endif } }