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, [ReadOnly] ref Connection connection, [ReadOnly] ref ConnectionLength conLength) { CommandBuffer.AddComponent(index, entity, new ConnectionState { EnterLength = conLength.Length, ExitLength = 0f, }); CommandBuffer.AddBuffer <AgentQueueBuffer>(index, entity); }
public void Execute(int index) { CommandBuffer.AddComponent(index, Entities[index], new Position()); CommandBuffer.AddComponent(index, Entities[index], new Rotation()); CommandBuffer.AddComponent(index, Entities[index], new Scale()); CommandBuffer.AddComponent(index, Entities[index], new CopyTransformToGameObject()); CommandBuffer.AddComponent(index, Entities[index], new LifeTime()); CommandBuffer.AddBuffer <Angle>(index, Entities[index]); }
public void Execute(int index) { var road = Roads[index]; Entity entity = default; DynamicBuffer <LaneVertex> laneVertices = default; if (SplitScheme == SplitScheme.Road) { entity = CommandBuffer.CreateEntity(index, RoadLaneArchetype); CommandBuffer.SetComponent(index, entity, new RoadLane { Name = road.Name }); laneVertices = CommandBuffer.AddBuffer <LaneVertex>(index, entity); } for (var geometryIdx = road.GeometryStartIndex; geometryIdx < road.GeometryStartIndex + road.GeometryCount; geometryIdx++) { var geometry = Geometries[geometryIdx]; if (SplitScheme == SplitScheme.Geometry) { entity = CommandBuffer.CreateEntity(index, RoadLaneArchetype); CommandBuffer.SetComponent(index, entity, new RoadLane { Name = new NativeString512($"{road.Name} {geometry.geometryKind}") }); laneVertices = CommandBuffer.AddBuffer <LaneVertex>(index, entity); } var samples = GeometrySampling.BuildSamplesFromGeometry(geometry, 3f); foreach (var sample in samples) { // TODO: support elevation //Samples use x/y coordinates. Translate to x/z planar Unity coordinates laneVertices.Add(new LaneVertex { GeometryIndex = geometryIdx - road.GeometryStartIndex, Position = sample.pose.pos, Orientation = sample.pose.rot }); } } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { NativeArray <UnitMovement> movements = chunk.GetNativeArray(UnitMovementType); NativeArray <MoveTo> unitMoveTo = chunk.GetNativeArray(UnitMoveToType); NativeArray <Entity> entities = chunk.GetNativeArray(EntityType); for (var i = 0; i < movements.Length; i++) { var move = movements[i]; var moveTo = unitMoveTo[i]; if (move.CurrentCellCoord.x != moveTo.Coord.x || move.CurrentCellCoord.y != moveTo.Coord.y) { EntityCommandBuffer.AddComponent <Path>(chunkIndex, entities[i]); EntityCommandBuffer.SetComponent(chunkIndex, entities[i], new Path { StartCoord = move.CurrentCellCoord, GoalCoord = moveTo.Coord, InProgress = true, Reachable = false }); EntityCommandBuffer.AddBuffer <PathNode>(chunkIndex, entities[i]); EntityCommandBuffer.AddBuffer <SearchNode>(chunkIndex, entities[i]); movements[i] = UnitMovement.Reset(move); #if UNITY_EDITOR EntityCommandBuffer.AddBuffer <DebugNode>(chunkIndex, entities[i]); #endif } EntityCommandBuffer.RemoveComponent <MoveTo>(chunkIndex, entities[i]); } }
public void Execute(int index) { var buffer = CommandBuffer.AddBuffer <EcsIntElement>(index, Entities[index]); var sourceBuffer = new NativeArray <EcsIntElement>(100, Allocator.Temp); for (var i = 0; i < sourceBuffer.Length; ++i) { sourceBuffer[i] = i; } buffer.CopyFrom(sourceBuffer); sourceBuffer.Dispose(); }
public void Execute(Entity entity, int index, [ReadOnly] ref EntitySlot slots) { var writeBuffer = CommandBuffer.AddBuffer <EntitySlotBuffer>(index, entity); writeBuffer.Reserve(slots.SlotCount); for (int i = 0; i < slots.SlotCount; i++) { writeBuffer.Add(new EntitySlotBuffer { Agent = Entity.Null, }); } CommandBuffer.AddComponent(index, entity, new EntitySlotDone()); }
public StateData(int jobIndex, EntityCommandBuffer.Concurrent entityCommandBuffer, Entity stateEntity) { StateEntity = stateEntity; TraitBasedObjects = entityCommandBuffer.AddBuffer <TraitBasedObject>(jobIndex, stateEntity); TraitBasedObjectIds = entityCommandBuffer.AddBuffer <TraitBasedObjectId>(jobIndex, stateEntity); AgentBuffer = entityCommandBuffer.AddBuffer <Agent>(jobIndex, stateEntity); LocationBuffer = entityCommandBuffer.AddBuffer <Location>(jobIndex, stateEntity); TargetBuffer = entityCommandBuffer.AddBuffer <Target>(jobIndex, stateEntity); CollectibleBuffer = entityCommandBuffer.AddBuffer <Collectible>(jobIndex, stateEntity); }
public StateData(int jobIndex, EntityCommandBuffer.Concurrent entityCommandBuffer, Entity stateEntity) { StateEntity = stateEntity; TraitBasedObjects = entityCommandBuffer.AddBuffer <TraitBasedObject>(jobIndex, stateEntity); TraitBasedObjectIds = entityCommandBuffer.AddBuffer <TraitBasedObjectId>(jobIndex, stateEntity); LocationBuffer = entityCommandBuffer.AddBuffer <Location>(jobIndex, stateEntity); RobotBuffer = entityCommandBuffer.AddBuffer <Robot>(jobIndex, stateEntity); DirtBuffer = entityCommandBuffer.AddBuffer <Dirt>(jobIndex, stateEntity); MoveableBuffer = entityCommandBuffer.AddBuffer <Moveable>(jobIndex, stateEntity); }
public StateData(int jobIndex, EntityCommandBuffer.Concurrent entityCommandBuffer, Entity stateEntity) { StateEntity = stateEntity; TraitBasedObjects = entityCommandBuffer.AddBuffer <TraitBasedObject>(jobIndex, stateEntity); TraitBasedObjectIds = entityCommandBuffer.AddBuffer <TraitBasedObjectId>(jobIndex, stateEntity); GameBuffer = entityCommandBuffer.AddBuffer <Game>(jobIndex, stateEntity); CoordinateBuffer = entityCommandBuffer.AddBuffer <Coordinate>(jobIndex, stateEntity); CellBuffer = entityCommandBuffer.AddBuffer <Cell>(jobIndex, stateEntity); BlockerBuffer = entityCommandBuffer.AddBuffer <Blocker>(jobIndex, stateEntity); }
public void Execute(Entity entity, int index, [ReadOnly] ref Spline spline, [ReadOnly] ref EntitySlot slots) { var buffer = CommandBuffer.AddBuffer <SplineSegmentBuffer>(index, entity); buffer.Reserve(slots.SlotCount); //TODO compute correct spline length here! float totalLength = math.length(spline.a - spline.d); float segmentLength = totalLength / slots.SlotCount; for (int i = 0; i < slots.SlotCount; i++) { buffer.Add(new SplineSegmentBuffer { Length = (int)math.ceil(segmentLength), }); } CommandBuffer.AddComponent(index, entity, new SplineDone()); }
//The DataToSpawn component tells us how many entities with buffers to create public void Execute(Entity spawnEntity, int index, [ReadOnly] ref DataToSpawn data) { for (int e = 0; e < data.EntityCount; e++) { //Create a new entity for the command buffer Entity newEntity = CommandBuffer.CreateEntity(index); //Create the dynamic buffer and add it to the new entity DynamicBuffer <MyBufferElement> buffer = CommandBuffer.AddBuffer <MyBufferElement>(index, newEntity); //Reinterpret to plain int buffer DynamicBuffer <int> intBuffer = buffer.Reinterpret <int>(); //Optionally, populate the dynamic buffer for (int j = 0; j < data.ElementCount; j++) { intBuffer.Add(j); } } //Destroy the DataToSpawn entity since it has done its job CommandBuffer.DestroyEntity(index, spawnEntity); }
public void Execute(Entity entity, int index, ref Health c0) { EntityCommandBuffer.AddBuffer <DamageStack>(index, entity); }
public void Execute(Entity entity, int jobIndex, [ReadOnly] ref NetworkStreamConnection con) { var rpcBuffer = commandBuffer.AddBuffer <OutgoingRpcDataStreamBufferComponent>(jobIndex, entity); RpcSystem.SendProtocolVersion(rpcBuffer, protocolVersion); }
public void Compute(int index, EntityCommandBuffer.Concurrent commandBuffer) { int len = _nodes.Length; var nodes = _nodes.GetKeyArray(Allocator.Temp); for (int k = 0; k < len; k++) { var nodeK = nodes[k]; var kk = new Path(nodeK, nodeK); WriteDist(kk, 0); } for (int k = 0; k < len; k++) { var nodeK = nodes[k]; for (int i = 0; i < len; i++) { var nodeI = nodes[i]; for (int j = 0; j < len; j++) { var nodeJ = nodes[j]; var ij = new Path(nodeI, nodeJ); var ik = new Path(nodeI, nodeK); float newDist = ReadDist(ik) + ReadDist(new Path(nodeK, nodeJ)); if (ReadDist(ij) > newDist) { WriteDist(ij, newDist); WriteNext(ij, _next[ik]); } } } } int conLen = _cons.Length; for (int i = 0; i < conLen; i++) { var conEnt = _cons[i]; commandBuffer.AddComponent(index, conEnt, new IndexInNetwork { Index = i }); } for (int i = 0; i < conLen; i++) { var conI = _cons[i]; var endI = _conInfos[i].To; var buffer = commandBuffer.AddBuffer <NextBuffer>(index, conI); for (int j = 0; j < conLen; j++) { Entity nextCon; var conJ = _cons[j]; var fromJ = _conInfos[j].From; if (i == j) { nextCon = Entity.Null; } else if (endI == fromJ) { nextCon = conJ; } else { if (!_next.TryGetValue(new Path(endI, fromJ), out nextCon)) { nextCon = Entity.Null; } } buffer.Add(new NextBuffer { Connection = nextCon, }); } } nodes.Dispose(); }
public void Execute(Entity entity, int index, ref PathFindingRequest request) { _iterations = 0; _pathNodeCount = 0; //Generate Working Containers var openSet = new NativeMinHeap(MapSize, Allocator.Temp); var cameFrom = new NativeArray <int>(MapSize, Allocator.Temp); var costCount = new NativeArray <int>(MapSize, Allocator.Temp); for (var i = 0; i < MapSize; i++) { costCount[i] = int.MaxValue; } // Path finding var startId = request.StartId; var goalId = request.GoalId; openSet.Push(new MinHeapNode(startId, 0)); costCount[startId] = 0; var currentId = -1; while (_iterations < IterationLimit && openSet.HasNext()) { var currentNode = openSet[openSet.Pop()]; currentId = currentNode.Id; if (currentId == goalId) { break; } var neighboursId = new NativeList <int>(4, Allocator.Temp); Nodes[currentId].GetNeighbours(ref neighboursId); foreach (var neighbourId in neighboursId) { //if cost == -1 means obstacle, skip if (Nodes[neighbourId].GetCost() == -1) { continue; } var currentCost = costCount[currentId] == int.MaxValue ? 0 : costCount[currentId]; var newCost = currentCost + Nodes[neighbourId].GetCost(); //not better, skip if (costCount[neighbourId] <= newCost) { continue; } var priority = newCost + Nodes[neighbourId].Heuristic(goalId); openSet.Push(new MinHeapNode(neighbourId, priority)); cameFrom[neighbourId] = currentId; costCount[neighbourId] = newCost; } _iterations++; neighboursId.Dispose(); } //Construct path var buffer = ResultECB.AddBuffer <PathRoute>(index, entity); var nodeId = goalId; while (_pathNodeCount < PathNodeLimit && !nodeId.Equals(startId)) { buffer.Add(new PathRoute { Id = nodeId }); nodeId = cameFrom[nodeId]; _pathNodeCount++; } //Construct Result var success = true; var log = new NativeString64("Path finding success"); if (!openSet.HasNext() && currentId != goalId) { success = false; log = new NativeString64("Out of openset"); } if (_iterations >= IterationLimit && currentId != goalId) { success = false; log = new NativeString64("Iteration limit reached"); } else if (_pathNodeCount >= PathNodeLimit && !nodeId.Equals(startId)) { success = false; log = new NativeString64("Step limit reached"); } ResultECB.AddComponent(index, entity, new PathResult { Success = success, Log = log }); //Clean result at end of simulation CleanECB.DestroyEntity(index, entity); //Clear openSet.Dispose(); cameFrom.Dispose(); costCount.Dispose(); }
public DynamicBuffer <T> AddBuffer <T>() where T : struct, IBufferElementData { return(_ecb.AddBuffer <T>(_jobIndex, _entity)); }