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); }
void CheckCollision(int indexA, int indexB) { // we skip if indexA < indexB to avoid checking the same collision twice if (indexA <= indexB || !IsColliding(indexA, indexB)) { return; } Size sizeA = Sizes[indexA]; Size sizeB = Sizes[indexB]; float sizeAValue = sizeA.Value; float sizeBValue = sizeB.Value; if (sizeAValue > sizeBValue) { sizeA.Value = (int)math.min(sizeAValue + sizeBValue, MaxPlayerSize); CommandBuffer.CreateEntity(indexA); CommandBuffer.AddComponent(indexA, new Destroy { Entity = Entities[indexB] }); } else { sizeB.Value = (int)math.min(sizeAValue + sizeBValue, MaxPlayerSize); CommandBuffer.CreateEntity(indexA); CommandBuffer.AddComponent(indexA, new Destroy { Entity = Entities[indexA] }); } Sizes[indexA] = sizeA; Sizes[indexB] = sizeB; }
public void Execute(Entity entity, int index, [Unity.Collections.ReadOnly] ref ResolveAbilityTradeData c0) { EntityCommandBuffer.RemoveComponent <ResolveAbilityTradeData>(index, entity); var e = EntityCommandBuffer.CreateEntity(index); EntityCommandBuffer.AddComponent(index, e, new LootCoinsData { Amount = 10, }); EntityCommandBuffer.CreateEntity(index, PostResolveCardArchetype); }
public void Execute(Entity entity, int index, [Unity.Collections.ReadOnly] ref CoinsData coinsData, ref StatData statData) { EntityCommandBuffer.RemoveComponent <ResolveCardInteractionData>(index, entity); EntityCommandBuffer.AddComponent(index, entity, new DirtyData()); var e = EntityCommandBuffer.CreateEntity(index, LootCoinsArchetype); EntityCommandBuffer.SetComponent(index, e, new LootCoinsData { Amount = statData.Value }); EntityCommandBuffer.CreateEntity(index, PostResolveCardArchetype); }
public void Execute(Entity entity, int index, [ReadOnly] ref PotionData potionData, ref StatData statData) { EntityCommandBuffer.RemoveComponent <ResolveCardInteractionData>(index, entity); EntityCommandBuffer.AddComponent(index, entity, new DirtyData()); var e = EntityCommandBuffer.CreateEntity(index, HealPlayerArchetype); EntityCommandBuffer.SetComponent(index, e, new HealPlayerData { Amount = statData.Value }); EntityCommandBuffer.CreateEntity(index, PostResolveCardArchetype); }
Entity CreateCaret(Entity inputFieldEntity, int chunkIdx) { var caret = CommandBuff.CreateEntity(chunkIdx, CaretArchetype); #if UNITY_EDITOR //CommandBuff.SetName(caret, "INPUT_FIELD_CARET"); #endif CommandBuff.SetComponent(chunkIdx, caret, new InputFieldCaret { InputFieldEntity = inputFieldEntity }); CommandBuff.SetComponent(chunkIdx, caret, new UIParent { Value = inputFieldEntity }); CommandBuff.SetComponent(chunkIdx, caret, new RectTransform() { AnchorMin = new float2(0.0f, 0.0f), AnchorMax = new float2(0.0f, 0.0f), Pivot = new float2(0.0f, 0.0f), Position = new float2(0.0f, 0.0f), SizeDelta = new float2(2.0f, 10.0f) }); CommandBuff.SetComponent(chunkIdx, caret, new VertexColorValue() { Value = new float4(1.0f, 0.0f, 0.0f, 1.0f), }); CommandBuff.SetComponent(chunkIdx, caret, new VertexColorMultiplier() { Value = new float4(1.0f, 1.0f, 1.0f, 1.0f), }); return(caret); }
public void Execute(int index) { Buffer.CreateEntity(); Buffer.AddComponent(new EcsTestData { value = index }); }
public void Execute() { Buffer.CreateEntity(0); Buffer.AddComponent(0, new EcsTestData { value = 1 }); }
public void Execute(int index) { Cmds.CreateEntity(index); Cmds.AddComponent(index, new EcsTestData { value = index }); }
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; } })
protected override void OnUpdate() { //Assumes there is exactly 1 player Entity playerEntity = this.playerQuery.GetSingletonEntity(); EntityCommandBuffer.Concurrent entityCommandBuffer = this.endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); EntityArchetype sfxArchetypeForJob = this.EntityManager.CreateSFXArchetype(); this.Dependency = JobHandle.CombineDependencies(this.Dependency, this.Entities .WithAll <PlayerTag>() .ForEach((int entityInQueryIndex, ref PlayerInfo playerInfo, in PlayerTakeDamageComponent playerTakeDamageComponent) => { playerInfo.Health -= playerTakeDamageComponent.Damage; entityCommandBuffer.RemoveComponent <PlayerTakeDamageComponent>(entityInQueryIndex, playerEntity); //Add Negative SFX Entity sfx = entityCommandBuffer.CreateEntity(entityInQueryIndex, sfxArchetypeForJob); entityCommandBuffer.SetComponent <SFXComponent>(entityInQueryIndex, sfx, new SFXComponent { SFXType = SFXType.Negative }); }).ScheduleParallel(this.Dependency)); this.endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(this.Dependency); this.Dependency.Complete(); }
public void Execute(Entity e, int index, ref PhysicsCollider collider, ref Translation translation, ref Rotation rotation) { ColliderDistanceInput distanceInput = new ColliderDistanceInput { Collider = collider.ColliderPtr, MaxDistance = .01f, Transform = new RigidTransform(rotation.Value, translation.Value), }; NativeList <DistanceHit> hits = new NativeList <DistanceHit>(Allocator.Temp); var collisionWorld = physicsWorld.CollisionWorld; if (collisionWorld.CalculateDistance(distanceInput, ref hits)) { foreach (var hit in hits) { var entity = collisionWorld.Bodies[hit.RigidBodyIndex].Entity; if (entity != e) { if (consumedObjectIndex.HasComponent(entity)) { var consumedEntity = commandBuffer.CreateEntity(index); var consumedObject = consumedObjectIndex[entity]; commandBuffer.AddComponent(index, consumedEntity, consumedObject); commandBuffer.AddComponent(index, consumedEntity, new ConsumedTag()); commandBuffer.DestroyEntity(index, entity); } } } } hits.Dispose(); }
public void Execute(int i) { commandBuffer.CreateEntity(particleArchetype); var rotatorComponent = randomRotators[i * offset]; var newParticle = BootstrapperParticles.particleTemplate; newParticle.velocity = (emitter.emissionDirection + randomDirections[i * offset]) * emitter.initialSpeed; commandBuffer.SetComponent(new Position() { Value = emitterPosition.Value }); commandBuffer.SetComponent(new Rotation() { Value = quaternion.identity }); commandBuffer.SetComponent(new Scale() { Value = 1f }); commandBuffer.SetComponent(rotatorComponent); commandBuffer.SetComponent(newParticle); commandBuffer.AddSharedComponent(BootstrapperParticles.particleLook); }
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, }); }
public void Execute(Entity entity, int index, [ReadOnly] ref CommandTargetComponent state) { if (shoot != 0) { var req = commandBuffer.CreateEntity(index); commandBuffer.AddComponent <FireBulletRequest>(index, req); commandBuffer.AddComponent(index, req, new SendRpcCommandRequestComponent { TargetConnection = entity }); } if (state.targetEntity == Entity.Null) { } else { // If ship, store commands in network command buffer if (inputFromEntity.Exists(state.targetEntity)) { Debug.Log("Does this get called"); var input = inputFromEntity[state.targetEntity]; input.AddCommandData(new TestCommandData { tick = inputTargetTick, shoot = shoot }); } } }
public void Execute(Entity entity, int index, [ReadOnly] ref CommandTargetComponent state) { if (state.targetEntity == Entity.Null) { if (shoot != 0) { var req = commandBuffer.CreateEntity(index); commandBuffer.AddComponent <PlayerSpawnRequest>(index, req); commandBuffer.AddComponent(index, req, new SendRpcCommandRequestComponent { TargetConnection = entity }); } } else { // If ship, store commands in network command buffer if (inputFromEntity.Exists(state.targetEntity)) { var input = inputFromEntity[state.targetEntity]; input.AddCommandData(new ShipCommandData { tick = inputTargetTick, left = left, right = right, thrust = thrust, shoot = shoot }); } } }
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); }
protected override void OnUpdate() { CollisionWorld collisionWorldForJob = this.physicsWorld.PhysicsWorld.CollisionWorld; //SystemBase Dependency for the Physics system -> This system must wait for the phyiscs world to complete in order to create a new batch of parallel jobs this.Dependency = JobHandle.CombineDependencies(this.Dependency, this.physicsWorld.FinalJobHandle); Entity gameStateEntity = this.gameStateQuery.GetSingletonEntity(); GameStateComponent gameStateComponent = this.EntityManager.GetComponentData <GameStateComponent>(gameStateEntity); EntityArchetype sfxArchetypeForJob = this.EntityManager.CreateSFXArchetype(); EntityCommandBuffer.Concurrent entityCommandBuffer = this.endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(); this.Dependency = JobHandle.CombineDependencies(this.Dependency, this.Entities.WithAll <AltarTag>().ForEach((int entityInQueryIndex, in Translation position, in Rotation rotation, in PhysicsCollider collider) => { if (CollisionHelper.ColliderCast(position.Value, position.Value, rotation.Value, collisionWorldForJob, collider)) { gameStateComponent.GameStateEnum = GameStateEnum.Win; entityCommandBuffer.SetComponent <GameStateComponent>(entityInQueryIndex, gameStateEntity, gameStateComponent); //Add Fanfare SFX Entity sfx = entityCommandBuffer.CreateEntity(entityInQueryIndex, sfxArchetypeForJob); entityCommandBuffer.SetComponent <SFXComponent>(entityInQueryIndex, sfx, new SFXComponent { SFXType = SFXType.Fanfare }); } }).ScheduleParallel(this.Dependency));
public void Execute() { if (!queue.TryDequeue(out Spawn spawn)) { return; } var entity = spawn.Prefab.Equals(Entity.Null) ? CommandBuffer.CreateEntity(nativeThreadIndex) : CommandBuffer.Instantiate(nativeThreadIndex, spawn.Prefab); foreach (IBufferElementData buffer in spawn.BufferList) { addBuffer.MakeGenericMethod(buffer.GetType()).Invoke( CommandBuffer, new object[] { nativeThreadIndex, entity } ); } foreach (IComponentData component in spawn.ComponentList) { addComponent.MakeGenericMethod(component.GetType()).Invoke( CommandBuffer, new object[] { nativeThreadIndex, entity, component } ); } }
public void Execute(Entity entity, int index, ref EnemyAttackData attackData) { attackData.Timer += DeltaTime; var attacker = attackData.Source; var target = attackData.Target; if (attackData.Timer >= attackData.Frequency && Health[attacker].Value > 0 && Health[target].Value > 0) { attackData.Timer = 0f; var newHp = Health[target].Value - attackData.Damage; Ecb.SetComponent(index, target, new HealthData { Value = newHp }); var evt = Ecb.CreateEntity(index, HealthUpdatedArchetype); Ecb.SetComponent(index, evt, new HealthUpdatedEvent { Health = newHp }); if (newHp <= 0) { Ecb.AddComponent(index, target, new DeadData()); } } }
public void Execute(ref MatterSpawning spawning, ref Position position, ref Rotation rotation) { entityCommandBuffer.CreateEntity(num); entityCommandBuffer.AddSharedComponent(num, Bootstrap.MatterRenderer); //entityCommandBuffer.AddComponent(num, new TransformMatrix()); //entityCommandBuffer.AddSharedComponent(num, new MoveForward()); var spawnPos = position; spawnPos.Value = spawnPos.Value + randomize; entityCommandBuffer.AddComponent(num, spawnPos); entityCommandBuffer.AddComponent(num, rotation); entityCommandBuffer.AddComponent(num, new Scale() { Value = new float3(1F) }); entityCommandBuffer.AddComponent(num, new MatterObject() { Mass = mass, Density = 1F }); entityCommandBuffer.AddComponent(num, new DynamicObject() { velocity = new float3(0, 0, 0), forces = new float3(0, 0, 0) }); entityCommandBuffer.AddComponent(num, new PendingMatter() { MassToAdd = 0F }); }
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 */, }); }
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(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(Entity entity, int index, [Unity.Collections.ReadOnly] ref ResolveAbilityLIfeData c0) { EntityCommandBuffer.RemoveComponent <ResolveAbilityLIfeData>(index, entity); EntityCommandBuffer.SetComponent(index, PlayerEntity, new PlayerData { Hp = PlayerHP, Coins = PlayerCoins }); var e = EntityCommandBuffer.CreateEntity(index); EntityCommandBuffer.AddComponent(index, e, new SetHpData { Amount = PlayerHP }); EntityCommandBuffer.CreateEntity(index, PostResolveCardArchetype); }
public void Execute(Entity weaponEntity, int index, [ReadOnly] ref WeaponInput weaponInput, [ReadOnly] ref WeaponExplosionSelf weaponExplosionSelf, [ReadOnly] ref WeaponControlInfo weaponControlInfo, ref WeaponControl weaponControl) { 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) { var fireActorType = weaponControlInfo.GetFireActorType(false); if (fireActorType != ActorTypes.None) { var e = ctrlCommandBuffer.CreateEntity(index); ctrlCommandBuffer.AddComponent(index, e, new FireCreateData { actorOwner = weaponExplosionSelf.lastShipActorOwner, shipEntity = weaponExplosionSelf.lastShipEntity, weaponEntity = weaponEntity, fireActorType = fireActorType, firePosition = weaponInput.firePosition, }); } } }
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); }
public void Execute(Entity entity, int index, [ReadOnly] ref MassPoint_C mass, [ReadOnly] ref Translation translation) { for (int j = 0; j < gravtiySenders.Length; j++) { var same = sendertranslations[j].Value == translation.Value; if (same.x && same.y && same.z) { continue; } double3 dir = math.normalize(sendertranslations[j].Value - translation.Value); if (double.IsNaN(dir.x) || double.IsNaN(dir.y) || double.IsNaN(dir.z)) { continue; } double distance = math.distance(sendertranslations[j].Value, translation.Value); if (distance < 1) { distance = 1; } double power = mass.Mass * gravtiySenders[j].GravityMass * G * (1f / distance); // 添加受力情况 Force_C force = new Force_C(); force.value = power * dir; force.type = ForceType.Gravity; force.time = double.MaxValue; force.from = fromEntities[j]; force.to = entity; concurrent.AddComponent(index, concurrent.CreateEntity(index), force); } }
private void BuildChunkAt(float3 chunkPos, int index) { Entity en = commandBuffer.CreateEntity(index, archetype); commandBuffer.SetComponent(index, en, new MegaChunk { center = chunkPos, spawnCubes = true, entity = en }); commandBuffer.SetComponent(index, en, new Translation { Value = chunkPos }); commandBuffer.SetComponent(index, en, new Rotation { Value = quaternion.identity }); commandBuffer.SetComponent(index, en, new LocalToWorld { }); //commandBuffer.AddComponent(index, en, new PhysicsCollider //{ // Value = Unity.Physics.BoxCollider.Create(bm) //}); commandBuffer.AddSharedComponent(index, en, group); }
public void Execute(Entity entity, int jobIndex, ref Translation position, [ReadOnly] ref SpiderTag tag, ref LoadedShotCount loadedShots) { if (loadedShots.TimeToNextShoot > 0) { loadedShots.TimeToNextShoot -= DeltaTime; } else { if (RandomPicker <= SpiderGamePlayController.Controller.ShootingChance) { Entity shot = CommandBuffer.CreateEntity(jobIndex); CommandBuffer.AddComponent(jobIndex, shot, new Translation { Value = new float3(position.Value.x, position.Value.y - 0.2f, position.Value.z) }); CommandBuffer.AddComponent(jobIndex, shot, new ShotTag { Character = ChTags.Spider }); CommandBuffer.AddComponent(jobIndex, shot, new Scale { Value = 0.1f }); CommandBuffer.AddComponent(jobIndex, shot, new LocalToWorld { }); CommandBuffer.AddSharedComponent(jobIndex, shot, new RenderMesh { mesh = GameDetails.GD.Mesh, material = GameDetails.GD.SpiderShotMaterial, }); } loadedShots.TimeToNextShoot = SpiderGamePlayController.Controller.ShootingDelay; } }