I find some codes in my project. I use comtext.game.SubscribeId(id) many times, but I don't know why.
[Game, Input, Debug] // contexts here
public class IdComponent : IComponent
{
[PrimaryEntityIndex]
public int value;
}
public static class ContextsIdExtensions
{
public static void SubscribeId(this Contexts contexts)
{
foreach (var context in contexts.allContexts)
{
if (Array.FindIndex(context.contextInfo.componentTypes, v => v == typeof(IdComponent)) >= 0)
{
context.OnEntityCreated += AddId;
}
}
}
public static void AddId(IContext context, IEntity entity)
{
(entity as IIdEntity).ReplaceId(entity.creationIndex);
}
}
I find some codes in my project. I use comtext.game.SubscribeId(id) many times, but I don't know why.