public void Execute(Entity weaponEntity, int index, [ReadOnly] ref WeaponInput weaponInput, [ReadOnly] ref WeaponControlInfo weaponControlInfo, [ReadOnly] ref WeaponInstalledState weaponInstalledState, ref WeaponControl weaponControl, ref WeaponAttribute weaponAttribute) { var fireEvent = weaponControl.OnFire(fixedDeltaTime, weaponControlInfo); if (fireEvent == WeaponControl.FireEvent.Prepare) { ctrlCommandBuffer.AddComponent(index, weaponEntity, OnWeaponControlFirePrepareMessage); endCommandBuffer.RemoveComponent(index, weaponEntity, OnWeaponControlFirePrepareMessage); } else if (fireEvent == WeaponControl.FireEvent.Fire) { if (weaponAttribute.itemCount == 0) { return; } if (weaponAttribute.itemCount > 0) { --weaponAttribute.itemCount; } ctrlCommandBuffer.AddBuffer <ActorAttribute3Modifys <_Power> >(index, weaponInstalledState.shipEntity).Add( new ActorAttribute3Modifys <_Power> { //player = weaponInstalledState.shipActorOwner.playerEntity,//自己消耗自己的power 就不需要知道是谁消耗了 value = -weaponControlInfo.GetConsumePower(weaponInstalledState.slot.main), attribute3ModifyType = Attribute3SubModifyType.ValueOffset }); var fireActorType = weaponControlInfo.GetFireActorType(weaponInstalledState.slot.main); var attributeScale = weaponControlInfo.GetAttributeScale(weaponInstalledState.slot.main); if (fireActorType != ActorTypes.None) { var e = ctrlCommandBuffer.CreateEntity(index); ctrlCommandBuffer.AddComponent(index, e, new FireCreateData { actorOwner = weaponInstalledState.shipActorOwner, shipEntity = weaponInstalledState.shipEntity, weaponEntity = weaponEntity, fireActorType = fireActorType, firePosition = weaponInput.firePosition, attributeOffsetScale = attributeScale, }); } #if false else { weaponControlInFireStateCommandBuffer.AddComponent(weaponEntity, new WeaponControlInFireState { duration = weaponControlInfo.fireDuration }); commandBuffer.AddComponent(index, weaponEntity, OnWeaponControlFireOnMessage); endCommandBuffer.RemoveComponent(index, weaponEntity, OnWeaponControlFireOnMessage); } #endif } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var entities = chunk.GetNativeArray(EntitieType); var states = chunk.GetNativeArray(ComplitedType); bool hasTarget = chunk.Has(TargetType); bool hasTarget3 = chunk.Has(Target3Type); bool hasSpeed = chunk.Has(SpeedType); bool hasSpeed3 = chunk.Has(Speed3Type); for (int i = 0; i < states.Length; i++) { if (!states[i].IsComplited) { continue; } var e = entities[i]; Cb.RemoveComponent <TweenComplitedState>(chunkIndex, e); if (hasTarget) { Cb.RemoveComponent <TweenFloatTarget>(chunkIndex, e); } if (hasTarget3) { Cb.RemoveComponent <TweenFloat3Target>(chunkIndex, e); } if (hasSpeed) { Cb.RemoveComponent <TweenSpeed>(chunkIndex, e); } if (hasSpeed3) { Cb.RemoveComponent <TweenFloat3Speed>(chunkIndex, e); } } }
public void Execute(Entity entity, int index, ref Target target, [ReadOnly] ref AlertRange alertRange, [ReadOnly] ref Translation translation, ref MovementInput movementInput) { //First we check if the Entity exists in the Translation data array. //If not, it's dead and can be removed as the target if (!targetTranslations.Exists(target.Entity)) { ECB.RemoveComponent <Target>(index, entity); movementInput.MoveAmount = float3.zero; //stops the entity return; } //Then, we check the distance. If beyond the alertRange, the entity is too far //In this case, an enemy would go into idle float distanceSquared = math.lengthsq(targetTranslations[target.Entity].Value - translation.Value); if (distanceSquared > alertRange.Range * alertRange.Range) { ECB.RemoveComponent <Target>(index, entity); movementInput.MoveAmount = float3.zero; //stops the entity } }
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);
public void Execute(Entity entity, int index, ref CallTrigger messageTrigger) { messageTrigger.time -= fixedDeltaTime; if (messageTrigger.time <= 0f && (messageTrigger.maxCount == -1 || messageTrigger.count < messageTrigger.maxCount)) { if (messageTrigger.interval >= 0f) { messageTrigger.time += messageTrigger.interval; ++messageTrigger.count; // commandBuffer.AddComponent(index, entity, messageTrigger.type); endCommandBuffer.RemoveComponent(index, entity, messageTrigger.type); } else if (messageTrigger.maxCount == -1) { commandBuffer.AddComponent(index, entity, messageTrigger.type); endCommandBuffer.RemoveComponent(index, entity, CallTrigger); } } else { if (messageTrigger.maxCount != -1 && messageTrigger.count >= messageTrigger.maxCount) { endCommandBuffer.RemoveComponent(index, entity, CallTrigger); } } }
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 Execute(Entity entity, int index, ref HasTarget hasTarget) { if (componentDataFromEntity.Exists(hasTarget.target) && componentDataFromEntity.Exists(entity)) { var translation = componentDataFromEntity[entity]; var targetTranslation = componentDataFromEntity[hasTarget.target]; float3 targetDir = math.normalize(targetTranslation.Value - translation.Value); float moveSpeed = 1f; translation.Value += targetDir * moveSpeed * deltaTime; entityCommandBuffer.SetComponent(index, entity, new Translation() { Value = translation.Value }); if (math.distance(translation.Value, targetTranslation.Value) < 0.2f) { entityCommandBuffer.DestroyEntity(index, hasTarget.target); entityCommandBuffer.RemoveComponent <HasTarget> (index, entity); } } else { entityCommandBuffer.RemoveComponent <HasTarget> (index, entity); } }
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));
/// <summary> /// Moves Entity by Heading /// <para> /// Handles ending movement (through Destination) as well /// </para> /// </summary> /// <param name="entity">Entity to Move</param> /// <param name="index">Index of Job</param> /// <param name="c0">Translation for Entity</param> /// <param name="c1">Heading for Entity</param> public void Execute(Entity entity, int index, ref Translation c0, [ReadOnly] ref Heading c1) { if (!destinations.Exists(entity)) // Entity does not have Destination { Move(ref c0, c1, deltaT); } else // Handle movement with Destination { Destination dest = destinations[entity]; if (math.distance(c0.Value, dest.Value) > dest.Distance) { Move(ref c0, c1, deltaT); // Destination not reached. Perform regular movement } else { if (dest.Snap) // Snap to destination { c0.Value = dest.Value; } // Remove Heading & Destination buffer.RemoveComponent <Destination>(index, entity); buffer.RemoveComponent <Heading>(index, entity); } } }
private void ProcessChunkWithState(ArchetypeChunk chunk, int chunkIndex) { var entities = chunk.GetNativeArray(entityType); var raycastResults = chunk.GetNativeArray(raycastResultType); var raycastResultStates = chunk.GetNativeArray(raycastResultStateType); for (int i = 0; i < chunk.Count; i++) { var entity = entities[i]; var raycastResult = raycastResults[i]; var raycastResultState = raycastResultStates[i]; if (!raycastResult.IsHit() && chunk.Has(attackType) && !chunk.Has(movementType)) { commands.RemoveComponent <EnemyAttack>(chunkIndex, entity); commands.AddComponent(chunkIndex, entity, movementTemplate); commands.RemoveComponent <RaycastResultState>(chunkIndex, entity); if (chunk.Has(targetType)) { commands.RemoveComponent <TargetOwnership>(chunkIndex, entity); } } else if (!CompareDistance(raycastResult, raycastResultState) && chunk.Has(targetType)) { commands.SetComponent(chunkIndex, entity, new TargetOwnership { targetEntity = raycastResult.entity, targetPosition = raycastResult.position }); } } }
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); }
public void Execute(Entity entity, int index, ref HasTarget hasTarget, ref Translation translation) { var targetIndex = targets.IndexOf(hasTarget.target); if (targetIndex != -1) { var heroPosition = translation.Value; var targetPosition = targetsTranslations[targetIndex].Value; var distance = math.distance(heroPosition, targetPosition); if (distance > .01f) { var dir = math.normalize(targetPosition - heroPosition); translation = new Translation { Value = heroPosition + dir * deltaTime }; } else { commandBuffer.DestroyEntity(index, hasTarget.target); commandBuffer.RemoveComponent <HasTarget>(index, entity); } } else { commandBuffer.RemoveComponent <HasTarget>(index, entity); } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var Velocities = chunk.GetNativeArray(VelocityType); var Translations = chunk.GetNativeArray(TranslationType); var Targets = chunk.GetNativeArray(TargetType); var Entities = chunk.GetNativeArray(EntityType); for (int i = 0; i < chunk.Count; ++i) { var Target = Targets[i]; if (DyingType.Exists(Target.Value))//This code reads: "If Target is dead, stop following it" { ecb.RemoveComponent(chunkIndex, Entities[i], typeof(C_Target)); continue; } var translation = Translations[i]; var velocity = Velocities[i]; float3 targetPos = TranslationData[Target.Value].Value; float3 delta = targetPos - translation.Value; float distanceSquared = delta.x * delta.x + delta.y * delta.y + delta.z * delta.z; if (distanceSquared < HitDistance * HitDistance) { C_DeathTimer timer = new C_DeathTimer() { TimeRemaining = BeeTimeToDeath }; Tag_IsDying tag; ecb.AddComponent(chunkIndex, Target.Value, tag); ecb.SetComponent(chunkIndex, Target.Value, timer); ecb.RemoveComponent(chunkIndex, Entities[i], typeof(C_Target)); //Spawn particles; var bloodVel = new C_Velocity() { Value = velocity.Value * .35f }; for (int particle = 0; particle < 6; ++particle) { var blood = ecb.Instantiate(chunkIndex, BloodPrefab); ecb.SetComponent(chunkIndex, blood, translation); ecb.SetComponent(chunkIndex, blood, bloodVel); } continue; } float force = max(1.0, distanceSquared) < AttackDistance * AttackDistance ? AttackForce : ChaseForce; velocity.Value += delta * (force * dt / sqrt(distanceSquared)); Velocities[i] = velocity; } }
public void Execute(Entity armEntity, int index, [ReadOnly] ref ArmReachingTag tag, ref ArmComponent armComponent, [ReadOnly] ref Translation translation) { Entity intendedRock = tag.rockToReachFor; Translation intendedRockTranslation = translationsFromEntity[intendedRock]; Scale intendedRockScale = scalesFromEntity[intendedRock]; float3 delta = intendedRockTranslation.Value - translation.Value; if (math.lengthsq(delta) < armComponent.maxReachLength * armComponent.maxReachLength) { // Rock is still within reach, attempt to reach it. float3 flatDelta = delta; flatDelta.y = 0; flatDelta = math.normalize(flatDelta); float intendedRockSize = intendedRockScale.Value; armComponent.lastIntendedRockSize = intendedRockSize; armComponent.grabHandTarget = intendedRockTranslation.Value + directions.up * intendedRockSize * .5f - flatDelta * intendedRockSize * .5f; armComponent.lastIntendedRockPos = intendedRockTranslation.Value; armComponent.reachingTimer += deltaTime / armComponent.reachDuration; if (armComponent.reachingTimer >= 1f) { // We've arrived at the rock ecb.RemoveComponent <ConveyorComponent>(index, intendedRock); ecb.AddComponent(index, intendedRock, new RockHeldComponent()); ecb.RemoveComponent <ArmReachingTag>(index, armEntity); ecb.AddComponent(index, armEntity, new ArmHoldingTag()); armComponent.windupTimer = -.5f; armComponent.throwTimer = 0f; armComponent.heldRock = intendedRock; armComponent.heldRockOffset = armComponent.handMatrix.inverse.MultiplyPoint3x4(intendedRockTranslation.Value); } else { // We're still reaching for the rock // smoothed reach timer float grabT = armComponent.reachingTimer; grabT = 3f * grabT * grabT - 2f * grabT * grabT * grabT; armComponent.savedGrabT = grabT; armComponent.reachingTimer = Mathf.Clamp01(armComponent.reachingTimer); // reaching overrides our idle hand position armComponent.handTarget = math.lerp(armComponent.idleHandTarget, armComponent.grabHandTarget, armComponent.savedGrabT); } } else { // Rock has eluded our grasp. Unreserve the rock. ecb.RemoveComponent <ReservedTag>(index, intendedRock); ecb.RemoveComponent <ArmReachingTag>(index, armEntity); ecb.AddComponent(index, armEntity, new ArmResetTag()); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { NativeArray <Entity> lEntitiesToPickup = m_Query.ToEntityArray(Allocator.TempJob); NativeArray <Translation> entitiesTranslation = m_Query.ToComponentDataArray <Translation>(Allocator.TempJob); EntityCommandBuffer.Concurrent commandBuffer = m_EntityCommandBuffer.CreateCommandBuffer().ToConcurrent(); JobHandle handle = Entities. WithAll <TC_PerformingAction>() .WithNone <C_HoldComponentData>() .ForEach((Entity entity, int entityInQueryIndex, in Translation translation, in C_PickInfo pickInfo, in DirectionData directionData) => { int2 i2Direction = directionData.directionLook; float fMinLength = translation.Value.x; float fMaxLength = translation.Value.x + i2Direction.x * pickInfo.PickupDistance; int iClosestEntity = -1; float lastDistance = -1; for (int i = 0; i < entitiesTranslation.Length; i++) { Translation objTranslation = new Translation { Value = entitiesTranslation[i].Value }; if (!Utils.IsInRange(objTranslation.Value.x, fMinLength, fMaxLength)) { continue; } var actualDistance = Utils.CalculateDistance(objTranslation.Value.x, translation.Value.x); if (lastDistance > actualDistance) { continue; } lastDistance = actualDistance; iClosestEntity = i; } if (iClosestEntity == -1) { } else { commandBuffer.RemoveComponent <TC_CanPick>(entityInQueryIndex, entity); commandBuffer.AddComponent <C_HoldComponentData>(entityInQueryIndex, entity); commandBuffer.SetComponent(entityInQueryIndex, entity, new C_HoldComponentData { Item = lEntitiesToPickup[iClosestEntity] }); commandBuffer.RemoveComponent <TC_Pickable>(entityInQueryIndex, lEntitiesToPickup[iClosestEntity]); commandBuffer.AddComponent <TC_InHold>(entityInQueryIndex, lEntitiesToPickup[iClosestEntity]); commandBuffer.AddComponent <C_SetPositionComponentData>(entityInQueryIndex, lEntitiesToPickup[iClosestEntity]); } commandBuffer.RemoveComponent <TC_PerformingAction>(entityInQueryIndex, entity); }).WithoutBurst().Schedule(inputDeps);
public void Execute ( Entity actor, int index, ref ActionInfo c0) { EndEcb.RemoveComponent <OnActionInvalid>(index, actor); EndEcb.RemoveComponent(index, actor, c0.CurrentActionTag); c0 = default; }
public void Execute(Entity actor, int index, [ReadOnly] ref ValidateUsageRequest c0) { EndEcb.RemoveComponent <ValidateUsageRequest>(index, actor); if (c0.ResultType != ResultType.Fail) { return; } BeginEcb.AddComponent <OnActionInvalid>(index, actor); EndEcb.RemoveComponent <OnActionInvalid>(index, actor); }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var Velocities = chunk.GetNativeArray(VelocityType); var Translations = chunk.GetNativeArray(TranslationType); var Targets = chunk.GetNativeArray(TargetType); var Entities = chunk.GetNativeArray(EntityType); for (int i = 0; i < chunk.Count; ++i) { var Target = Targets[i]; if (HeldType.Exists(Target.Value)) { ecb.RemoveComponent(chunkIndex, Entities[i], typeof(C_Target)); continue; } var translation = Translations[i]; var velocity = Velocities[i]; var targetPos = TranslationData[Target.Value].Value; var delta = targetPos - translation.Value; var distanceSquared = delta.x * delta.x + delta.y * delta.y + delta.z * delta.z; var grid = GridType[Target.Value]; if (StackType[Target.Value].index < StackHeights[GridIndex(grid.x, grid.y)] - 1) { //Not top of stack anymore. ecb.RemoveComponent(chunkIndex, Entities[i], typeof(C_Target)); continue; } if (distanceSquared < GrabDistance * GrabDistance) { C_Held held; held.Holder = Entities[i]; Tag_IsHeld tag; ecb.SetComponent(chunkIndex, Target.Value, held); ecb.AddComponent(chunkIndex, Target.Value, tag); ecb.RemoveComponent(chunkIndex, Entities[i], typeof(C_Target)); C_Holding hold; hold.ent = Target.Value; ecb.AddComponent(chunkIndex, Entities[i], hold); continue; } velocity.Value += delta * (ChaseForce * dt / sqrt(distanceSquared)); Velocities[i] = velocity; } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var entityArray = chunk.GetNativeArray(EntityType); var caretStateAccessor = chunk.GetNativeArray(CaretStateType); var inputFieldArray = chunk.GetNativeArray(InputFieldType); for (int i = 0; i < chunk.Count; i++) { var inputFieldEntity = entityArray[i]; var thisInputField = inputFieldArray[i]; var isPointerInputPending = TargetToPointerEvent.TryGetValue(inputFieldEntity, out var pointerEventEntity); var isKeyboardInputPending = TargetToKeyboardEvent.TryGetValue(inputFieldEntity, out var eventEntity); if (isPointerInputPending || isKeyboardInputPending) { DynamicBuffer <PointerInputBuffer> pointerInputBuffer = default; if (isPointerInputPending) { pointerInputBuffer = PointerInputBufferType[pointerEventEntity]; } var textData = TextDataFromEntity[thisInputField.Target]; int oldTextLen = textData.Length; // Handle selection and click events if (isPointerInputPending) { caretStateAccessor[i] = ProcessPointerInput(inputFieldEntity, pointerInputBuffer, textData, caretStateAccessor[i], chunkIndex); } if (isKeyboardInputPending) { CommandBuff.AddComponent(chunkIndex, thisInputField.Target, new DirtyElementFlag()); caretStateAccessor[i] = ProcessInput(inputFieldEntity, KeyboardInputBufferType[eventEntity], textData, caretStateAccessor[i], chunkIndex); if (thisInputField.Placeholder != default) { if (textData.Length > 0) { CommandBuff.AddComponent(chunkIndex, thisInputField.Placeholder, new Disabled()); } else if (oldTextLen > 0 && textData.Length == 0) { CommandBuff.RemoveComponent <Disabled>(chunkIndex, thisInputField.Placeholder); } } } } } }
public void Execute(Entity e, int index, DynamicBuffer <CollisionInfoComp> cb, ref BoubleComp b, ref CollisionInfoSettingComp setting) { // var b = bubs[e]; if (cb.Length > 0) { for (int i = 0; i < cb.Length; i++) { ci = cb[i]; if (bubs.ContainsKey(ci.Opponent) == false || ci.Opponent == prefabEntity) { continue; } if (ci.OpponentType == OpponentType.Bouble) { op = bubs[ci.Opponent]; if (b.gravRadius == op.gravRadius) { // the tie breaker is Entity index b.gravRadius += (b.entity.Index > op.entity.Index) ? 0.0001f: -0.0001f; } if (b.gravRadius > op.gravRadius) { b.gravRadius += op.gravRadius * scaleInc; b.velc += (double3)op.vel * (op.gravRadius / b.gravRadius) * scaleInc; } else { if (explode) { exp = new ExplosionComp { timeToLive = explosionLifeTime, endScale = explosionEndScale, init = true, }; ecb.AddComponent <ExplosionComp>(i, e, exp); ecb.RemoveComponent <CollisionInfoSettingComp>(i, e); ecb.RemoveComponent <CollisionInfoComp>(i, e); ecb.RemoveComponent <PhysicsVelocity>(i, e); ecb.RemoveComponent <PhysicsCollider>(i, e); ecb.RemoveComponent <PhysicsDamping>(i, e); ecb.RemoveComponent <PhysicsGravityFactor>(i, e); ecb.RemoveComponent <PhysicsMass>(i, e); ecb.RemoveComponent <BoubleComp>(i, e); } else { ecb.DestroyEntity(i, e); } break; } } } cb.Clear(); } }
//public SharedComponentDataArray <Components.Half3SharedComponent> a_lodTargetPosition ; // public void Execute () // for IJob public void Execute(int i) // for IJobParallelFor { // Common.Components.LodComponent lodData = data.a_lod [i] ; //int i_triggerID = lodData.i_triggerID ; // float3 f3_targetPosition = targetsData.a_targetPosition [i].f3 ; // currently considering only one entity target float3 f3_position = data.a_movePatterns [i].f3_position; float3 f3_positionDiff = f3_targetPosition - f3_position; float f_distance = math.sqrt(math.lengthSquared(f3_positionDiff)); // TODO: Optimise sqrt, for lookup float f_switch2NextLodDistance = a_switch2NextLodDistances [2]; float f_switch2PreviousLodDistance = a_switch2PreviousLodDistances [2]; if (f_distance >= f_switch2NextLodDistance) { // TODO: switch to next LOD // there is no next LOD yet //commandsBuffer.RemoveComponent <Common.Components.Lod01Tag> ( a_entities [i] ) ; //commandsBuffer.RemoveComponent <Common.Components.Lod02Tag> ( a_entities [i] ) ; } else if (f_distance <= f_switch2PreviousLodDistance) { // Debug.Log ( "Switch Lod020 for entity #" + data.a_entities [i].Index ) ; // Debug.Log ( f_distance ) ; Entity jobEntity = data.a_entities [i]; // Switch to lower LOD commandsBuffer.RemoveComponent <Blocks.Pattern.Components.Lod030Tag> (jobEntity); commandsBuffer.AddComponent <Blocks.Pattern.Components.Lod020Tag> (jobEntity, new Blocks.Pattern.Components.Lod020Tag()); commandsBuffer.AddComponent(jobEntity, new Blocks.Pattern.Components.IsLodSwitchedTag()); } }
//public SharedComponentDataArray <Components.Half3SharedComponent> a_lodTargetPosition ; // public void Execute () // for IJob public void Execute(int i) // for IJobParallelFor { float3 f3_position = data.a_movePatterns [i].f3_position; float3 f3_positionDiff = f3_targetPosition - f3_position; float f_distance = math.sqrt(math.lengthSquared(f3_positionDiff)); // TODO: Optimise sqrt, for lookup float f_switch2NextLodDistance = a_switch2NextLodDistances [0]; float f_switch2PreviousLodDistance = a_switch2PreviousLodDistances [0]; if (f_distance >= f_switch2NextLodDistance) { //Debug.Log ( "Switch Lod020 for entity #" + data.a_entities [i].Index ) ; //Debug.Log ( f_distance ) ; Entity jobEntity = data.a_entities [i]; // switch to next LOD commandsBuffer.RemoveComponent <Blocks.Pattern.Components.Lod010Tag> (jobEntity); commandsBuffer.AddComponent(jobEntity, new Blocks.Pattern.Components.Lod020Tag()); commandsBuffer.AddComponent(jobEntity, new Blocks.Pattern.Components.IsLodSwitchedTag()); } else if (f_distance <= f_switch2PreviousLodDistance) { // there is no lower LOD } //} }
public void Execute(int index) { if (Time > Firings[index].Time + Weapons[index].FireRate) { CommandBuffer.RemoveComponent <Firing>(index, WeaponEntities[index]); } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var entities = chunk.GetNativeArray(EntityType); if (chunk.Has(DirtyElementType)) { for (int i = 0; i < chunk.Count; i++) { var entity = entities[i]; var root = GetRootRecursive(entity); if (root != Entity.Null) { CommandBuff.AddComponent(chunkIndex, root, new RebuildCanvasHierarchyFlag()); CommandBuff.RemoveComponent(chunkIndex, entity, DirtyElementComponent); } } } else if (chunk.Has(UpdateColorType)) // If element is dirty, there is no need to set updatecolor, because color will be updated anyway { for (int i = 0; i < chunk.Count; i++) { var entity = entities[i]; var root = GetRootRecursive(entity); if (root != Entity.Null) { CommandBuff.AddComponent(chunkIndex, root, new UpdateCanvasVerticesFlag()); } } } }
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 void Execute(Entity playerEntity, int index, ref PlayerActorArray playerActorArray) { playerActorArray = default; endCommandBuffer.RemoveComponent(index, playerEntity, Player_OnShipDestroy_NextFrameMessage); // /*playerActorArray.shipEntity = Entity.Null; * * // * if (playerActorArray.shieldEntity != Entity.Null) * { * playerActorArray.shieldEntity = Entity.Null; * } * * // * for (var i = PlayerActorArray.WeaponBegin; i <= PlayerActorArray.AssistWeaponEnd; ++i) * { * var weaponEntity = playerActorArray[i]; * if (weaponEntity == Entity.Null) * continue; * * playerActorArray[i] = default; * }*/ }
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 Execute(Entity entity, int index, [WriteOnly] ref Translation translation, [ReadOnly] ref BlockOffset offset) { PiecePosition position = Center[offset.Center]; switch (position.Rotation) { case 0: translation.Value = new float3(position.CenterX + offset.OffsetX, position.CenterY + offset.OffsetY, 0f); break; case 90: translation.Value = new float3(position.CenterX + offset.OffsetY, position.CenterY - offset.OffsetX, 0f); break; case 180: translation.Value = new float3(position.CenterX - offset.OffsetX, position.CenterY - offset.OffsetY, 0f); break; case 270: translation.Value = new float3(position.CenterX - offset.OffsetY, position.CenterY + offset.OffsetX, 0f); break; } Buffer.RemoveComponent <TagMove>(index, entity); }
public void Execute(Entity entity, int index, [ReadOnly] ref ResolveAbilityBloodPaktData resolveAbilityDat) { EntityCommandBuffer.RemoveComponent <ResolveAbilityBloodPaktData>(index, entity); var targetMonster = resolveAbilityDat.TargetMonster; EntityCommandBuffer.SetComponent(index, targetMonster, new StatData { Value = PlayerHp }); EntityCommandBuffer.AddComponent(index, targetMonster, new DirtyStatData()); EntityCommandBuffer.SetComponent(index, PlayerEntity, new PlayerData { Hp = MonsterHp, Coins = PlayerCoins }); var e = EntityCommandBuffer.CreateEntity(index); EntityCommandBuffer.AddComponent(index, e, new SetHpData { Amount = MonsterHp }); EntityCommandBuffer.CreateEntity(index, PostresolveCardArhetype); }
public void Execute(int index) { if (currentTime - spawnings[index].firedAt < 0.5f) { entityCommandBuffer.RemoveComponent <MatterSpawning>(index, entities[index]); } }