2022-12-13 08:34:35 +00:00
|
|
|
|
using System;
|
2022-12-03 07:43:54 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace MoonTools.ECS
|
|
|
|
|
{
|
|
|
|
|
public class TypeIndices
|
|
|
|
|
{
|
|
|
|
|
Dictionary<Type, int> TypeToIndex = new Dictionary<Type, int>();
|
|
|
|
|
int nextID = 0;
|
2022-12-06 09:59:22 +00:00
|
|
|
|
public int Count => TypeToIndex.Count;
|
2022-12-03 07:43:54 +00:00
|
|
|
|
|
|
|
|
|
public int GetIndex<T>() 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];
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 09:59:22 +00:00
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
#if DEBUG
|
2022-12-13 08:34:35 +00:00
|
|
|
|
public Dictionary<Type, int>.KeyCollection Types => TypeToIndex.Keys;
|
2022-12-03 07:43:54 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|