protected override void OnUpdate() { if (!Input.GetMouseButtonDown(0)) { return; } var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (!Physics.Raycast(ray, out RaycastHit hit)) { return; } float2 worldPos = new float2(hit.point.x, hit.point.z); EntityCommandBuffer.Concurrent ecb = ecbSystem.CreateCommandBuffer().ToConcurrent(); Entities.ForEach((int entityInQueryIndex, Entity entity, in Translation translation, in FormationLeader leader) => { ecb.AddComponent(entityInQueryIndex, entity, new PathFindingRequest() { startPos = new float2(translation.Value.x, translation.Value.z), endPos = worldPos }); }).ScheduleParallel();
protected override void OnUpdate() { float deltaTime = Time.DeltaTime; this.currentTime += deltaTime; if (this.currentTime >= UpdateInterval) { Entity seedEntity = this.GetEntityQuery(this.EntityManager.GetSeedIdentifier()).GetSingletonEntity(); Random random = new Random(this.EntityManager.GetComponentData <Seed>(seedEntity).Value); Entity worldBoundsEntity = this.GetEntityQuery(this.EntityManager.GetWorldBoundsIdentifier()).GetSingletonEntity(); WorldBounds worldBounds = this.EntityManager.GetComponentData <WorldBounds>(worldBoundsEntity); EntityArchetype sfxArchetypeForJob = this.EntityManager.CreateSFXArchetype(); //Assumes there is exactly 1 player Entity playerEntity = this.playerQuery.GetSingletonEntity(); Translation playerPosition = this.EntityManager.GetComponentData <Translation>(playerEntity); ComponentDataFromEntity <MonsterRunTowardsPlayerTag> monsterRunTowardsPlayerComponentDataFromEntity = this.GetComponentDataFromEntity <MonsterRunTowardsPlayerTag>(true); EntityCommandBuffer.Concurrent entityCommandBuffer = this.endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); this.Entities .WithAll <MonsterTag>() .ForEach((Entity monster, int entityInQueryIndex, ref PathfindingParameters pathfindingParameters, in Translation position, in MonsterInfo monsterInfo) => { //No attack tag yet added and player is withing agression radius //Run towards player on grid, afterwards in MovementSystem, we run to the player position -> here we only run to the same grid cell. if (!monsterRunTowardsPlayerComponentDataFromEntity.HasComponent(monster) && math.distance(position.Value, playerPosition.Value) <= monsterInfo.MonsterAgressionRadius) { entityCommandBuffer.AddComponent(entityInQueryIndex, monster, new MonsterRunTowardsPlayerTag()); //Choose playerPosition as destination on grid. Pathfinding grid is on x, z components (2d) pathfindingParameters.StartPosition = worldBounds.WorldSpaceToCell(position.Value); pathfindingParameters.EndPosition = worldBounds.WorldSpaceToCell(playerPosition.Value); pathfindingParameters.NeedsPathfindingCalculation = true; //Add Monster Growl SFX Entity sfx = entityCommandBuffer.CreateEntity(entityInQueryIndex, sfxArchetypeForJob); entityCommandBuffer.SetComponent <SFXComponent>(entityInQueryIndex, sfx, new SFXComponent { SFXType = SFXType.MonsterGrowl }); } else if (monsterRunTowardsPlayerComponentDataFromEntity.HasComponent(monster) && math.distance(position.Value, playerPosition.Value) > monsterInfo.MonsterAgressionRadius) { entityCommandBuffer.RemoveComponent(entityInQueryIndex, monster, ComponentType.ReadOnly <MonsterRunTowardsPlayerTag>()); } //0.01% chance monster chooses new target node to walk to if (!monsterRunTowardsPlayerComponentDataFromEntity.HasComponent(monster) && random.NextFloat() < 0.0001f) { //Choose position on grid. Pathfinding grid is on x, z components (2d) pathfindingParameters.StartPosition = worldBounds.WorldSpaceToCell(position.Value); pathfindingParameters.EndPosition = random.NextInt2(new int2(0, 0), worldBounds.XZGridSize); pathfindingParameters.NeedsPathfindingCalculation = true; } })
public static Entity Instantiate(EntityCommandBuffer.Concurrent ecb, int jobIndex, float3 target, Entity prefab, Entity prefabTrail, float3 pos, float3 vel, float time) { var entity = ecb.Instantiate(jobIndex, prefab); ecb.SetComponent(jobIndex, entity, new Translation { Value = pos, }); var rot = quaternion.LookRotationSafe(vel, new float3(0, 1, 0)); ecb.SetComponent(jobIndex, entity, new Rotation { Value = rot, }); ecb.SetComponent(jobIndex, entity, new MissileComponent { Target = target, Velocity = vel, }); ecb.SetComponent(jobIndex, entity, AlivePeriod.Create(time, 2f /* period */)); TrailSystem.Instantiate(ecb, jobIndex, prefabTrail, entity /* refering_entity */, pos, 0.5f /* width */, new Color(0.8f, 0.8f, 0.8f), time); return(entity); }
public void ApplyGameplayEffect(int index, EntityCommandBuffer.Concurrent Ecb, AttributesComponent attributesComponent, float WorldTime) { var attributeModData = new _AttributeModificationComponent() { Add = 0, Multiply = 0, Divide = 0, Change = 0, Source = Source, Target = Target }; var attributeModEntity = Ecb.CreateEntity(index); var gameplayEffectData = new _GameplayEffectDurationComponent() { WorldStartTime = WorldTime, Duration = Duration, Effect = EGameplayEffect.FireAbilityCooldown }; var cooldownEffectComponent = new CooldownEffectComponent() { Caster = Source }; Ecb.AddComponent(index, attributeModEntity, new NullAttributeModifier()); Ecb.AddComponent(index, attributeModEntity, new TemporaryAttributeModification()); Ecb.AddComponent(index, attributeModEntity, gameplayEffectData); Ecb.AddComponent(index, attributeModEntity, attributeModData); Ecb.AddComponent(index, attributeModEntity, cooldownEffectComponent); }
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); }
public static void UnJoinIfJoined(EntityCommandBuffer.Concurrent ecb, int jobIndex, ComponentDataFromEntity <LineJoinPoint> joinPoints, Entity oneSide) { var fromEntity = oneSide; var fromData = joinPoints[oneSide]; if (!fromData.IsJoined) { return; } var toEntity = fromData.JoinToPointEntity; if (!joinPoints.Exists(toEntity)) { var toData = joinPoints[toEntity]; toData.JoinToPointEntity = Entity.Null; ecb.SetComponent(jobIndex, toEntity, toData); } fromData.JoinToPointEntity = Entity.Null; ecb.SetComponent(jobIndex, fromEntity, fromData); }
protected override void OnUpdate() { float deltaTime = Time.DeltaTime; //Assumes there is exactly 1 player Entity playerEntity = this.playerQuery.GetSingletonEntity(); EntityCommandBuffer.Concurrent entityCommandBuffer = this.endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); this.Entities .WithAll <MonsterAttackTag>() .ForEach((Entity monster, int entityInQueryIndex, ref MonsterInfo monsterInfo) => { if (monsterInfo.MonsterAttackIntervalCurrent >= monsterInfo.MonsterAttackIntervalInSeconds) { entityCommandBuffer.AddComponent <PlayerTakeDamageComponent>(entityInQueryIndex, playerEntity, new PlayerTakeDamageComponent { Damage = monsterInfo.Damage }); entityCommandBuffer.RemoveComponent <MonsterAttackTag>(entityInQueryIndex, monster); monsterInfo.MonsterAttackIntervalCurrent = 0f; } else { monsterInfo.MonsterAttackIntervalCurrent += deltaTime; } }).ScheduleParallel(); this.endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(this.Dependency); this.Dependency.Complete(); }
public void UninitializedConcurrentEntityCommandBufferThrows() { EntityCommandBuffer.Concurrent cmds = new EntityCommandBuffer.Concurrent(); var exception = Assert.Throws <NullReferenceException>(() => cmds.CreateEntity(0)); Assert.AreEqual(exception.Message, "The EntityCommandBuffer has not been initialized!"); }
public void Execute(int index, Entity entity, EntityCommandBuffer.Concurrent commandBuffer) { NetworkSerializeUnsafe.AutoAddBufferMessage(index, entity , new WeaponInstalledStateNetMessage { weaponId = weaponId, install = install, shipId = shipId, slotIndex = slotIndex }, commandBuffer); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityCommandBuffer.Concurrent CommandBuffer = m_EntityCommandBuffer.CreateCommandBuffer().ToConcurrent(); JobHandle handle = Entities .WithNone <TC_CooldownRunning>() .WithAll <TC_CooldownCompleted, TC_CreationCooldown>() .ForEach( (Entity entity, int entityInQueryIndex) => { CommandBuffer.RemoveComponent <TC_CreationCooldown>(entityInQueryIndex, entity); CommandBuffer.RemoveComponent <TC_CooldownCompleted>(entityInQueryIndex, entity); CommandBuffer.AddComponent <PlayMonoAnimation_C>(entityInQueryIndex, entity); CommandBuffer.SetComponent(entityInQueryIndex, entity, new PlayMonoAnimation_C { id = UnityEngine.Animator.StringToHash("Caixa@Open") }); }) .WithoutBurst() .Schedule(inputDeps); handle.Complete(); return(handle); }
private void spawn_internal(EntityCommandBuffer.Concurrent entity_command_buffer, float current_time, Entity target_entity, Material mat) { // Develop.print("yes"); entity_command_buffer.CreateEntity(arche_type_); entity_command_buffer.SetComponent(new AlivePeriod { start_time_ = current_time, period_ = 0.3f, }); entity_command_buffer.SetComponent(new StartTime { value_ = current_time, }); entity_command_buffer.SetComponent(new Sight { target_entity_ = target_entity, }); entity_command_buffer.SetSharedComponent(new CustomMeshInstanceRenderer { // entity_command_buffer.SetSharedComponent(new MeshInstanceRenderer { mesh = mesh_, material = mat, castShadows = UnityEngine.Rendering.ShadowCastingMode.Off, receiveShadows = false, layer = 9 /* final */, }); }
protected override void OnUpdate() { // ECB to add components EntityCommandBuffer.Concurrent ecb = this.endSimulationEntitySystem.CreateCommandBuffer().ToConcurrent(); // Job, update dissolve NativeArray <int> numDissolvedNodes = new NativeArray <int>(1, Allocator.TempJob); BlockDissolveJob blockDissolveJob = new BlockDissolveJob() { entityType = GetArchetypeChunkEntityType(), childrenBuffer = GetBufferFromEntity <Child>(true), blockGridNodeType = GetArchetypeChunkComponentType <BlockGridNodeData>(true), blockDissolveType = GetArchetypeChunkComponentType <BlockDissolveData>(false), outNumDissolvedNodes = numDissolvedNodes, outDissolvedNodeIndices = this.dissolvedNodeIndices, ecb = ecb, }; JobHandle blockDissolveJobHandle = blockDissolveJob.ScheduleParallel(this.blockQuery, this.Dependency); // Job, update grid nodes UpdateNavigationGridJob updateNavigationGridJob = new UpdateNavigationGridJob() { numDissolvedNodes = numDissolvedNodes, dissolvedNodeIndices = this.dissolvedNodeIndices, nodeBufferType = GetArchetypeChunkBufferType <AStarNodeElement>(false), }; JobHandle updateNavigationGridJobHandle = updateNavigationGridJob.ScheduleParallel(this.gridQuery, blockDissolveJobHandle); this.Dependency = updateNavigationGridJobHandle; this.endSimulationEntitySystem.AddJobHandleForProducer(this.Dependency); }
private void spawn_internal(EntityCommandBuffer.Concurrent entity_command_buffer, float current_time, ref float3 position, float rotation1) { entity_command_buffer.CreateEntity(arche_type_); entity_command_buffer.SetComponent(new Position { Value = position, }); entity_command_buffer.SetComponent(new Rotation { Value = quaternion.axisAngle(new float3(0f, 0f, 1f), rotation1), }); entity_command_buffer.SetComponent(new AlivePeriod { start_time_ = current_time, period_ = 0.8f, }); entity_command_buffer.SetComponent(new StartTime { value_ = current_time, }); var renderer = new MeshInstanceRenderer { mesh = mesh_, material = material_, subMesh = 0, castShadows = UnityEngine.Rendering.ShadowCastingMode.Off, receiveShadows = true, }; entity_command_buffer.SetSharedComponent(renderer); }
public static void spawn(EntityCommandBuffer.Concurrent entity_command_buffer, float current_time, ref float3 position, float rotation1) { Instance.spawn_internal(entity_command_buffer, current_time, ref position, rotation1); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityCommandBuffer.Concurrent commandBuffer = m_EntityCommandBuffer.CreateCommandBuffer().ToConcurrent(); JobHandle jobConfigureDrop = Entities .WithAll <TC_PerformingAction>() .ForEach((Entity entity, int entityInQueryIndex, in Translation translation, in C_HoldComponentData holdComponent, in DirectionData directionData) => { int2 i2Direction = directionData.directionLook; float fXDropPosition = translation.Value.x + (float)i2Direction.x / 2; commandBuffer.AddComponent <MC_RemoveInHold>(entityInQueryIndex, holdComponent.Item); commandBuffer.SetComponent(entityInQueryIndex, holdComponent.Item, new MC_RemoveInHold { Position = new float3(fXDropPosition, translation.Value.y, 0) }); commandBuffer.RemoveComponent <TC_PerformingAction>(entityInQueryIndex, entity); commandBuffer.RemoveComponent <C_HoldComponentData>(entityInQueryIndex, entity); commandBuffer.AddComponent <TC_CooldownAction>(entityInQueryIndex, entity); commandBuffer.AddComponent <TC_CooldownRunning>(entityInQueryIndex, entity); commandBuffer.SetComponent(entityInQueryIndex, entity, new C_CooldownComponent { Cooldown = 1, DeltaTime = 0 }); }).Schedule(inputDeps);
protected override void OnUpdate() { EntityCommandBuffer.Concurrent entityCommandBuffer = this.endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); this.Dependency = JobHandle.CombineDependencies(this.Dependency, this.Entities.ForEach((int entityInQueryIndex, Entity player, ref PlayerInfo playerInfo, in ConsumeArrowComponent consumeArrowComponent, in ConsumeManaComponent consumeManaComponent) => { if (playerInfo.ArrowCount - consumeArrowComponent.Amount >= 0) { playerInfo.ArrowCount -= consumeArrowComponent.Amount; } else { entityCommandBuffer.AddComponent <NoArrowTag>(entityInQueryIndex, player); } entityCommandBuffer.RemoveComponent <ConsumeManaComponent>(entityInQueryIndex, player); if (playerInfo.Mana - consumeManaComponent.Amount >= 0) { playerInfo.Mana -= consumeManaComponent.Amount; } else { entityCommandBuffer.AddComponent <NoManaTag>(entityInQueryIndex, player); } entityCommandBuffer.RemoveComponent <ConsumeManaComponent>(entityInQueryIndex, player); }).ScheduleParallel(this.Dependency));
public StateData Copy(int jobIndex, EntityCommandBuffer.Concurrent entityCommandBuffer) { var stateEntity = entityCommandBuffer.Instantiate(jobIndex, StateEntity); var traitBasedObjects = entityCommandBuffer.SetBuffer <TraitBasedObject>(jobIndex, stateEntity); traitBasedObjects.CopyFrom(TraitBasedObjects.AsNativeArray()); var traitBasedObjectIds = entityCommandBuffer.SetBuffer <TraitBasedObjectId>(jobIndex, stateEntity); traitBasedObjectIds.CopyFrom(TraitBasedObjectIds.AsNativeArray()); var Locations = entityCommandBuffer.SetBuffer <Location>(jobIndex, stateEntity); Locations.CopyFrom(LocationBuffer.AsNativeArray()); var Robots = entityCommandBuffer.SetBuffer <Robot>(jobIndex, stateEntity); Robots.CopyFrom(RobotBuffer.AsNativeArray()); var Dirts = entityCommandBuffer.SetBuffer <Dirt>(jobIndex, stateEntity); Dirts.CopyFrom(DirtBuffer.AsNativeArray()); var Moveables = entityCommandBuffer.SetBuffer <Moveable>(jobIndex, stateEntity); Moveables.CopyFrom(MoveableBuffer.AsNativeArray()); return(new StateData { StateEntity = stateEntity, TraitBasedObjects = traitBasedObjects, TraitBasedObjectIds = traitBasedObjectIds, LocationBuffer = Locations, RobotBuffer = Robots, DirtBuffer = Dirts, MoveableBuffer = Moveables, }); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { int mapWidth = PathfindingGridSetup.Instance.pathfindingGrid.GetWidth(); int mapHeight = PathfindingGridSetup.Instance.pathfindingGrid.GetHeight(); float3 originPosition = float3.zero; float cellSize = PathfindingGridSetup.Instance.pathfindingGrid.GetCellSize(); Unity.Mathematics.Random random = new Unity.Mathematics.Random(this.random.NextUInt(1, 10000)); EntityCommandBuffer.Concurrent entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); JobHandle jobHandle = Entities.WithNone <PathfindingParams>().ForEach((Entity entity, int entityInQueryIndex, in PathFollow pathFollow, in Translation translation) => { if (pathFollow.pathIndex == -1) { GetXY(translation.Value + new float3(1, 1, 0) * cellSize * +.5f, originPosition, cellSize, out int startX, out int startY); ValidateGridPosition(ref startX, ref startY, mapWidth, mapHeight); int endX = random.NextInt(0, mapWidth); int endY = random.NextInt(0, mapHeight); entityCommandBuffer.AddComponent(entityInQueryIndex, entity, new PathfindingParams { startPosition = new int2(startX, startY), endPosition = new int2(endX, endY) }); } }).Schedule(inputDeps);
protected override JobHandle OnUpdate(JobHandle inputDependencies) { EntityCommandBuffer.Concurrent ecb = EndSimECBSystem.CreateCommandBuffer().ToConcurrent(); //Fetch the translation of the Player to be used for distance calculations //Note: this system assumes there's only one Player. If more than one exists, you will see errors pop up Translation playerTranslation = EntityManager.GetComponentData <Translation>(GetSingletonEntity <PlayerTag>()); var job = new LoadSceneJob(); job.ECB = ecb; job.playerPosition = playerTranslation; var job2 = new UnloadSceneJob(); job2.ECB = ecb; job2.playerPosition = playerTranslation; JobHandle jobHandle = job.Schedule(this, inputDependencies); EndSimECBSystem.AddJobHandleForProducer(jobHandle); JobHandle job2Handle = job2.Schedule(this, jobHandle); EndSimECBSystem.AddJobHandleForProducer(job2Handle); return(job2Handle); }
protected override void OnUpdate(EntityCommandBuffer.Concurrent ecb) { float deltaTime = Time.DeltaTime; Entities .WithAll <Chain>() .WithNone <TempTranslation>() .ForEach((Entity entity, int entityInQueryIndex) => { ecb.AddComponent(entityInQueryIndex, entity, new TempTranslation { }); }) .ScheduleParallel(); var cdfe = GetComponentDataFromEntity <Translation>(true); Entities .WithReadOnly(cdfe) .ForEach((Entity entity, int entityInQueryIndex, ref TempTranslation tempTrans, ref Rotation rot, in Chain chain, in ChainParent parent) => { if (cdfe.Exists(parent.Value)) { var m = cdfe[parent.Value]; var dir = math.normalize(m.Value - tempTrans.Value); tempTrans.Value = m.Value - dir * chain.dist; rot.Value = quaternion.LookRotation(dir, up); } else { //ecb.DestroyEntity(entityInQueryIndex, entity); ecb.RemoveComponent <Chain>(entityInQueryIndex, entity); ecb.RemoveComponent <ChainParent>(entityInQueryIndex, entity); ecb.RemoveComponent <MovementTypeTag>(entityInQueryIndex, entity); } })
public void ApplyGameplayEffect <T0, T1>(int index, EntityCommandBuffer.Concurrent Ecb, Entity Source, Entity Target, AttributesComponent attributesComponent, float WorldTime) where T0 : struct, IComponentData, IGameplayEffect where T1 : struct, IComponentData, IGameplayEffect { ApplyGameplayEffect <T0>(index, Ecb, Source, Target, attributesComponent, WorldTime); ApplyGameplayEffect <T1>(index, Ecb, Source, Target, attributesComponent, WorldTime); }
public static void EvaluateList(Translation translation, AlertRange alertRange, NativeArray <Entity> entities, NativeArray <Translation> positions, Entity entity, int entityIndex, EntityCommandBuffer.Concurrent ECB) { float closestSqDistance = alertRange.Range * alertRange.Range; bool targetFound = false; Entity target = Entity.Null; for (int i = 0; i < entities.Length; i++) { //check the squared distance to this Player and see if it's under the closest one we already found float currentSqDistance = math.lengthsq(positions[i].Value - translation.Value); if (currentSqDistance < closestSqDistance) { target = entities[i]; closestSqDistance = currentSqDistance; targetFound = true; } } if (targetFound) { ECB.AddComponent <Target>(entityIndex, entity, new Target { Entity = target }); } }
public static Entity Instantiate(EntityCommandBuffer.Concurrent ecb, int jobIndex, Entity prefab, float3 pos, float3 vel) { var up = new float3(0f, 1f, 0f); var rot = quaternion.LookRotationSafe(vel, up); return(Instantiate(ecb, jobIndex, prefab, pos, rot, vel)); }
private void spawn_internal(EntityCommandBuffer.Concurrent entity_command_buffer, float current_time, ref float3 pos, Material mat) { entity_command_buffer.CreateEntity(arche_type_); entity_command_buffer.SetComponent(new Position { Value = pos, }); entity_command_buffer.SetComponent(new Rotation { Value = quaternion.identity, }); entity_command_buffer.SetComponent(new AlivePeriod { start_time_ = current_time, period_ = 1f, }); entity_command_buffer.SetComponent(new StartTime { value_ = current_time, }); entity_command_buffer.SetSharedComponent(new MeshInstanceRenderer { mesh = mesh_, material = mat, castShadows = UnityEngine.Rendering.ShadowCastingMode.Off, receiveShadows = false, }); }
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();
public void MoveMonsterToLobbyWithEcb(EntityCommandBuffer.Concurrent ecb, int index, Entity monsterEntity, float timeToLeave) { //remove the entity from its previous room! var roomEnt = World.Active.EntityManager.GetComponentData <InsideRoom>(monsterEntity); var buff = World.Active.EntityManager.GetBuffer <Monster>(roomEnt.RoomEntity); for (int i = buff.Length - 1; i >= 0; i--) { if (buff[i].Value.Equals(monsterEntity)) { buff.RemoveAt(i); } } ecb.SetComponent(index, monsterEntity, new InsideRoom() { RoomEntity = GetRoomEntity(lobby) }); // EntityManager entityManager = World.Active.EntityManager; // entityManager.SetComponentData(monsterEntity, new Translation() { Value = spawnPos }); // entityManager.SetComponentData(monsterEntity, new InsideRoom() { RoomEntity = roomEntity }); // entityManager.SetComponentData(monsterEntity, new TimeToLeave() { TimeRemaining = timeToLeave }); // var monsterBuffer = entityManager.GetBuffer<Monster>(roomEntity); //so we need to make a monster type /*var mon = new Monster(); * mon.Value = monsterEntity; * monsterBuffer.Add(mon);*/ }
protected override void OnUpdate(EntityCommandBuffer.Concurrent ecb) { var random = new Random(mainRandom.NextUInt(uint.MinValue, uint.MaxValue)); var minSpeed = setup.minSpeed; var maxSpeed = setup.maxSpeed; var movementEnumCount = MovementEnumCount; Entities .WithAll <EnemyTag>() .WithNone <MovementTypeTag>() .ForEach((Entity entity, int entityInQueryIndex, ref Rotation rot) => { ecb.AddComponent <MovementTypeTag>(entityInQueryIndex, entity); var i = random.NextInt(0, 1) * 2 - 1; // -1 or 1 rot.Value = quaternion.Euler(0, i * math.PI / 2, 0); var index = (MovementEnum)random.NextInt(0, movementEnumCount); index = MovementEnum.Spiral; switch (index) { case MovementEnum.Linear: break; case MovementEnum.Spiral: ecb.AddComponent(entityInQueryIndex, entity, new MovementSpiral { speed = random.NextFloat(minSpeed, maxSpeed) }); break; } }) .ScheduleParallel(); }
public static void SetParent(this EntityCommandBuffer.Concurrent entityCommandBuffer, int jobIndex, Entity parent, Entity child) { entityCommandBuffer.AddComponent(jobIndex, child, new Parent { Value = parent }); entityCommandBuffer.AddComponent(jobIndex, child, new LocalToParent()); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityManager m_entityManager = SwarmOfIron.Instance.entityManager; NativeArray <float3> movePositionList = new NativeArray <float3>(Soldier.movePositionList.ToArray(), Allocator.TempJob); Entity target = UnitControlHelpers.GetEntityTarget(); float3 targetPosition = UnitControlHelpers.GetMousePosition(); bool harvest = false; if (EntityManager.Exists(target)) { harvest = EntityManager.HasComponent <RockComponent>(target); } EntityCommandBuffer.Concurrent entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); JobHandle jobHandle = Entities.WithAll <UnitSelectedComponent>().WithNone <CityHallComponent>().ForEach((Entity entity, int entityInQueryIndex, in Translation translation) => { entityCommandBuffer.AddComponent(entityInQueryIndex, entity, new MoveToComponent { harvest = harvest, startPosition = translation.Value, endPosition = (!harvest ? movePositionList[entityInQueryIndex] : 0) + targetPosition }); }).Schedule(inputDeps); endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); return(movePositionList.Dispose(jobHandle)); }
public StateData Copy(int jobIndex, EntityCommandBuffer.Concurrent entityCommandBuffer) { var stateEntity = entityCommandBuffer.Instantiate(jobIndex, StateEntity); var traitBasedObjects = entityCommandBuffer.SetBuffer <TraitBasedObject>(jobIndex, stateEntity); traitBasedObjects.CopyFrom(TraitBasedObjects.AsNativeArray()); var traitBasedObjectIds = entityCommandBuffer.SetBuffer <TraitBasedObjectId>(jobIndex, stateEntity); traitBasedObjectIds.CopyFrom(TraitBasedObjectIds.AsNativeArray()); var Games = entityCommandBuffer.SetBuffer <Game>(jobIndex, stateEntity); Games.CopyFrom(GameBuffer.AsNativeArray()); var Coordinates = entityCommandBuffer.SetBuffer <Coordinate>(jobIndex, stateEntity); Coordinates.CopyFrom(CoordinateBuffer.AsNativeArray()); var Cells = entityCommandBuffer.SetBuffer <Cell>(jobIndex, stateEntity); Cells.CopyFrom(CellBuffer.AsNativeArray()); var Blockers = entityCommandBuffer.SetBuffer <Blocker>(jobIndex, stateEntity); Blockers.CopyFrom(BlockerBuffer.AsNativeArray()); return(new StateData { StateEntity = stateEntity, TraitBasedObjects = traitBasedObjects, TraitBasedObjectIds = traitBasedObjectIds, GameBuffer = Games, CoordinateBuffer = Coordinates, CellBuffer = Cells, BlockerBuffer = Blockers, }); }