public void Execute() { if (Request.Status == PathSearchStatus.Requested) { StartPathSearch(JobIndex, EntityRequestId, Query, CommandBuffer, Request); } else if (Request.Status == PathSearchStatus.Started) { var pathfindingStatus = Query.UpdateFindPath(10, out _); if (pathfindingStatus == PathQueryStatus.Success) { Query.EndFindPath(out int pathSize); var pathBuffer = BuffersLookup[Request.Agent]; //Path is straight and has no obstacles if (pathSize == 1) { pathBuffer.Add(new PathBufferElement { Value = Request.Destination }); CommandBuffer.DestroyEntity(JobIndex, EntityRequestId); return; } //Path is complex and needs to be properly extracted CompletePathSearch(JobIndex, EntityRequestId, Query, CommandBuffer, pathSize, MaximumPoolSize, Request, pathBuffer); } } }
public void Execute(Entity entity, int index, [ReadOnly] ref HelloSpawner8 spawner, [ReadOnly] ref LocalToWorld location) { var random = new Random(1); for (int x = 0; x < spawner.CountX; x++) { for (int y = 0; y < spawner.CountY; y++) { Entity instance = CommandBuffer.Instantiate(index, spawner.Prefab); // Place the instantiated in a grid with some noise var position = math.transform(location.Value, new float3(x * 1.3F, noise.cnoise(new float2(x, y) * 0.21F) * 2, y * 1.3F)); CommandBuffer.SetComponent(index, instance, new Translation { Value = position }); CommandBuffer.SetComponent(index, instance, new LifeTime { Value = random.NextFloat(10.0F, 100.0F) }); CommandBuffer.SetComponent(index, instance, new RotationSpeed { RadiansPerSecond = math.radians(random.NextFloat(25.0F, 90.0F)) }); } } CommandBuffer.DestroyEntity(index, entity); }
public void Execute(Entity entity, int jobIndex, [ReadOnly] ref AlivePeriod ap) { if (ap.GetRemainTime(Time) < 0f) { CommandBuffer.DestroyEntity(jobIndex, entity); } }
public void Execute(int index) { if (CurrentTime > Bullets[index].RemoveAt) { EntityBuffer.DestroyEntity(index, EntityArray [index]); } }
public void Execute(Entity entity, int index, [ReadOnly] ref Translation posComp, ref ItemStorageComponent itemStorageComp) { var atPlayerPosDelta = math.abs(playerPosX - posComp.Value.x); if (itemStorageComp.checkRadius < atPlayerPosDelta) { return; } itemStorageComp.gettingTime -= (agility * deltaTime); if (0.0f < itemStorageComp.gettingTime) { cmdBuf.SetComponent(index, avatarEntity, new ForceStateComponent() { state = (int)ForceState.Item }); return; } var newInventoryComp = inventory; newInventoryComp.currentGettingItem = itemStorageComp.index; cmdBuf.SetComponent(index, avatarEntity, newInventoryComp); cmdBuf.SetComponent(index, avatarEntity, new ForceStateComponent() { state = (int)ForceState.None }); cmdBuf.DestroyEntity(index, entity); }
private InputFieldCaretState ProcessPointerInput(Entity inputFieldEntity, DynamicBuffer <PointerInputBuffer> pointerInputBuffer, DynamicBuffer <TextData> textData, InputFieldCaretState caretState, int chunkIdx) { for (int i = 0; i < pointerInputBuffer.Length; i++) { var pointerEvent = pointerInputBuffer[i]; if (pointerEvent.EventType == PointerEventType.Selected) { caretState.CaretPosition = textData.Length; CommandBuff.AddComponent(chunkIdx, inputFieldEntity, new InputFieldCaretEntityLink() { CaretEntity = CreateCaret(inputFieldEntity, chunkIdx) }); //CommandBuff.RemoveComponent(chunkIdx, caretState.CaretEntity, typeof(Disabled)); } if (pointerEvent.EventType == PointerEventType.Click) { } if (pointerEvent.EventType == PointerEventType.Deselected) { CommandBuff.AddComponent(chunkIdx, inputFieldEntity, new InputFieldEndEditEvent()); if (InputFieldCaretLinkFromEntity.Exists(inputFieldEntity)) { CommandBuff.DestroyEntity(chunkIdx, InputFieldCaretLinkFromEntity[inputFieldEntity].CaretEntity); CommandBuff.RemoveComponent(chunkIdx, inputFieldEntity, typeof(InputFieldCaretEntityLink)); } CommandBuff.AddComponent(chunkIdx, inputFieldEntity, new DirtyElementFlag()); } } return(caretState); }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkTranslations = chunk.GetNativeArray(translationType); var chunkBullets = chunk.GetNativeArray(bulletComponentType); var chunkEntities = chunk.GetNativeArray(entityType); for (int i = 0; i < chunk.Count; i++) { var vec0 = chunkBullets[i].vec; var vec1 = vec0 - math.up() * 9.8f * deltaTime; var newPos = chunkTranslations[i].Value + (vec0 + vec1) * 0.5f * deltaTime; chunkBullets[i] = new BulletComponent { vec = vec1 }; chunkTranslations[i] = new Translation { Value = newPos }; if (newPos.y < 0 && vec1.y < 0) { commandBuffer.DestroyEntity(chunkIndex, chunkEntities[i]); } } }
public void Execute(Entity entity, int index, ref SimapleForceSender_C sender) { double t = deltime; if (sender.time < t) { t = sender.time; } sender.time -= t; if (sender.time <= 0) { concurrent.RemoveComponent(index, entity, typeof(SimapleForceSender_C)); concurrent.DestroyEntity(index, entity); return; } Force_C f = new Force_C(); f.from = entity; f.time = t; f.to = sender.to; f.value = sender.value; f.type = sender.type; var forceClone = concurrent.CreateEntity(index); concurrent.AddComponent(index, forceClone, f); //var senderClone = concurrent.Instantiate (index, entity); //concurrent.SetComponent (index, senderClone, sender); //concurrent.DestroyEntity (index, entity); }
public void Execute(Entity entity, int index, [ReadOnly] ref Distance distance) { if (distance.Value >= distance.MaxDistance || distance.Value >= MaxDistance) // cache distance and compare squares { Buffer.DestroyEntity(index, entity); } }
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(Entity entity, int index, ref Health health) { if (health.Value <= 0) { commandBuffer.DestroyEntity(index, entity); } }
protected override void OnUpdate() { //线程安全的IBufferElementData,World管理的单例锁,Allocator.TempJob 4帧后回收 EntityCommandBuffer.Concurrent cmdBuffer = m_syncPointCEManager.CreateCommandBuffer().ToConcurrent(); //sync point job/Task.Run() Entities.WithName("SpawnData") //找到自己GOToEntity,特殊编译设置 .WithBurst(FloatMode.Default, FloatPrecision.Standard, true) //sync compile: compile before Update .ForEach((Entity entity, int entityInQueryIndex, in SpawnData spawnData, in LocalToWorld location) => { //entityQueryIndex as CommandEntityIndex for (var x = 0; x < spawnData.SpawnSize.x; x++) { for (var z = 0; z < spawnData.SpawnSize.z; z++) { Entity instance = cmdBuffer.Instantiate(entityInQueryIndex, spawnData.PrefabRoot); //center transform(parent.transform), offset float3 pos = math.transform(location.Value, new float3(x, 0, z)); //原生Component,new赋值 cmdBuffer.SetComponent(entityInQueryIndex, instance, new Translation { Value = pos }); //增加Component,也是new赋值 cmdBuffer.AddComponent(entityInQueryIndex, instance, new PlanetRotateBehavior { AngularVelocity = 2 }); cmdBuffer.AddComponent(entityInQueryIndex, instance, new LifetimeData { TimeSpan = spawnData.TimeSpan }); } } //this CommandEntityIndex cmdBuffer.DestroyEntity(entityInQueryIndex, entity); }).ScheduleParallel();
public void Execute(int i) { if (ToDestroy[i].Destroy == 1) { CommandBuffer.DestroyEntity(i, Entities[i]); } }
public void Execute(int i) { var entity = entities[i]; if (predictionMask[i] == 0) { pendingSpawnQueue.Enqueue(new DelayedSpawnGhost { ghostId = newGhostIds[i], spawnTick = newGhosts[i].Tick, oldEntity = entity }); } // If multiple entities map to the same prediction spawned entity, the first one will get it, the others are treated like regular spawns else if (predictionMask[i] > 1 && predictionSpawnCleanupMap.TryAdd(predictionMask[i] - 2, 1)) { commandBuffer.DestroyEntity(i, entity); entity = predictionSpawnGhosts[predictionMask[i] - 2].entity; } else { predictedSpawnQueue.Enqueue(new DelayedSpawnGhost { ghostId = newGhostIds[i], spawnTick = newGhosts[i].Tick, oldEntity = entity }); } var snapshot = snapshotFromEntity[entity]; snapshot.ResizeUninitialized(1); snapshot[0] = newGhosts[i]; ghostMap.TryAdd(newGhostIds[i], new GhostEntity { entity = entity, #if ENABLE_UNITY_COLLECTIONS_CHECKS ghostType = ghostType #endif }); }
public void Execute(Entity entity, int index, [ReadOnly] ref InitComponent initComponent) { var positionX = initComponent.X; var positionY = initComponent.Y; var canMove = true; for (var i = 0; i < BlockPositionArray.Length; i++) { var blockPositionX = BlockPositionArray[i].x; var blockPositionY = BlockPositionArray[i].y; if (positionX != blockPositionX || positionY != blockPositionY) { continue; } canMove = false; break; } if (canMove) { EntityCommandBuffer.RemoveComponent(index, entity, ComponentType.ReadOnly <InitComponent>()); EntityCommandBuffer.AddComponent(index, entity, new StartTranslationComponent() { X = positionX, Y = positionY }); } else { EntityCommandBuffer.DestroyEntity(index, entity); } }
public void Execute(Entity entity, int index, ref CubeComponent cube, ref Scale scale) { cube.lifeTime = cube.lifeTime - deltaTime; if (cube.lifeTime > 0.5 && cube.lifeTime <= 2) { //do not change } else if (cube.lifeTime > 0.2 && cube.lifeTime <= 0.25) { scale.Value = new float3(scale.Value.x, 1f, (0.25f - cube.lifeTime) * 1000); } else if (cube.lifeTime > 0.1 && cube.lifeTime <= 0.2) { //do not change } else if (cube.lifeTime > 0 && cube.lifeTime <= 0.1) { scale.Value = new float3(scale.Value.x, 1f, (cube.lifeTime) * 500); } else if (cube.lifeTime <= 0) { entityCommandBuffer.DestroyEntity(index, entity); } }
public void Execute(Entity entity, int index, ref Translation translation, [ReadOnly] ref Collectible collectible) { if (translation.Value.x == x && translation.Value.z == z) { CommandBuffer.DestroyEntity(index, entity); result[0] = true; } }
public void Execute(Entity entity, int jobIndex, ref CursorLifetimeComponent lifetime) { lifetime.Value -= DeltaTime; if (lifetime.Value <= 0.01f) { CommandBuffer.DestroyEntity(jobIndex, entity); } }
public void Execute(Entity entity, int index, ref LongNoteComponent longNote, ref Scale scale) { if (longNote.position.z <= LongNoteBasis.GetInstance().GetHitPos(LaneController.NoteNum - 1).z + 1.0f && longNote.position.z >= LongNoteBasis.GetInstance().GetHitPos(LaneController.NoteNum - 1).z - 1.0f && LaneController.HitOrNot) { entityCommandBuffer.DestroyEntity(index, entity); } longNote.lifeTime = longNote.lifeTime - deltaTime; if (longNote.lifeTime <= 0) { entityCommandBuffer.DestroyEntity(index, entity); } }
public void Execute(int index, Entity requestEntity, ref ReceiveRpcCommandRequestComponent reqSrc) { CommandBuffer.AddComponent <NetworkStreamInGame>(index, reqSrc.SourceConnection); CommandBuffer.DestroyEntity(index, requestEntity); EnqueueClientConnectedEventJobPart.EventData.ConnectionEntity = reqSrc.SourceConnection; EnqueueClientConnectedEventJobPart.Execute(); CommandBuffer.CreateRpcRequest(index, new ConfirmConnectionRequest(), reqSrc.SourceConnection); }
public void Execute(Entity entity, int index, ref BulletAgeComponentData age) { age.age += deltaTime; if (age.age > age.maxAge) { commandBuffer.DestroyEntity(index, entity); } }
public void Execute(Entity entity, int index, ref Runner runner) { Runner.UpdateMultipleTicks(ref runner, globals); if (runner.dead != 0) { ecb.DestroyEntity(index, entity); } }
public void Execute(Entity entity, int index, ref Lifetime lifetime) { lifetime.value -= dt; if (lifetime.value <= 0) { commandBuffer.DestroyEntity(index, entity); } }
public void Execute(int index) { // remove after 10 seconds if (time > deads[index].TimeOfDeath + 10) { buffer.DestroyEntity(entities[index]); } }
public void Execute(Entity entity, int index, ref Translation position, [ReadOnly] ref ShotTag spiderTag) { if (GameDetails.GD.DestroyedShotsIndexes.Contains(entity.Index)) { GameDetails.GD.DestroyedShotsIndexes.Remove(entity.Index); CommandBuffer.DestroyEntity(index, entity); } }
public void Execute(Entity entity, int index, ref LifeTimerComponent c0) { c0.Value -= DeltaTime; if (c0.Value <= 0.0f) { CommandBuffer.DestroyEntity(index, entity); } }
/// <summary> /// 每帧执行,如果寿命 < 0, 则摧毁实体 /// </summary> /// <param name="entity">实体</param> /// <param name="jobIndex">任务索引器</param> /// <param name="timeToLive">寿命</param> public void Execute(Entity entity, int jobIndex, ref TimeToLive timeToLive) { timeToLive.Value -= dt; if (timeToLive.Value <= 0f) { commands.DestroyEntity(jobIndex, entity); //如果时间到则进入销毁队列 } }
public void Execute(Entity entity, int index, ref AsteroidData c0) { if (index > limit) { //destroy asteroid CommandBuffer.DestroyEntity(index, entity); } }
public void Execute(Entity entity, int index, [ReadOnly] ref PingServerConnectionComponentData connection) { // Cleanup old connections if (!connection.connection.IsCreated) { commandBuffer.DestroyEntity(index, entity); } }
public void Execute(Entity entity, int jobIndex, ref TimeToLive timeToLive) { timeToLive.Value -= mainThreadDeltaTime; if (timeToLive.Value <= 0f) { bufferCommandBuffer.DestroyEntity(jobIndex, entity); } }