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); }
#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); }
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); }
protected override void OnUpdate() { var glyphMap = new NativeHashMap <int, Entity>(glyphQuery.CalculateEntityCount(), Allocator.TempJob); Dependency = new BuildGlyphMapJobChunk { GlyphMap = glyphMap.AsParallelWriter(), EntityType = GetEntityTypeHandle(), FontType = GetComponentTypeHandle <FontID>(true) }.Schedule(glyphQuery, Dependency); Dependency = new BuildTextMeshJob { GlyphMap = glyphMap, GlyphData = GetBufferFromEntity <GlyphElement>(true), FontFaces = GetComponentDataFromEntity <FontFaceInfo>(true), Parents = GetComponentDataFromEntity <Parent>(true), EntityType = GetEntityTypeHandle(), CharBufferType = GetBufferTypeHandle <CharElement>(true), TextOptionType = GetComponentTypeHandle <TextOptions>(true), TxtFontIDType = GetComponentTypeHandle <TextFontID>(true), ColorType = GetComponentTypeHandle <AppliedColor>(true), LTWType = GetComponentTypeHandle <LocalToWorld>(true), DimensionType = GetComponentTypeHandle <Dimensions>(true), MeshVertexDataType = GetBufferTypeHandle <LocalVertexData>(), TriangleIndexType = GetBufferTypeHandle <LocalTriangleIndexElement>(), CmdBuffer = cmdBufferSystem.CreateCommandBuffer().AsParallelWriter() }.Schedule(textQuery, Dependency); Dependency = glyphMap.Dispose(Dependency); cmdBufferSystem.AddJobHandleForProducer(Dependency); }
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); }
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); }
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); }
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 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); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (CullingManager.CullIndexList.Count > 0) { int totalCount = CullingManager.CullIndexList.Count; var EntityCommandBuffer = EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); NativeArray <int> totalTileID = new NativeArray <int>(totalCount, Allocator.Persistent); for (int i = 0; i < totalCount; i++) { totalTileID[i] = CullingManager.CullIndexList[i]; } var jobhandle = Entities.ForEach((Entity en, int nativeThreadIndex, ref EntityCreate.GeneraGrassTile GrassTile) => { for (int i = 0; i < totalCount; i++) { if (totalTileID[i] == GrassTile.tile_id) { EntityCommandBuffer.DestroyEntity(nativeThreadIndex, en); return; } } }).Schedule(inputDeps); CullingManager.CullIndexList.Clear(); EntityCommandBufferSystem.AddJobHandleForProducer(jobhandle); jobhandle.Complete(); totalTileID.Dispose(); return(jobhandle); } return(inputDeps); }
protected override void OnUpdate() { //Timer specific Job.WithoutBurst().WithCode(() => { timer.Start(); }).Schedule(); //Timer specific EntityCommandBuffer.Concurrent ecb = ecbSystem.CreateCommandBuffer().ToConcurrent(); Entities.ForEach((int entityInQueryIndex, Entity entity, in PathFindingRequest pathFindingRequest) => { ecb.RemoveComponent <PathFindingRequest>(entityInQueryIndex, entity); }).ScheduleParallel(); ecbSystem.AddJobHandleForProducer(Dependency); //Timer specific Job.WithoutBurst().WithCode(() => { double ticks = timer.ElapsedTicks; double milliseconds = (ticks / Stopwatch.Frequency) * 1000; time = milliseconds; timer.Stop(); timer.Reset(); }).Schedule(); timerRecoder.RegisterTimeInMS(time); //Timer specific }
protected override void OnUpdate() { var time = Time.DeltaTime; var ecb = commandBufferSystem.CreateCommandBuffer().AsParallelWriter(); random.NextFloat(); var rand = random; Entities .ForEach((Entity entity, int entityInQueryIndex, ref Translation position, ref Rotation rot, ref NonUniformScale scale, ref PollenComponent poll) => { Quaternion rotation = rot.Value; rotation *= Quaternion.Euler( rand.NextFloat(-1, 1) * time * 360, rand.NextFloat(-1, 1) * time * 360, rand.NextFloat(-1, 1) * time * 360); position.Value += (float3)(rotation * new float3(time, 0, 0)); rot.Value = rotation; poll.lifespanRemaining -= time; if (poll.lifespanRemaining <= 0) { ecb.DestroyEntity(entityInQueryIndex, entity); } else { var newScale = math.pow(poll.lifespanRemaining / poll.totalLifespan, 1f / 3) * poll.scaleMultiplier; scale.Value = new float3(newScale, newScale, newScale); } }).ScheduleParallel(); commandBufferSystem.AddJobHandleForProducer(this.Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //Prepare maps var nodes = new NativeArray <T>(_mapSize, Allocator.TempJob); var prepareNodesJob = new PrepareNodesJob { Nodes = nodes, }; var prepareMapHandle = prepareNodesJob.Schedule(this, inputDeps); var sortNodesHandle = nodes.SortJob(prepareMapHandle); //Path Finding var pathFindingJob = new PathFindingJob { MapSize = _mapSize, Nodes = nodes, ResultECB = resultECB.CreateCommandBuffer().ToConcurrent(), CleanECB = cleanECB.CreateCommandBuffer().ToConcurrent(), IterationLimit = _iterationLimit, PathNodeLimit = _pathNodeLimit }; var pathFindingHandle = pathFindingJob.Schedule(this, sortNodesHandle); resultECB.AddJobHandleForProducer(pathFindingHandle); return(pathFindingHandle); }
protected override JobHandle OnUpdate(JobHandle inputDependencies) { JobHandle job = new JobHandle(); if (ClientAvatarsStates.State == null || ClientAvatarsStates.State.RemoteClientAvatar == null) { return(job); } ChTags charTag = ChTags.Cooper; if (ClientAvatarsStates.State.LocalClientAvatar.name == "CooperAvatar") { charTag = ChTags.Spider; } var commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(); job = new RemoteDamageJob { RemoteClientChar = charTag, RemotePos = ClientAvatarsStates.State.RemoteClientAvatar.transform.position, CommandBuffer = commandBuffer, }.Schedule(this, inputDependencies); m_Barrier.AddJobHandleForProducer(job); return(job); }
protected override void OnUpdate() { Entity playerEntity = playerEntityQuery.GetSingletonEntity(); var commandBuffer = commandBufferSystem.CreateCommandBuffer().ToConcurrent(); // Add CurrentVelocity component to entities with MoveTowardsPlayer component. Entities .WithAll <MoveTowardsPlayer>() .WithNone <CurrentVelocity>() .ForEach((Entity entity, int entityInQueryIndex) => { commandBuffer.AddComponent <CurrentVelocity>(entityInQueryIndex, entity); }) .ScheduleParallel(); commandBufferSystem.AddJobHandleForProducer(Dependency); // Adjust velocity to follow player. Entities .WithAll <MoveTowardsPlayer>() .ForEach((ref CurrentVelocity currentVelocity, in BaseSpeed baseSpeedComponent, in Translation translation) => { float3 playerPosition = GetComponent <Translation>(playerEntity).Value; float3 currentPosition = translation.Value; float3 direction = math.normalize(playerPosition - currentPosition); currentVelocity.Value = direction * baseSpeedComponent.Value; })
protected override void OnUpdate() { float worldYKill = -25.0f; var ecb = ecbs.CreateCommandBuffer(); var ecbp = ecb.ToConcurrent(); EntityManager em = EntityManager; Dependency = Entities.ForEach((Entity e, int entityInQueryIndex, ref Translation t) => { if (t.Value.y <= worldYKill) { if (em.HasComponent <Player>(e)) { t.Value = new float3(0, 10, 0); ecbp.SetComponent <Velocity>(entityInQueryIndex, e, new Velocity() { value = float3.zero }); } else { ecbp.DestroyEntity(entityInQueryIndex, e); } } }).Schedule(Dependency); Dependency.Complete(); ecbs.AddJobHandleForProducer(Dependency); }
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 void OnUpdate() { // The command buffer to record commands, // which are executed by the command buffer system later in the frame EntityCommandBuffer.ParallelWriter commandBuffer = CommandBufferSystem.CreateCommandBuffer().AsParallelWriter(); //The DataToSpawn component tells us how many entities with buffers to create Entities.ForEach((Entity spawnEntity, int entityInQueryIndex, in DataToSpawn data) => { for (int e = 0; e < data.EntityCount; e++) { //Create a new entity for the command buffer Entity newEntity = commandBuffer.CreateEntity(entityInQueryIndex); //Create the dynamic buffer and add it to the new entity DynamicBuffer <MyBufferElement> buffer = commandBuffer.AddBuffer <MyBufferElement>(entityInQueryIndex, newEntity); //Reinterpret to plain int buffer DynamicBuffer <int> intBuffer = buffer.Reinterpret <int>(); //Optionally, populate the dynamic buffer for (int j = 0; j < data.ElementCount; j++) { intBuffer.Add(j); } } //Destroy the DataToSpawn entity since it has done its job commandBuffer.DestroyEntity(entityInQueryIndex, spawnEntity); }).ScheduleParallel(); CommandBufferSystem.AddJobHandleForProducer(this.Dependency); }
protected override void OnUpdate() { InitByRandomSeed(); InitByCustomSeed(); Destroy(); _ECB.AddJobHandleForProducer(Dependency); }
protected override void OnUpdate() { var ecb = _barrier.CreateCommandBuffer(); var gameStateCTX = new GameStateJobContext(this); if (Input.GetKeyDown(KeyCode.Escape)) { gameStateCTX.ChangeGameState <GameStateTakingTurns>(ecb); _barrier.AddJobHandleForProducer(Dependency); return; } var playerEntity = GetSingletonEntity <Player>(); NativeList <ItemWithName> playerItems = new NativeList <ItemWithName>(5, Allocator.TempJob); Entities .ForEach((Entity e, in InInventory inInventory, in Item item, in Name name) => { if (inInventory.owner == playerEntity) { playerItems.Add(new ItemWithName { item = e, name = name }); } }).Schedule();
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); }
protected override void OnUpdate() { var ecb = _entityCommandBuffer.CreateCommandBuffer().AsParallelWriter(); var dt = Time.DeltaTime; Entities.ForEach((Entity e, int entityInQueryIndex, ref LifetimeData lifetimeData) => { lifetimeData.Lifetime -= dt; if (lifetimeData.Lifetime < 0f) { ecb.DestroyEntity(entityInQueryIndex, e); } // Implement the work to perform for each entity here. // You should only access data that is local or that is a // field on this job. Note that the 'rotation' parameter is // marked as 'in', which means it cannot be modified, // but allows this job to run in parallel with other jobs // that want to read Rotation component data. // For example, // translation.Value += math.mul(rotation.Value, new float3(0, 0, 1)) * deltaTime; }).Schedule(); _entityCommandBuffer.AddJobHandleForProducer(this.Dependency); }
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); }
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); }
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 JobHandle OnUpdate(JobHandle inputDependencies) { var cmndBuffer = commandBuffer.CreateCommandBuffer().ToConcurrent(); int unitCount = damageableUnits.CalculateEntityCount(); DamageMap.Clear(); if (unitCount > DamageMap.Capacity) { DamageMap.Capacity = unitCount; } var job = new ZombieAttackSystemJob { CommandBuffer = cmndBuffer, MinDistance = GameGlobals.zombieAttackReach, DamageTakerData = GetComponentDataFromEntity <DamageTakerTag>(true), HealthData = GetComponentDataFromEntity <HealthComponent>(true), EntityDamageMap = DamageMap.AsParallelWriter() }.Schedule(this, inputDependencies); commandBuffer.AddJobHandleForProducer(job); return(job); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var commandBuffer = _commandBufferSystem.CreateCommandBuffer().ToConcurrent(); var updateJob = new UpdateJob { attackTemplate = _enemyAttack, movementTemplate = _enemyMovement, entityType = GetArchetypeChunkEntityType(), raycastResultStateType = GetArchetypeChunkComponentType <RaycastResultState>(false), raycastResultType = GetArchetypeChunkComponentType <RaycastResult>(true), movementType = GetArchetypeChunkComponentType <Movement>(true), attackType = GetArchetypeChunkComponentType <EnemyAttack>(true), targetType = GetArchetypeChunkComponentType <TargetOwnership>(false), commands = commandBuffer }; var cleanupJob = new CleanupJob { commands = commandBuffer }; inputDeps = updateJob.Schedule(_updateQuery, inputDeps); inputDeps = updateJob.Schedule(_updateQueryNoState, inputDeps); inputDeps = cleanupJob.Schedule(_cleanupQuery, inputDeps); _commandBufferSystem.AddJobHandleForProducer(inputDeps); return(inputDeps); }
protected override void OnUpdate() { if (_grid == null) { _grid = SetupPathFindingGrid.Instance; } var ecb = _ecbSystem.CreateCommandBuffer().AsParallelWriter(); float cellSize = _grid.Grid.GetCellSize(); float3 originOffset = _grid.OriginOffset; var gridSize = new int2(_grid.Grid.GetWidth(), _grid.Grid.GetHeight()); //var mousePos = GetMousePosOnPlane(); // GetXY(originOffset, cellSize, mousePos, out int endX, out int endY); var entities = _query.ToEntityArrayAsync(Allocator.TempJob, out JobHandle jobhandle); Dependency = JobHandle.CombineDependencies(Dependency, jobhandle); Dependency = new RandomMoveOrderJob { CommandBuffer = ecb, EntityType = GetEntityTypeHandle(), GridSize = gridSize, OriginOffset = originOffset, CellSize = cellSize, //EndPos = new int2(endX, endY), TranslationType = GetComponentTypeHandle <Translation>(true), Randoms = _randoms }.ScheduleParallel(_query, Dependency); _ecbSystem.AddJobHandleForProducer(Dependency); entities.Dispose(Dependency); }
//[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); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityCommandBuffer buffer = bufferSystem.CreateCommandBuffer(); var job = new BulletCollisionHandlingJob { _World = World.Active.GetExistingSystem <BuildPhysicsWorld>().PhysicsWorld, CommandBuffer = buffer, HealthComponents = GetComponentDataFromEntity <Health>(true), ExplosionComponents = GetComponentDataFromEntity <ExplosionComponent>(true), TranslationComponents = GetComponentDataFromEntity <Translation>(true) }.Schedule(this, inputDeps); bufferSystem.AddJobHandleForProducer(job); job.Complete(); var healthManagementJob = new HealthManagementJob { CommandBuffer = buffer, }.Schedule(this, job); var disablerJob = new ParentDisableCheckJob { CommandBuffer = buffer, DisabledEntities = GetComponentDataFromEntity <Disabled>(true) }.Schedule(this, healthManagementJob); return(disablerJob); }