Example #1
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        if (m_Query.CalculateEntityCount() <= 0)
        {
            return(inputDeps);
        }

        var generator = m_GeneratorQuery.GetSingleton <LbBoardGenerator>();

        var board        = m_BoardQuery.GetSingleton <LbBoard>();
        var boardEntity  = m_BoardQuery.GetSingletonEntity();
        var bufferLookup = GetBufferFromEntity <LbDirectionMap>();

        var buffer      = bufferLookup[boardEntity];
        var bufferArray = buffer.AsNativeArray();


        var spawnerHandle = new BoardSpawnerJob()
        {
            Generator       = generator,
            Seed            = m_Random.NextUInt(),
            DirectionBuffer = bufferLookup[boardEntity].AsNativeArray(),
            CommandBuffer   = m_Barrier.CreateCommandBuffer()
        }.Schedule(inputDeps);

        var cleanUpHandle = new BoardSpawnerCleanJob()
        {
            CommandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(),
        }.Schedule(this, spawnerHandle);

        m_Barrier.AddJobHandleForProducer(cleanUpHandle);

        return(cleanUpHandle);
    }
Example #2
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        m_yellowGroup.SetFilter(new C_Shared_Team()
        {
            Team = Proxy_Bee.Team.YellowTeam
        });

        var yellowJob = new Sys_Bee_GoHomeJob()
        {
            CarryForce = BeeManager.S.CarryForce,
            Field      = Field.size,
            Team       = (int)Proxy_Bee.Team.YellowTeam,
            dt         = UnityEngine.Time.deltaTime,
            ecb        = m_entityCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
        }.Schedule(m_yellowGroup, inputDependencies);

        m_purpleGroup.SetFilter(new C_Shared_Team()
        {
            Team = Proxy_Bee.Team.PurpleTeam
        });
        var purpleJob = new Sys_Bee_GoHomeJob()
        {
            CarryForce = BeeManager.S.CarryForce,
            Field      = Field.size,
            Team       = (int)Proxy_Bee.Team.PurpleTeam,
            dt         = UnityEngine.Time.deltaTime,
            ecb        = m_entityCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
        }.Schedule(m_purpleGroup, yellowJob);

        m_entityCommandBufferSystem.AddJobHandleForProducer(yellowJob);
        m_entityCommandBufferSystem.AddJobHandleForProducer(purpleJob);

        return(purpleJob);
    }
Example #3
0
#pragma warning restore 618

    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        var newEntityJob = new NewEntityJob()
        {
            ConcurrentECB = m_ECBSource.CreateCommandBuffer().ToConcurrent()
        };
        var newJobHandle = newEntityJob.ScheduleSingle(m_newEntities, inputDependencies);

        m_ECBSource.AddJobHandleForProducer(newJobHandle);

        var processEntityJob = new ProcessEntityJob()
        {
            ConcurrentECB = m_ECBSource.CreateCommandBuffer().ToConcurrent()
        };
        var processJobHandle = processEntityJob.Schedule(m_activeEntities, newJobHandle);

        m_ECBSource.AddJobHandleForProducer(processJobHandle);

        var cleanupEntityJob = new CleanupEntityJob()
        {
            ConcurrentECB = m_ECBSource.CreateCommandBuffer().ToConcurrent()
        };
        var cleanupJobHandle = cleanupEntityJob.ScheduleSingle(m_destroyedEntities, processJobHandle);

        m_ECBSource.AddJobHandleForProducer(cleanupJobHandle);

        return(cleanupJobHandle);
    }
        private void AddCommandTween <T>(int tagId, T command, EntityQuery tweens) where T : struct, IComponentData
        {
            var totalTweens = tweens.CalculateLength();

            if (totalTweens == 0)
            {
                return;
            }
            var entities      = tweens.ToEntityArray(Allocator.TempJob);
            var tags          = tweens.ToComponentDataArray <TweenTag>(Allocator.TempJob);
            var commandBuffer = m_EndFrameSystem.CreateCommandBuffer();

            for (int i = 0; i < totalTweens; i++)
            {
                var entity = entities[i];
                var tag    = tags[i];
                if (tagId == -1 || tag.Value == tagId)
                {
                    commandBuffer.AddComponent <T>(entity, command);
                }
            }

            entities.Dispose();
            tags.Dispose();
        }
        void InitByRandomSeed()
        {
            var ecb        = _ECB.CreateCommandBuffer().AsParallelWriter();
            var randomSeed = new Random((uint)System.Environment.TickCount);

            Entities.WithNone <ExistTag, BehaviorTreeRandomSeed>()
            .ForEach((Entity entity, int nativeThreadIndex, ref BehaviorTreeRandom random) =>
            {
                random.Value.InitState(randomSeed.NextUInt());
                ecb.AddComponent <ExistTag>(nativeThreadIndex, entity);
            }).ScheduleParallel();
        }
Example #6
0
        protected override void OnUpdate()
        {
            var cb = _barrier.CreateCommandBuffer();

            Entities
            .WithNone <GameOfLifeTexture>()
            .WithAll <IsConwaysSimulation>()
            .ForEach((Entity e, ref WorldSize world) =>
            {
                if (world.Size.x <= 0)
                {
                    world.Size.x = Screen.width;
                }
                if (world.Size.y <= 0)
                {
                    world.Size.y = Screen.height;
                }
                var sizeInDemandedAreas = (int2)math.ceil(world.Size / new float2(16, 3));
                world.Size       = sizeInDemandedAreas * new int2(16, 3);
                var texture      = new Texture2D(4 * sizeInDemandedAreas.x, sizeInDemandedAreas.y, TextureFormat.RGBA32, false);
                texture.wrapMode = TextureWrapMode.Clamp;
                var array        = texture.GetRawTextureData <int4>();
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = 0;
                }
                texture.Apply();
                cb.AddComponent(e, new GameOfLifeTexture {
                    Value = texture, IsCreated = true
                });
            }).WithoutBurst().Run();
        }
Example #7
0
    protected override unsafe void OnUpdate()
    {
        var deltaTime = UnityEngine.Time.deltaTime;
        EntityCommandBuffer commandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer();

        Entities
        .WithName("ChangeColliderType")
        .WithAll <PhysicsCollider, RenderMesh>()
        .WithoutBurst()
        .ForEach((Entity entity, ref ChangeColliderType modifier) =>
        {
            modifier.LocalTime -= deltaTime;

            if (modifier.LocalTime > 0.0f)
            {
                return;
            }

            modifier.LocalTime = modifier.TimeToSwap;
            var collider       = EntityManager.GetComponentData <PhysicsCollider>(entity);
            if (collider.ColliderPtr->Type == modifier.ColliderA.ColliderPtr->Type)
            {
                commandBuffer.SetComponent(entity, modifier.ColliderB);
                commandBuffer.SetSharedComponent(entity, EntityManager.GetSharedComponentData <RenderMesh>(modifier.EntityB));
            }
            else
            {
                commandBuffer.SetComponent(entity, modifier.ColliderA);
                commandBuffer.SetSharedComponent(entity, EntityManager.GetSharedComponentData <RenderMesh>(modifier.EntityA));
            }
        }).Run();

        m_EntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
    }
Example #8
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //test if we have any requests
            if (pokemonMoveDataQuery.CalculateEntityCount() == 0 && pokemonMoveFinishEntities.CalculateEntityCount() == 0)
            {
                return(inputDeps);
            }
            NativeArray <EntityParent>   entityParents = pokemonMoveDataQuery.ToComponentDataArray <EntityParent>(Allocator.TempJob);
            NativeArray <GroupIndexInfo> parentInfos   = new NativeArray <GroupIndexInfo>(entityParents.Length, Allocator.TempJob);

            for (int i = 0; i < entityParents.Length; i++)
            {
                parentInfos[i] = EntityManager.GetComponentData <GroupIndexInfo>(entityParents[i].entity);
            }
            //preform the job
            JobHandle jh = new RemovePokemonData
            {
                pokemonMoveDataEntities = pokemonMoveDataQuery.ToEntityArray(Allocator.TempJob),
                ecb = ecbs.CreateCommandBuffer(),
                pokemonMoveDatas          = pokemonMoveDataQuery.ToComponentDataArray <PokemonMoveDataEntity>(Allocator.TempJob),
                parents                   = entityParents,
                parentInfos               = parentInfos,
                pokemonMoveEntityEntities = pokemonMoveFinishEntities.ToEntityArray(Allocator.TempJob),
                hasParticleRemoveRequest  = GetComponentDataFromEntity <ParticleSystemRemoveRequest>(),
                pokemonMoveRemoveDatas    = pokemonMoveFinishEntities.ToComponentDataArray <PokemonMoveDataEntity>(Allocator.TempJob)
            }.Schedule(inputDeps);

            jh.Complete();
            return(jh);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var glyphMap = new NativeHashMap <int, Entity>(glyphQuery.CalculateEntityCount(), Allocator.TempJob);

            var glyphMapDeps = new BuildGlyphMapJob {
                GlyphMap = glyphMap.AsParallelWriter()
            }.Schedule(glyphQuery, inputDeps);

            var textMeshDeps = new BuildTextMeshJob {
                GlyphMap           = glyphMap,
                GlyphData          = GetBufferFromEntity <GlyphElement>(true),
                FontFaces          = GetComponentDataFromEntity <FontFaceInfo>(true),
                EntityType         = GetArchetypeChunkEntityType(),
                CharBufferType     = GetArchetypeChunkBufferType <CharElement>(true),
                TextOptionType     = GetArchetypeChunkComponentType <TextOptions>(true),
                TxtFontIDType      = GetArchetypeChunkComponentType <TextFontID>(true),
                ColorType          = GetArchetypeChunkComponentType <AppliedColor>(true),
                LTWType            = GetArchetypeChunkComponentType <LocalToWorld>(true),
                DimensionType      = GetArchetypeChunkComponentType <Dimensions>(true),
                MeshVertexDataType = GetArchetypeChunkBufferType <MeshVertexData>(),
                TriangleIndexType  = GetArchetypeChunkBufferType <TriangleIndexElement>(),
                CmdBuffer          = cmdBufferSystem.CreateCommandBuffer().ToConcurrent()
            }.Schedule(textQuery, glyphMapDeps);

            var finalDeps = glyphMap.Dispose(textMeshDeps);

            cmdBufferSystem.AddJobHandleForProducer(finalDeps);

            return(finalDeps);
        }
Example #10
0
        protected override void OnUpdate()
        {
            //hacky
            var inPreround = false;

            Entities.WithAll <PreRoundPhase>().ForEach((Entity e) => inPreround = true);

            var buffer = CommandBuffer.CreateCommandBuffer();

            Entities.WithAll <Carrier>().ForEach(
                (Entity e, ref Focussing focussing, ref Carrier carrier) =>
            {
                if (inPreround)
                {
                    return;
                }
                if (focussing.Entity == Entity.Null)
                {
                    return;
                }
                if (!carrier.WantsToPickUp || focussing.Intention != FocusType.Carryable)
                {
                    return;
                }
                var pickup = buffer.CreateEntity();
                buffer.AddComponent(pickup,
                                    new PickingUp {
                    Carrier = e, Carryable = focussing.Entity
                }
                                    );
                buffer.AddComponent(pickup, new Message());
            }
                );
        }
Example #11
0
    protected override void OnUpdate()
    {
        var ecb = _ecbSystem.CreateCommandBuffer().AsParallelWriter();
        var dt  = Time.DeltaTime;

        Entities.ForEach((Entity entity, int entityInQueryIndex, DynamicBuffer <PathPosition> pathPositionBuffer, ref Translation translation,
                          ref PathIndex pathIndex) =>
        {
            if (pathIndex.Value >= 0)
            {
                int2 pathPosition = pathPositionBuffer[pathIndex.Value].Value;

                float3 targetPosition = new float3(pathPosition.x, translation.Value.y, pathPosition.y);
                float3 moveDirection  = math.normalizesafe(targetPosition - translation.Value);
                float moveSpeed       = 3f;

                translation.Value += moveDirection * moveSpeed * dt;
                if (math.distance(translation.Value, targetPosition) < .1f)
                {
                    //next waypoint
                    pathIndex.Value--;
                }
            }
            else
            {
                ecb.AddComponent(entityInQueryIndex, entity, new AwaitingOrder());
            }
        }).ScheduleParallel();
    }
Example #12
0
    protected override void OnUpdate()
    {
        var commandBuffer = enityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter();

        Entities.ForEach((Entity entity, int entityInQueryIndex, ref SpawnerComponent spawner, ref LocalToWorld location) =>
        {
            for (var x = 0; x < spawner.countX; x++)
            {
                for (var y = 0; y < spawner.countY; y++)
                {
                    for (int z = 0; z < spawner.countZ; z++)
                    {
                        var instance = commandBuffer.Instantiate(entityInQueryIndex, spawner.entity);

                        // Place the instantiated in a grid with some noise
                        var position = math.transform(location.Value, new float3(x * spawner.spaceX, y * spawner.spaceY, z * spawner.spaceZ));
                        commandBuffer.SetComponent(entityInQueryIndex, instance, new Translation {
                            Value = position
                        });
                    }
                }
            }

            commandBuffer.DestroyEntity(entityInQueryIndex, entity);
        })
        .WithName("SpawnerSystem")
        .ScheduleParallel();

        enityCommandBufferSystem.AddJobHandleForProducer(Dependency);
    }
Example #13
0
    protected override void OnUpdate()
    {
        EntityCommandBuffer.Concurrent ECB = ECBSystem.CreateCommandBuffer().ToConcurrent();
        float deltaTime = Time.DeltaTime;

        Entities
        .ForEach((int entityInQueryIndex, ref FireCooldown fireCooldown, in TurretInput input, in FireInterval fireInterval, in FireSpeed fireSpeed, in LocalToWorld localToWorld, in ProjectilePrefab projectilePrefab, in ProjectileSpawnPoint spawnPointData) =>
        {
            //decrease the cooldown
            if (fireCooldown.Value > 0f)
            {
                fireCooldown.Value -= deltaTime;
            }

            if (input.Fire &&
                fireCooldown.Value <= 0f)
            {
                //fire!
                Entity newProjectile = ECB.Instantiate(entityInQueryIndex, projectilePrefab.Reference);

                //override a few components to position, rotate and push the newly created bullet
                ECB.SetComponent <Translation>(entityInQueryIndex, newProjectile, new Translation {
                    Value = math.transform(localToWorld.Value, spawnPointData.LocalTranslation)
                });
                quaternion worldRotation = math.mul(localToWorld.Rotation, spawnPointData.LocalRotation);
                ECB.SetComponent <Rotation>(entityInQueryIndex, newProjectile, new Rotation {
                    Value = worldRotation
                });
                ECB.SetComponent <PhysicsVelocity>(entityInQueryIndex, newProjectile, new PhysicsVelocity {
                    Linear = fireSpeed.Value * math.forward(worldRotation)
                });

                fireCooldown.Value = fireInterval.Value;
            }
        }).ScheduleParallel();
Example #14
0
    protected override void OnUpdate()
    {
        var translationType      = GetArchetypeChunkComponentType <Translation>(true);
        var factionComponentType = GetArchetypeChunkComponentType <FactionComponent>(true);
        var batteryComponentType = GetArchetypeChunkComponentType <BatteryComponent>();

        var random = new Unity.Mathematics.Random((uint)UnityEngine.Random.Range(1, 100000));

        var job = new FireJob
        {
            deltaTime            = Time.DeltaTime,
            commandBuffer        = barrier.CreateCommandBuffer().ToConcurrent(),
            prefab               = prefab,
            random               = random,
            entities             = group.ToEntityArray(Allocator.TempJob),
            factions             = GetComponentDataFromEntity <FactionComponent>(true),
            translations         = GetComponentDataFromEntity <Translation>(true),
            batteryComponentType = batteryComponentType,
            factionComponentType = factionComponentType,
            translationType      = translationType,
        };

        Dependency = job.Schedule(group, Dependency);
        barrier.AddJobHandleForProducer(Dependency);
    }
        protected override void OnUpdate()
        {
            var commandBuffer = _entityCommandBufferSystem.CreateCommandBuffer();

            Entities.ForEach((Entity unitEntity, ref HasTarget hasTarget, ref Translation translation) =>
            {
                var targetExist = EntityManager.Exists(hasTarget.targetEntity);
                if (targetExist)
                {
                    // Debug.Log($"has target");
                    var targetTranslation = EntityManager.GetComponentData <Translation>(hasTarget.targetEntity);
                    var targetDirection   = math.normalize(targetTranslation.Value - translation.Value);
                    // var moveSpeed = 10.0f;
                    var moveSpeed = Random.Range(2.0f, 10.0f);

                    translation.Value += targetDirection * moveSpeed * Time.DeltaTime;

                    if (math.distance(translation.Value, targetTranslation.Value) < 0.2f)
                    {
                        Debug.Log($"move close to {hasTarget.targetEntity}");
                        commandBuffer.DestroyEntity(hasTarget.targetEntity);
                        commandBuffer.RemoveComponent <HasTarget>(unitEntity);
                    }
                }
                else
                {
                    commandBuffer.RemoveComponent <HasTarget>(unitEntity);
                }
            })
            .WithoutBurst()
            .Run();
        }
        protected override void OnUpdate()
        {
            var commandBuffer = commandBufferSystem.CreateCommandBuffer();

            Entities
            .WithoutBurst()
            .WithSharedComponentFilter(new EffectTriggerApplyEffectType {
                EffectType = EffectType.Damage
            })
            .ForEach((int entityInQueryIndex, Entity entity, in EffectTriggerApplyData effectTriggerApplyData) =>
            {
                commandBuffer.DestroyEntity(entity);

                if (!entityManager.Exists(effectTriggerApplyData.Target))
                {
                    return;
                }

                var buffer = entityManager.GetBuffer <DamageToApplyBufferElement>(effectTriggerApplyData.Target);
                buffer.Add((int)effectTriggerApplyData.Value);
            })
            .Run();

            commandBufferSystem.AddJobHandleForProducer(Dependency);
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var boardCount = m_BoardQuery.CalculateEntityCount();

        if (boardCount <= 0)
        {
            return(inputDeps);
        }

        var   board     = m_BoardQuery.GetSingleton <LbBoard>();
        float deltaTime = Mathf.Clamp(Time.deltaTime, 0.0f, 0.3f);

        var handle = new PlayerCursorJob()
        {
            BoardSize     = new int2(board.SizeX, board.SizeY),
            Seed          = m_Random.NextInt(),
            CommandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(),

            MovementType    = GetArchetypeChunkComponentType <LbMovementTarget>(),
            DistanceType    = GetArchetypeChunkComponentType <LbDistanceToTarget>(),
            ArrowPrefabType = GetArchetypeChunkComponentType <LbArrowPrefab>(),
            PlayerType      = GetArchetypeChunkComponentType <LbPlayer>(),
        }.Schedule(m_Query, inputDeps);

        return(handle);
    }
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        JobHandle job = new JobHandle();



        var commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent();


        ShotPositions = m_Group.ToComponentDataArray <Translation>(Allocator.Persistent);
        Tags          = m_Group.ToComponentDataArray <ShotTag>(Allocator.Persistent);
        Shots         = m_Group.ToEntityArray(Allocator.Persistent);
        for (int i = 0; i < ShotPositions.Length; i++)
        {
            job.Complete();

            job = new MPShotCollidingJob
            {
                shotTag       = Tags[i].Character,
                ShotIndex     = Shots[i].Index,
                ShotPos       = ShotPositions[i].Value,
                CommandBuffer = commandBuffer,
            }.Schedule(this, inputDependencies);

            m_Barrier.AddJobHandleForProducer(job);
        }

        Shots.Dispose();
        ShotPositions.Dispose();
        Tags.Dispose();
        return(job);
    }
Example #19
0
        protected override void OnUpdate()
        {
            var buffer = BufferSystem.CreateCommandBuffer();

            float dt = Time.DeltaTime;

            Entities.WithNone <SpawnWaveComponent>().ForEach(
                (
                    ref WaveSpawner spawner,
                    in DynamicBuffer <SpawnWave> waves,
                    in Translation translation,
                    in Team team
                ) =>
            {
                spawner.CurrentTime -= dt;

                if (spawner.CurrentTime > 0f)
                {
                    return;
                }

                //Spawn a random wave
                spawner.CurrentTime = spawner.TimeBetweenWaves;

                var waveToSpawn = waves[Random.Range(0, waves.Length)].Wave;
                var spawnedWave = buffer.Instantiate(waveToSpawn);
                buffer.SetComponent(spawnedWave, translation);
                buffer.AddComponent(spawnedWave, team);
                buffer.AddComponent(spawnedWave, spawner);
            }
Example #20
0
        protected override void OnUpdate()
        {
            var cb = _barrier.CreateCommandBuffer();

            Entities
            .WithNone <GameOfLifeTexture>()
            .WithAll <IsSteppersSimulation>()
            .ForEach((Entity e, ref WorldSize world) =>
            {
                if (world.Size.x <= 0)
                {
                    world.Size.x = Screen.width;
                }
                if (world.Size.y <= 0)
                {
                    world.Size.y = Screen.height;
                }
                var texture      = new Texture2D(world.Size.x, world.Size.y, TextureFormat.R8, false);
                texture.wrapMode = TextureWrapMode.Clamp;
                var array        = texture.GetRawTextureData <int4>();
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = 0;
                }
                texture.Apply();
                cb.AddComponent(e, new GameOfLifeTexture {
                    Value = texture, IsCreated = true
                });
            }).WithoutBurst().Run();
        }
Example #21
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        EntityCommandBuffer.Concurrent buffer = bufferSystem.CreateCommandBuffer().ToConcurrent();

        //If DamageEvent => set Health component
        var jobApplyDamage = Entities
                             .ForEach((Entity e, int entityInQueryIndex, ref DynamicBuffer <DamageEvent> damageBuffer, ref Health health) =>
        {
            for (int i = damageBuffer.Length - 1; i >= 0; i--)
            {
                health.currentHealth -= damageBuffer[i].damage;
                if (health.currentHealth < 0f)
                {
                    // DIE!
                    buffer.DestroyEntity(entityInQueryIndex, e);
                    return;
                }

                damageBuffer.RemoveAt(i);
            }
        }).Schedule(inputDeps);

        //If health component was just removed => destroy the entity, spawn death FX

        return(jobApplyDamage);
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var configEntity = GetSingletonEntity <StreamingLogicConfig>();

        var config         = EntityManager.GetComponentData <StreamingLogicConfig>(configEntity);
        var cameraPosition = EntityManager.GetComponentData <LocalToWorld>(configEntity).Position;

        m_AddRequestList.Clear();
        var streamInHandle = new StreamSubScenesIn
        {
            AddRequestList     = m_AddRequestList,
            CameraPosition     = cameraPosition,
            MaxDistanceSquared = config.DistanceForStreamingIn * config.DistanceForStreamingIn
        }.ScheduleSingle(this, inputDeps);

        m_RemoveRequestList.Clear();
        var streamOutHandle = new StreamSubScenesOut
        {
            RemoveRequestList  = m_RemoveRequestList,
            CameraPosition     = cameraPosition,
            MaxDistanceSquared = config.DistanceForStreamingOut * config.DistanceForStreamingOut
        }.ScheduleSingle(this, inputDeps);

        var combinedHandle = JobHandle.CombineDependencies(streamInHandle, streamOutHandle);
        var commandHandle  = new BuildCommandBufferJob
        {
            CommandBuffer      = m_EntityCommandBufferSystem.CreateCommandBuffer(),
            AddRequestArray    = m_AddRequestList.AsDeferredJobArray(),
            RemoveRequestArray = m_RemoveRequestList.AsDeferredJobArray()
        }.Schedule(combinedHandle);

        m_EntityCommandBufferSystem.AddJobHandleForProducer(commandHandle);

        return(commandHandle);
    }
        protected override void OnUpdate()
        {
            var commandBuffer = commandBufferSystem.CreateCommandBuffer().ToConcurrent();

            // Foreach entity with damage to apply -> sum damage, clear buffer and apply.
            Entities
            .WithChangeFilter <DamageToApplyBufferElement>()
            .ForEach((Entity entity, int entityInQueryIndex,
                      ref HealthPoints healthPoints, ref DynamicBuffer <DamageToApplyBufferElement> damageBuffer) =>
            {
                int damage = 0;
                for (int i = 0; i < damageBuffer.Length; i++)
                {
                    damage += damageBuffer[i].Value;
                }

                damageBuffer.Clear();

                healthPoints.Value = math.max(healthPoints.Value - damage, 0);

                if (healthPoints.Value == 0)
                {
                    commandBuffer.AddComponent <HealthDepleted>(entityInQueryIndex, entity);
                }
            })
            .ScheduleParallel();

            commandBufferSystem.AddJobHandleForProducer(Dependency);
        }
Example #24
0
        protected override void OnUpdate()
        {
            var buffer = _removeECBufferSystem.CreateCommandBuffer()
                         .SetBuffer <State>(CurrentStatesEntity);

            buffer.Clear();
        }
Example #25
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var concurrent = bufferSystem.CreateCommandBuffer().ToConcurrent();
        //添加View所需组件
        var addJob1 = new AddCommponentJob();

        addJob1.concurrent = concurrent;
        inputDeps          = addJob1.Schedule(nonMassQuery, inputDeps);

        var addJob2 = new AddCommponentJob();

        addJob2.concurrent = concurrent;
        inputDeps          = addJob2.Schedule(nonScaleQuery, inputDeps);

        var addMoverJob = new AddMoverJob();

        addMoverJob.concurrent = concurrent;
        inputDeps = addMoverJob.Schedule(nonMoverQuery, inputDeps);

        //添加View
        //var addViewJob = new AddViewJob();
        //addViewJob.concurrent = concurrent;
        //inputDeps = addViewJob .Schedule(nonViewQuery, inputDeps);
        return(inputDeps);
    }
Example #26
0
        protected unsafe override void OnUpdate()
        {
            var current = new int2(Screen.width, Screen.height);

            if (res->Equals(current))
            {
                return;
            }

            *     res   = current;
            int2 *local = res;

            var cmdBuffer = cmdBufferSystem.CreateCommandBuffer();

            Dependency = Entities.ForEach((ref LocalToWorld c2, in ReferenceResolution c0, in WidthHeightRatio c1) => {
                var logWidth  = math.log2(local->x / c0.Value.x);
                var logHeight = math.log2(local->y / c0.Value.y);
                var avg       = math.lerp(logWidth, logHeight, c1.Value);
                var scale     = math.pow(2, avg);
                var center    = new float3(local->xy / 2, 0);

                c2 = new LocalToWorld {
                    Value = float4x4.TRS(center, c2.Rotation, new float3(scale))
                };
            }).WithNativeDisableUnsafePtrRestriction(local).Schedule(Dependency);
Example #27
0
        protected override JobHandle OnUpdate(JobHandle inputDependencies)
        {
            Entity avatarEntity = Entity.Null;

            var entities = EntityManager.GetAllEntities();

            foreach (var entity in entities)
            {
                if (EntityManager.HasComponent <AvatarComponent>(entity))
                {
                    avatarEntity = entity;
                    break;
                }
            }
            entities.Dispose();

            if (Entity.Null == avatarEntity || EntityManager.HasComponent <EyesightComponent>(avatarEntity))
            {
                return(inputDependencies);
            }

            var job = new SearchSystemJob()
            {
                xPos         = EntityManager.GetComponentData <Translation>(avatarEntity).Value.x,
                xDir         = EntityManager.GetComponentData <VelocityComponent>(avatarEntity).xValue,
                propComp     = EntityManager.GetComponentData <AvatarComponent>(avatarEntity),
                avatarEntity = avatarEntity,
                cmdBuf       = _cmdSystem.CreateCommandBuffer().ToConcurrent()
            };

            var handle = job.Schedule(this, inputDependencies);

            _cmdSystem.AddJobHandleForProducer(handle);
            return(handle);
        }
Example #28
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var commandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent();

        var jobHandle = Entities
                        .WithBurst(FloatMode.Default, FloatPrecision.Standard, true)
                        .ForEach((Entity entity, int entityInQueryIndex, ref SpawnerComponent spawner) =>
        {
            for (var x = 0; x < spawner.spawnerValue; x++)
            {
                var instance = commandBuffer.Instantiate(entityInQueryIndex, spawner.prefabToSpawn);

                // Place the instantiated in a grid with some noise
                var position = new float3(0, 12, 0);
                commandBuffer.SetComponent(entityInQueryIndex, instance, new Translation {
                    Value = position
                });
            }

            commandBuffer.DestroyEntity(entityInQueryIndex, entity);
        }).Schedule(inputDeps);

        m_EntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);

        return(jobHandle);
    }
    //[RequireComponentTag(typeof(MovingCube))]
    //struct MoveRandomJob : IJobForEachWithEntity<Translation, MoveRandom>
    //{
    //    public float DeltaTime;

    //    [WriteOnly]
    //    public EntityCommandBuffer.Concurrent CommandBuffer;

    //    // The [ReadOnly] attribute tells the job scheduler that this job will not write to rotSpeedSpawnAndRemove
    //    public void Execute(Entity entity, int index, ref Translation translation, ref MoveRandom moving)
    //    {
    //        // Rotate something about its up vector at the speed given by RotationSpeed_SpawnAndRemove.
    //        translation.Value = new float3(translation.Value.x + moving.Direction.x * DeltaTime, translation.Value.y + DeltaTime * moving.Direction.y, translation.Value.z + moving.Direction.z * DeltaTime);
    //        moving.LifeSpan -= DeltaTime;

    //        if (translation.Value.y > 7.0f || moving.LifeSpan <= 0f || translation.Value.x > 20f)
    //        {
    //            CommandBuffer.RemoveComponent<MoveRandom>(index, entity);
    //            CommandBuffer.AddComponent<ResetCube>(index, entity);
    //        }
    //    }
    //}



    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent();


        ///create the job that needs to be scheduled
        var job = new MoveJob
        {
            DeltaTime     = Time.deltaTime,
            CommandBuffer = commandBuffer
        }.Schedule(this, inputDeps);

        m_Barrier.AddJobHandleForProducer(job);

        ///I have no idea if this is right but it does what I want it to

        /*job.Complete();
         *
         * job = new MoveRandomJob
         * {
         *  DeltaTime = Time.deltaTime,
         *  CommandBuffer = commandBuffer
         * }.Schedule(this, inputDeps);
         *
         * m_Barrier.AddJobHandleForProducer(job);
         */
        return(job);
    }
Example #30
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        var cmdBuf    = _bufSystem.CreateCommandBuffer().ToConcurrent();
        var deltaTime = Time.DeltaTime;

        return(Entities
               .WithName("ThinkingSystem")
               .WithoutBurst()
               .ForEach((Entity entity, int entityInQueryIndex, ref EyesightComponent eyesight, in PropertyComponent property) => {
            eyesight.thinkingTime -= property.intelligence * deltaTime;
            if (0.0f < eyesight.thinkingTime)
            {
                return;
            }

            cmdBuf.AddComponent(entityInQueryIndex, entity, new ReactiveComponent()
            {
                target = eyesight.target
            });

            if (SomethingProxy.Type.Wall == (SomethingProxy.Type)eyesight.type)
            {
                cmdBuf.AddComponent(entityInQueryIndex, entity, new WallComponent());
            }

            cmdBuf.RemoveComponent <EyesightComponent>(entityInQueryIndex, entity);
        })
               .Schedule(inputDependencies));
    }