parent
6c8108e3ea
commit
d9b66edd89
18 changed files with 221 additions and 58 deletions
@ -1,25 +1,30 @@ |
|||||||
using System; |
using Unity.Burst; |
||||||
|
|
||||||
namespace GameCore.TinyECS |
namespace GameCore.TinyECS |
||||||
{ |
{ |
||||||
public struct ComponentId |
internal static class ComponentIdHelper |
||||||
{ |
{ |
||||||
struct Inner<T> where T : unmanaged |
public static int currentId; |
||||||
{ |
} |
||||||
public int id; |
|
||||||
private Inner(int i) => id = i; |
public struct ComponentId<T> |
||||||
public static Inner<T> Instance = default; |
{ |
||||||
} |
public int id; |
||||||
|
public static readonly SharedStatic<ComponentId<T>> Instance = SharedStatic<ComponentId<T>>.GetOrCreate<ComponentId<T>>(); |
||||||
static int currentId; |
|
||||||
|
|
||||||
public static int Get<T>() where T : unmanaged |
[BurstDiscard] |
||||||
|
static void EnsureInitialized() |
||||||
{ |
{ |
||||||
if (Inner<T>.Instance.id == 0) |
if (Instance.Data.id == 0) |
||||||
{ |
{ |
||||||
Inner<T>.Instance.id = ++currentId; |
Instance.Data.id = ++ComponentIdHelper.currentId; |
||||||
} |
} |
||||||
return Inner<T>.Instance.id; |
} |
||||||
|
|
||||||
|
public static int Get() |
||||||
|
{ |
||||||
|
EnsureInitialized(); |
||||||
|
return Instance.Data.id; |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
Loading…
Reference in new issue