public void Execute(int index) { PlayerInputData playerInputData = playerInputDataArray[index]; PlayerMoveData playerMoveData = playerMoveDataArray[index]; float3 movementVector = playerMoveData.rightDirection * playerInputData.inputMovementDirection.x + playerMoveData.forwardDirection * playerInputData.inputMovementDirection.z; playerMoveData.position += (playerMoveData.speed * movementVector * deltaTime); playerMoveData.position = math.clamp(playerMoveData.position, playerMoveData.minBoundary, playerMoveData.maxBoundary); playerMoveDataArray[index] = playerMoveData; EntityInstanceRenderData entityInstanceRenderData = entityInstanceRenderDataArray[index]; entityInstanceRenderData.position = playerMoveData.position; entityInstanceRenderData.forward = playerMoveData.forwardDirection; entityInstanceRenderData.up = new float3(0, 1, 0) + (playerMoveData.rightDirection * playerInputData.inputMovementDirection.x); entityInstanceRenderDataArray[index] = entityInstanceRenderData; EntityBoundCenterData entityBoundCenterData = entityBoundCenterDataArray[index]; EntityBoundMinMaxData entityBoundMinMaxData = entityBoundMinMaxDataArray[index]; entityBoundCenterData.centerPosition = playerMoveData.position + entityBoundOffsetDataArray[index].offset; entityBoundMinMaxData.min = entityBoundCenterData.centerPosition - entityBoundExtendDataArray[index].extend; entityBoundMinMaxData.max = entityBoundCenterData.centerPosition + entityBoundExtendDataArray[index].extend; entityBoundCenterDataArray[index] = entityBoundCenterData; entityBoundMinMaxDataArray[index] = entityBoundMinMaxData; }
protected override void OnUpdate() { for (int i = 0; i < playerInputDataGroup.Length; i++) { PlayerInputData playerInputData = playerInputDataGroup.playerInputDataArray[i]; float moveHorizontal = 0.0f; float moveVertical = 0.0f; bool fireButtonPressed = false; switch (playerInputData.playerID) { case 0: { moveHorizontal = Input.GetAxis("Horizontal"); moveVertical = Input.GetAxis("Vertical"); fireButtonPressed = Input.GetButton("Fire1"); } break; default: { Debug.LogError("Addional players not supported for now"); } break; } playerInputData.inputMovementDirection.x = moveHorizontal; playerInputData.inputMovementDirection.z = moveVertical; playerInputData.fireButtonPressed = fireButtonPressed ? 1 : 0; playerInputDataGroup.playerInputDataArray[i] = playerInputData; } }
public void Execute(int chunkIndex) { ArchetypeChunk chunk = chunks[chunkIndex]; int dataCount = chunk.Count; NativeArray <Entity> playerEntityArray = chunk.GetNativeArray(entityTypeRO); NativeArray <PlayerInputData> playerInputDataArray = chunk.GetNativeArray(playerInputDataRO); NativeArray <PlayerMoveData> playerMoveDataArray = chunk.GetNativeArray(playerMoveDataRO); NativeArray <Position> positionDataArray = chunk.GetNativeArray(positionRO); NativeArray <PlayerSpawnBoltData> playerSpawnBoltDataArray = chunk.GetNativeArray(playerSpawnBoltDataRW); for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { Entity playerEntity = playerEntityArray[dataIndex]; PlayerInputData playerInputData = playerInputDataArray[dataIndex]; PlayerMoveData playerMoveData = playerMoveDataArray[dataIndex]; Position playerPosition = positionDataArray[dataIndex]; PlayerSpawnBoltData playerSpawnBoltData = playerSpawnBoltDataArray[dataIndex]; if (playerInputData.fireButtonPressed == 1 && currentTime >= playerSpawnBoltData.nextFireTime) { playerSpawnBoltData.nextFireTime = currentTime + playerSpawnBoltData.fireRate; spawnBoltEntityQueue.Enqueue(playerEntity); } playerSpawnBoltData.spawnPosition = playerPosition.Value + (playerMoveData.forwardDirection * playerSpawnBoltData.offset); playerSpawnBoltData.spawnDirection = playerMoveData.forwardDirection; playerSpawnBoltDataArray[dataIndex] = playerSpawnBoltData; } }
public void Execute(int chunkIndex) { ArchetypeChunk chunk = chunks[chunkIndex]; int dataCount = chunk.Count; NativeArray <PlayerInputData> playerInputDataArray = chunk.GetNativeArray(playerInputDataRO); NativeArray <PlayerMoveData> playerMoveDataArray = chunk.GetNativeArray(playerMoveDataRO); NativeArray <Position> positionDataArray = chunk.GetNativeArray(positionRW); NativeArray <Rotation> rotationDataArray = chunk.GetNativeArray(rotationRW); NativeArray <EntityBoundCenterData> boundCenterDataArray = chunk.GetNativeArray(boundCenterDataRW); NativeArray <EntityBoundMinMaxData> boundMinMaxDataArray = chunk.GetNativeArray(boundMinMaxDataRW); NativeArray <EntityBoundOffsetData> boundOffsetDataArray = chunk.GetNativeArray(boundOffsetDataRO); NativeArray <EntityBoundExtendData> boundExtendDataArray = chunk.GetNativeArray(boundExtendDataRO); for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { PlayerInputData playerInputData = playerInputDataArray[dataIndex]; PlayerMoveData playerMoveData = playerMoveDataArray[dataIndex]; Position playerPosition = positionDataArray[dataIndex]; Rotation playerRotation = rotationDataArray[dataIndex]; float3 shipUp = new float3(0, 1, 0) + (playerMoveData.rightDirection * playerInputData.inputMovementDirection.x); float3 movementVector = playerMoveData.rightDirection * playerInputData.inputMovementDirection.x + playerMoveData.forwardDirection * playerInputData.inputMovementDirection.z; playerPosition.Value += (playerMoveData.speed * movementVector * deltaTime); playerPosition.Value = math.clamp(playerPosition.Value, playerMoveData.minBoundary, playerMoveData.maxBoundary); playerRotation.Value = quaternion.LookRotation(playerMoveData.forwardDirection, shipUp); positionDataArray[dataIndex] = playerPosition; rotationDataArray[dataIndex] = playerRotation; EntityBoundCenterData entityBoundCenterData = boundCenterDataArray[dataIndex]; EntityBoundMinMaxData entityBoundMinMaxData = boundMinMaxDataArray[dataIndex]; entityBoundCenterData.centerPosition = playerPosition.Value + boundOffsetDataArray[dataIndex].offset; entityBoundMinMaxData.min = entityBoundCenterData.centerPosition - boundExtendDataArray[dataIndex].extend; entityBoundMinMaxData.max = entityBoundCenterData.centerPosition + boundExtendDataArray[dataIndex].extend; boundCenterDataArray[dataIndex] = entityBoundCenterData; boundMinMaxDataArray[dataIndex] = entityBoundMinMaxData; } }
protected override void OnUpdate() { ArchetypeChunkComponentType <PlayerInputData> playerInputDataRW = GetArchetypeChunkComponentType <PlayerInputData>(false); NativeArray <ArchetypeChunk> playerInputDataChunk = playerInputDataGroup.CreateArchetypeChunkArray(Allocator.TempJob); if (playerInputDataChunk.Length == 0) { playerInputDataChunk.Dispose(); return; } for (int chunkIndex = 0; chunkIndex < playerInputDataChunk.Length; chunkIndex++) { ArchetypeChunk chunk = playerInputDataChunk[chunkIndex]; int dataCount = chunk.Count; NativeArray <PlayerInputData> playerInputDataArray = chunk.GetNativeArray(playerInputDataRW); for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { PlayerInputData playerInputData = playerInputDataArray[dataIndex]; float moveHorizontal = 0.0f; float moveVertical = 0.0f; bool fireButtonPressed = false; switch (playerInputData.playerID) { case 0: { moveHorizontal = Input.GetAxis("Horizontal"); moveVertical = Input.GetAxis("Vertical"); fireButtonPressed = Input.GetButton("Fire1"); } break; default: { Debug.LogError("Addional players not supported for now"); } break; } playerInputData.inputMovementDirection.x = moveHorizontal; playerInputData.inputMovementDirection.z = moveVertical; playerInputData.fireButtonPressed = fireButtonPressed ? 1 : 0; playerInputDataArray[dataIndex] = playerInputData; } } playerInputDataChunk.Dispose(); }
public void Execute(int index) { PlayerInputData playerInputData = playerInputDataArray[index]; PlayerMoveData playerMoveData = playerMoveDataArray[index]; PlayerSpawnBoltData playerSpawnBoltData = playerSpawnBoltDataArray[index]; if (playerInputData.fireButtonPressed == 1 && currentTime >= playerSpawnBoltData.nextFireTime) { playerSpawnBoltData.nextFireTime = currentTime + playerSpawnBoltData.fireRate; spawnBoltEntityQueue.Enqueue(entityArray[index]); } playerSpawnBoltData.spawnPosition = playerMoveData.position + (playerMoveData.forwardDirection * playerSpawnBoltData.offset); playerSpawnBoltData.spawnDirection = playerMoveData.forwardDirection; playerSpawnBoltDataArray[index] = playerSpawnBoltData; }