Пример #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);
        }
 public ProcessGroup(EntityManager em, EntityQueryBuilder entities)
 {
     _entities     = entities;
     _em           = em;
     _items        = new Dictionary <Entity, bool>();
     _queryBuilder = _entities.WithAllReadOnly <TComponent, TMarker>();
 }
Пример #8
0
        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
        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
        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
    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);
        }