/// <summary> /// возвращаем первую ентити у которой есть необходимые нам компоненты /// </summary> /// <param name="outEntity"></param> /// <param name="componentIDs"></param> public bool TryGetEntityByComponents(out IEntity outEntity, ref HECSMask mask) { if (cacheTryGet.TryGetValue(mask, out outEntity)) { if (outEntity.IsAlive) { return(true); } else { cacheTryGet.Remove(mask); } } var count = EntitiesCount; for (int i = 0; i < count; i++) { var currentEntity = Entities[i]; if (currentEntity.ContainsMask(ref mask)) { outEntity = currentEntity; cacheTryGet.Add(mask, currentEntity); return(true); } } outEntity = null; return(false); }
/// <summary> /// Если нам нужно убедиться что такая ентити существует, или дождаться когда она появиться, /// то мы отправляем команду ожидать появления нужной сущности /// </summary> /// <typeparam name="T"></typeparam> /// <param name="command"></param> /// <param name="waitForComponent"></param> public void Command <T>(T command, ref HECSMask waitForComponent) where T : ICommand, IGlobalCommand { if (TryGetEntityByComponents(out var entity, ref waitForComponent)) { commandService.Invoke(command); } waitingCommandsSystems.AddWaitingCommand(command, waitForComponent); }
public Filter(World world, HECSMask includeComponents, HECSMask excludeComponents) { this.world = world; mask = includeComponents; excludeMask = excludeComponents; world.AddGlobalReactComponent(this); world.AddEntityListener(this, true); GatherEntities(world); }
public bool TryGetHecsComponent <T>(HECSMask mask, out T component) where T : IComponent { var needed = components[mask.Index]; if (needed != null && needed is T cast) { component = cast; return(true); } component = default; return(false); }
public List <IEntity> GetFilter(HECSMask include, HECSMask exclude) { int sumMask = include.GetHashCode(); sumMask += exclude.GetHashCode(); if (filters.TryGetValue(sumMask, out var filter)) { return(filter.Entities); } var nf = new Filter(world, include, exclude); filters.Add(sumMask, nf); return(nf.Entities); }
public List <IEntity> Filter(HECSMask include) => entityFilter.GetFilter(include);
public bool ContainsMask(ref HECSMask mask) { return(componentsMask.Contain(ref mask)); }
public void RemoveHecsComponent(HECSMask component) { var needed = components[component.Index]; RemoveHecsComponent(needed); }
public bool TryGetComponentFromEntity <T>(out T component, ref HECSMask owner, ref HECSMask neededComponent, int worldIndex) where T : IComponent => worlds[worldIndex].TryGetComponentFromEntity(out component, ref owner, ref neededComponent);
public List <IEntity> GetFilter(HECSMask include) { return(GetFilter(include, HECSMask.Empty)); }
public T GetHECSComponent <T>(ref HECSMask owner, int worldIndex = 0) => worlds[worldIndex].GetHECSComponent <T>(ref owner);
public bool TryGetSystemFromEntity <T>(ref HECSMask mask, out T system, int worldIndex = 0) where T : ISystem { var world = Instance.worlds[worldIndex]; return(world.TryGetSystemFromEntity(ref mask, out system)); }
/// <summary> /// возвращаем первую ентити у которой есть необходимые нам компоненты /// </summary> /// <param name="outEntity"></param> /// <param name="componentIDs"></param> public static bool TryGetEntityByComponents(out IEntity outEntity, ref HECSMask mask, int worldIndex = 0) { var world = Instance.worlds[worldIndex]; return(world.TryGetEntityByComponents(out outEntity, ref mask)); }
public static List <IEntity> Filter(HECSMask include, int worldIndex = 0) => Instance.worlds[worldIndex].Filter(include);
/// <summary> /// Если нам нужно убедиться что такая ентити существует, или дождаться когда она появиться, /// то мы отправляем команду ожидать появления нужной сущности /// </summary> /// <typeparam name="T"></typeparam> /// <param name="command"></param> /// <param name="waitForComponent"></param> public static void Command <T>(T command, ref HECSMask waitForComponent, int worldIndex = 0) where T : ICommand, IGlobalCommand => Worlds[worldIndex].Command(command, ref waitForComponent);