public void ValidateMatchesCache_WithMismatchedDelegateTypeIndices_Throws() { var cache = new EntityQueryCache(1); var builder = new EntityQueryBuilder().WithAll <EcsTestTag>(); int index; fixed(int *delegateTypes = new[] { 1 }) index = cache.CreateCachedQuery(0, k_DummyGroup, ref builder, delegateTypes, 1); Assert.Throws <InvalidOperationException>(() => cache.ValidateMatchesCache(index, ref builder, null, 0)); // note: can't use a `fixed` var inside a closure, so below we implement a manual Assert.Throws InvalidOperationException testException0 = null; try { fixed(int *anotherDelegateTypes0 = new[] { 2 }) cache.ValidateMatchesCache(index, ref builder, anotherDelegateTypes0, 1); } catch (InvalidOperationException x) { testException0 = x; } Assert.NotNull(testException0); InvalidOperationException testException1 = null; try { fixed(int *anotherDelegateTypes1 = new[] { 1, 2 }) cache.ValidateMatchesCache(index, ref builder, anotherDelegateTypes1, 2); } catch (InvalidOperationException x) { testException1 = x; } Assert.NotNull(testException1); }
/// <summary> /// resumes all timers /// </summary> /// <param name="entities">A reference to the EntityQueryBuilder instance</param> public static void ResumeAllTimers(EntityQueryBuilder entities) { entities.ForEach((ref Timer timer) => { timer.isPaused = false; }); }
/// <summary> /// 返回满足条件的一组实体对象。 /// </summary> /// <param name="condition">一般的条件语句。</param> /// <param name="orderBy">排序语句。</param> /// <param name="segment">数据分段对象。</param> /// <param name="parameters">查询参数集合。</param> /// <returns></returns> public virtual IEnumerable <object> Query(string condition, string orderBy, IDataSegment segment = null, ParameterCollection parameters = null) { var syntax = Database.Provider.GetService <ISyntaxProvider>(); var query = new EntityQueryBuilder(syntax, Environment, GetEntityType(), parameters).Select().All().From().Where(condition).OrderBy(orderBy); return(Database.InternalExecuteEnumerable(GetEntityType(), query.ToSqlCommand(), segment, parameters).Cast <object>()); }
/// <summary> /// Marks a scene for unloading /// </summary> /// <param name="entityManager">Reference to the entitymanager instance</param> /// <param name="entities">A reference tot the entityquerybuilder instance named entities</param> /// <param name="sceneNumberToUnload">The index fo the scene to unload</param> /// <returns>Weather or not the scene is succesfully marked for unloading</returns> public static bool MarkSceneForUnload(EntityManager entityManager, EntityQueryBuilder entities, int sceneNumberToUnload) { NativeArray <ScenesLoaded> scenesLoaded = entityManager.GetBuffer <ScenesLoaded>(_sceneHandler).ToNativeArray(Allocator.Temp); if (!entityManager.HasComponent <Indestructable>(scenesLoaded[sceneNumberToUnload].referenceEntity)) { try { entities.ForEach((DynamicBuffer <ScenesToUnload> scenesToLoad) => { scenesToLoad.Add(new ScenesToUnload { sceneNumber = sceneNumberToUnload, doByNumber = true }); }); return(true); } catch (Exception e) { Debug.Log(e.ToString()); } } scenesLoaded.Dispose(); return(false); }
protected override void OnUpdate() { EntityQueryBuilder queryBuilder = Entities.WithAll(typeof(MoveComponent), typeof(Translation), typeof(EnemyComponent)); queryBuilder.ForEach((ref MoveComponent move, ref Translation translation, ref EnemyComponent enemyComponent) => { //move.speed += move.acc * Time.DeltaTime; translation.Value += new float3(move.dragDir * Time.DeltaTime, 0); }); queryBuilder = Entities.WithAll(typeof(MoveComponent), typeof(Translation), typeof(Rotation)); queryBuilder.ForEach((ref MoveComponent move, ref Translation translation, ref Rotation rotation) => { move.acc = move.dragDir * math.lerp(0, GameSetting.Instance.maxAccDirStep, move.dragDirLenth) * GameSetting.Instance.playerAccParam; move.speed += move.acc * Time.DeltaTime; move.speed = math.clamp(move.speed, -move.maxSpeed, move.maxSpeed); if (!move.speed.Equals(float2.zero)) { float2 nspeed = math.normalize(move.speed); float angle = nspeed.x > 0 ? math.acos(nspeed.y) : -math.acos(nspeed.y); rotation.Value = quaternion.AxisAngle(zAxis, angle); } translation.Value += new float3(move.speed * Time.DeltaTime, 0); }); }
/// <summary> /// Marks a scene for unloading /// </summary> /// <param name="entityManager">Reference to the entitymanager instance</param> /// <param name="entities">A reference tot the entityquerybuilder instance named entities</param> /// <param name="sceneToUnload">The Entity with the SceneData component</param> /// <returns>Weather or not the scene is succesfully marked for unloading</returns> public static bool MarkSceneForUnload(EntityManager entityManager, EntityQueryBuilder entities, Entity sceneToUnload) { if (!entityManager.HasComponent <Indestructable>(sceneToUnload)) { try { entities.ForEach((DynamicBuffer <ScenesToUnload> scenesToLoad) => { scenesToLoad.Add(new ScenesToUnload { scene = sceneToUnload, doByNumber = false }); }); return(true); } catch (Exception e) { Debug.Log(e.ToString()); } } return(false); }
public ProcessGroup(EntityManager em, EntityQueryBuilder entities) { _entities = entities; _em = em; _items = new Dictionary <Entity, bool>(); _queryBuilder = _entities.WithAllReadOnly <TComponent, TMarker>(); }
public static NativeList <Empty> GetEmptyEntities(this EntityQueryBuilder builder) { var result = new NativeList <Empty>(Allocator.Temp); builder.WithAll <Empty>().ForEach((Entity e, ref Empty empty) => result.Add(empty)); return(result); }
public static NativeList <Entity> GetCellEntities(this EntityQueryBuilder builder) { var result = new NativeList <Entity>(Allocator.Temp); builder.WithAll <Cell>().ForEach((Entity e) => result.Add(e)); return(result); }
protected virtual void BuildDefaultQueries() { var qBuilder = new EntityQueryBuilder(this); _detailQry = qBuilder.BuildDetailQry(); BuildRelatedFIeldQueries(qBuilder); }
protected override void BuildDefaultQueries() { var qBuilder = new EntityQueryBuilder(this); _detailQry = qBuilder.BuildDetailQry(true); BuildRelatedFIeldQueries(qBuilder); }
public static void AddMissingBuffers(EntityQueryBuilder builder, EntityQuery query, EntityManager entityManager) { var ecb = new EntityCommandBuffer(Allocator.Temp); builder.With(query).ForEach(e => ecb.AddBuffer <T>(e)); ecb.Playback(entityManager); ecb.Dispose(); }
public void With_Should_return_EntitySetBuilder() { using World world = new(); EntityQueryBuilder builder = world.GetEntities(); Check.That(builder.WithEither <bool>().With <int>()).IsEqualTo(builder); }
public void Copy_Should_return_different_instance() { using World world = new(); EntityQueryBuilder builder = world.GetEntities(); EntityQueryBuilder copy = builder.WithEither <bool>().Copy(); Check.That(copy).IsNotEqualTo(builder); }
static void SimpleWrapCreateCachedQuery(EntityQueryCache cache, uint hash, EntityQuery group) { #if ENABLE_UNITY_COLLECTIONS_CHECKS var builder = new EntityQueryBuilder(); cache.CreateCachedQuery(hash, group, ref builder, null, 0); #else cache.CreateCachedQuery(hash, group); #endif }
public GameStateHelper(EntityManager em, EntityQueryBuilder entities) { _entities = entities; _em = em; Entity game = Entity.Null; _entities.WithAllReadOnly <GameComponent>().ForEach(entity => { game = entity; }); _game = game; }
public Process(EntityManager em, EntityQueryBuilder entities, TComponent component, TMarker marker) { _entities = entities; _em = em; _queryBuilder = _entities.WithAllReadOnly <TComponent, TMarker>(); _client = _em.CreateEntity(typeof(TComponent), typeof(TMarker)); _em.SetComponentData(_client, component); _em.SetComponentData(_client, marker); }
/// <summary> /// Set a new scenerefernce to spawn /// </summary> /// <param name="entities">A reference to the entityquerybuilder instance</param> /// <param name="ID">The ID of the spawner to trigger</param> /// <param name="sceneReference">The new scenereference to spawn</param> public static void SetSceneReference(EntityQueryBuilder entities, uint ID, SceneReference sceneReference) { entities.ForEach((ref Spawner spawner) => { if (spawner.ID == ID) { spawner.sceneReferenceToSpawn = sceneReference; } }); }
/// <summary> /// resumes the timer /// </summary> /// <param name="ID">The ID of the timer</param> /// <param name="entities">A reference to the EntityQueryBuilder instance</param> public static void ResumeTimer(uint ID, EntityQueryBuilder entities) { entities.ForEach((ref Timer timer) => { if (timer.ID == ID) { timer.isPaused = false; } }); }
/// <summary> /// set the maxTime for a timer /// </summary> /// <param name="ID">The ID of the timer</param> /// <param name="entities">A reference to the EntityQueryBuilder instance</param> /// <param name="time">The max time to set the timer to</param> public static void SetMaxTime(uint ID, EntityQueryBuilder entities, float time) { entities.ForEach((ref Timer timer) => { if (timer.ID == ID) { timer.maxTime = time; } }); }
/// <summary> /// Resume a spawner to spawning scenes /// </summary> /// <param name="entities">A reference to the entityquerybuilder instance</param> /// <param name="ID">The ID of the spawner to trigger</param> public static void ResumeSpawning(EntityQueryBuilder entities, uint ID) { entities.ForEach((ref Spawner spawner) => { if (spawner.ID == ID) { spawner.isSpawningPaused = false; } }); }
/// <summary> /// Set a spawner to a new spawntype /// </summary> /// <param name="entities">A reference to the entityquerybuilder instance</param> /// <param name="ID">The ID of the spawner to trigger</param> /// <param name="type">The new spawntype</param> public static void SetSpawnMode(EntityQueryBuilder entities, uint ID, SpawnType type) { entities.ForEach((ref Spawner spawner) => { if (spawner.ID == ID) { spawner.spawnType = type; } }); }
/// <summary> /// Set a new absolute spawning position /// </summary> /// <param name="entities">A reference to the entityquerybuilder instance</param> /// <param name="ID">The ID of the spawner to trigger</param> /// <param name="newPos">The new absolute position</param> public static void SetSpawnPos(EntityQueryBuilder entities, uint ID, float2 newPos) { entities.ForEach((ref Spawner spawner) => { if (spawner.ID == ID) { spawner.spawnPos = newPos; } }); }
/// <summary> /// Set a new relative spawning position /// </summary> /// <param name="entities">A reference to the entityquerybuilder instance</param> /// <param name="ID">The ID of the spawner to trigger</param> /// <param name="newOffset">The new relative position</param> public static void SetSpawnOffset(EntityQueryBuilder entities, uint ID, float2 newOffset) { entities.ForEach((ref Spawner spawner) => { if (spawner.ID == ID) { spawner.spawnOffset = newOffset; } }); }
/// <summary> /// Triggers both timed and manual spawners to spawn /// </summary> /// <param name="entities">A reference to the entityquerybuilder instance</param> /// <param name="ID">The ID of the spawner to trigger</param> public static void Trigger(EntityQueryBuilder entities, uint ID) { entities.ForEach((ref Spawner spawner) => { if (spawner.ID == ID) { spawner.isTriggered = true; } }); }
/// <summary> /// Set the spawner to spawn with or without position and/or offset /// </summary> /// <param name="entities">A reference to the entityquerybuilder instance</param> /// <param name="ID">The ID of the spawner to trigger</param> /// <param name="translationType">The type of translation you want to add to all entities in the scene</param> public static void SetTranslationType(EntityQueryBuilder entities, uint ID, TranslationType translationType) { entities.ForEach((ref Spawner spawner) => { if (spawner.ID == ID) { spawner.translationType = translationType; } }); }
public void QueryBuilderExcludesTypes() { using EntityManager manager = new EntityManager(); var builder = new EntityQueryBuilder() .Exclude <Position>() .Exclude <Rotation>() .Exclude <Velocity>(); Assert.True(builder.excludeCount == 3); }