コード例 #1
0
        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);
        }
コード例 #2
0
 /// <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;
     });
 }
コード例 #3
0
        /// <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>());
        }
コード例 #4
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="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);
        }
コード例 #5
0
    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);
        });
    }
コード例 #6
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);
        }
コード例 #7
0
 public ProcessGroup(EntityManager em, EntityQueryBuilder entities)
 {
     _entities     = entities;
     _em           = em;
     _items        = new Dictionary <Entity, bool>();
     _queryBuilder = _entities.WithAllReadOnly <TComponent, TMarker>();
 }
コード例 #8
0
ファイル: SystemsHelper.cs プロジェクト: Nelar/Match3
        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);
        }
コード例 #9
0
ファイル: SystemsHelper.cs プロジェクト: Nelar/Match3
        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);
        }
コード例 #10
0
ファイル: DBEntity.cs プロジェクト: vipsingh/StackAppCore
        protected virtual void BuildDefaultQueries()
        {
            var qBuilder = new EntityQueryBuilder(this);

            _detailQry = qBuilder.BuildDetailQry();

            BuildRelatedFIeldQueries(qBuilder);
        }
コード例 #11
0
        protected override void BuildDefaultQueries()
        {
            var qBuilder = new EntityQueryBuilder(this);

            _detailQry = qBuilder.BuildDetailQry(true);

            BuildRelatedFIeldQueries(qBuilder);
        }
コード例 #12
0
ファイル: EventSystem.cs プロジェクト: zxx2112/TankBattle
    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();
    }
コード例 #13
0
        public void With_Should_return_EntitySetBuilder()
        {
            using World world = new();

            EntityQueryBuilder builder = world.GetEntities();

            Check.That(builder.WithEither <bool>().With <int>()).IsEqualTo(builder);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
 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
 }
コード例 #16
0
        public GameStateHelper(EntityManager em, EntityQueryBuilder entities)
        {
            _entities = entities;
            _em       = em;
            Entity game = Entity.Null;

            _entities.WithAllReadOnly <GameComponent>().ForEach(entity => { game = entity; });
            _game = game;
        }
コード例 #17
0
        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);
        }
コード例 #18
0
 /// <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;
         }
     });
 }
コード例 #19
0
 /// <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;
         }
     });
 }
コード例 #20
0
 /// <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;
         }
     });
 }
コード例 #21
0
 /// <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;
         }
     });
 }
コード例 #22
0
 /// <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;
         }
     });
 }
コード例 #23
0
 /// <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;
         }
     });
 }
コード例 #24
0
 /// <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;
         }
     });
 }
コード例 #25
0
 /// <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;
         }
     });
 }
コード例 #26
0
 /// <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;
         }
     });
 }
コード例 #27
0
        public void QueryBuilderExcludesTypes()
        {
            using EntityManager manager = new EntityManager();

            var builder = new EntityQueryBuilder()
                          .Exclude <Position>()
                          .Exclude <Rotation>()
                          .Exclude <Velocity>();

            Assert.True(builder.excludeCount == 3);
        }