2023-06-27 05:09:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-07-04 00:00:25 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2023-06-27 05:09:41 +08:00
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
|
|
|
|
{
|
|
|
|
|
namespace Internal
|
|
|
|
|
{
|
|
|
|
|
internal static class EcsTypeCode
|
|
|
|
|
{
|
|
|
|
|
private static readonly Dictionary<Type, int> _codes = new Dictionary<Type, int>();
|
|
|
|
|
private static int _incremetn = 1;
|
2023-07-04 00:00:25 +08:00
|
|
|
|
public static int Count => _codes.Count;
|
|
|
|
|
public static int Get(Type type)
|
2023-06-27 05:09:41 +08:00
|
|
|
|
{
|
|
|
|
|
if (!_codes.TryGetValue(type, out int code))
|
|
|
|
|
{
|
|
|
|
|
code = _incremetn++;
|
|
|
|
|
_codes.Add(type, code);
|
|
|
|
|
}
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2023-07-04 00:00:25 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public static int Get<T>() => Cache<T>.code;
|
|
|
|
|
private static class Cache<T>
|
2023-06-29 00:56:26 +08:00
|
|
|
|
{
|
2023-07-04 00:00:25 +08:00
|
|
|
|
public static readonly int code = Get(typeof(T));
|
2023-06-29 00:56:26 +08:00
|
|
|
|
}
|
2023-06-27 05:09:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|