2024-08-17 14:27:18 +08:00
|
|
|
|
using System;
|
|
|
|
|
using JNGame.Util.Types;
|
|
|
|
|
|
2024-09-29 20:18:48 +08:00
|
|
|
|
namespace JNGame.Runtime.Entitas
|
2024-08-17 14:27:18 +08:00
|
|
|
|
{
|
|
|
|
|
public abstract class JNLookup
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private int _index = 0;
|
|
|
|
|
|
2024-08-31 21:05:29 +08:00
|
|
|
|
public int Count => _index;
|
2024-08-17 14:27:18 +08:00
|
|
|
|
|
|
|
|
|
public int Next()
|
|
|
|
|
{
|
|
|
|
|
return _index++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly KeyValue<int, Type> _types = new();
|
|
|
|
|
|
|
|
|
|
public JNLookup()
|
|
|
|
|
{
|
|
|
|
|
BindIndex();
|
|
|
|
|
BindType(_types);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract void BindIndex();
|
|
|
|
|
protected abstract void BindType(KeyValue<int, Type> types);
|
|
|
|
|
|
|
|
|
|
//查询下标
|
|
|
|
|
public int GetIndex(Type type)
|
|
|
|
|
{
|
|
|
|
|
return _types.Value2Key(type);
|
|
|
|
|
}
|
|
|
|
|
//查询下标
|
|
|
|
|
public int GetIndex<T>()
|
|
|
|
|
{
|
|
|
|
|
return _types.Value2Key(typeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|