public void Execute(int index) { BoltMoveData boltMoveData = boltMoveDataArray[index]; boltMoveData.position += (boltMoveData.speed * boltMoveData.forwardDirection * deltaTime); boltMoveDataArray[index] = boltMoveData; EntityInstanceRenderData entityInstanceRenderData = entityInstanceRenderDataArray[index]; entityInstanceRenderData.position = boltMoveData.position; entityInstanceRenderData.forward = renderDataForward;// new float3(0, -1, 0); //Feedback: Burst write float3(0,0,1) here entityInstanceRenderData.up = -boltMoveData.forwardDirection; entityInstanceRenderDataArray[index] = entityInstanceRenderData; EntityBoundCenterData entityBoundCenterData = entityBoundCenterDataArray[index]; EntityBoundMinMaxData entityBoundMinMaxData = entityBoundMinMaxDataArray[index]; entityBoundCenterData.centerPosition = boltMoveData.position + entityBoundOffsetDataArray[index].offset; entityBoundMinMaxData.min = entityBoundCenterData.centerPosition - entityBoundExtendDataArray[index].extend; entityBoundMinMaxData.max = entityBoundCenterData.centerPosition + entityBoundExtendDataArray[index].extend; entityBoundCenterDataArray[index] = entityBoundCenterData; entityBoundMinMaxDataArray[index] = entityBoundMinMaxData; }
void BoltMove(NativeArray <BoltMoveData> boltMoveDataArray, NativeArray <Position> positionArray, NativeArray <Rotation> rotationArray, NativeArray <EntityBoundCenterData> boundCenterDataArray, NativeArray <EntityBoundMinMaxData> boundMinMaxDataArray, NativeArray <EntityBoundOffsetData> boundOffsetDataArray, NativeArray <EntityBoundExtendData> boundExtendDataArray) { //The array size will be equal to the amount of entity int dataCount = boltMoveDataArray.Length; for (int dataIndex = 0; dataIndex < dataCount; dataIndex++) { Position position = positionArray[dataIndex]; Rotation rotation = rotationArray[dataIndex]; BoltMoveData boltMoveData = boltMoveDataArray[dataIndex]; float3 forwardDirection = boltMoveData.forwardDirection; position.Value += (boltMoveData.speed * forwardDirection * deltaTime); positionArray[dataIndex] = position; EntityBoundCenterData entityBoundCenterData = boundCenterDataArray[dataIndex]; EntityBoundMinMaxData entityBoundMinMaxData = boundMinMaxDataArray[dataIndex]; entityBoundCenterData.centerPosition = position.Value + boundOffsetDataArray[dataIndex].offset; entityBoundMinMaxData.min = entityBoundCenterData.centerPosition - boundExtendDataArray[dataIndex].extend; entityBoundMinMaxData.max = entityBoundCenterData.centerPosition + boundExtendDataArray[dataIndex].extend; boundCenterDataArray[dataIndex] = entityBoundCenterData; boundMinMaxDataArray[dataIndex] = entityBoundMinMaxData; } }
public void Execute(int index) { //Get the spawning information from the entity we spawned from AISpawnBoltData spawnBoltData = aiSpawnBoltDataFromEntity[spawningFromEntityList[index]]; //Get our BoltMoveData BoltMoveData boldMoveData = boldMoveDataFromEntity[spawnedBoltEntityArray[index]]; //Set our initial BoltMoveData values boldMoveData.position = spawnBoltData.spawnPosition; boldMoveData.forwardDirection = spawnBoltData.spawnDirection; boldMoveDataFromEntity[spawnedBoltEntityArray[index]] = boldMoveData; }
public void Execute(int index) { //Get the spawning information from the entity we spawned from AISpawnBoltData spawnBoltData = aiSpawnBoltDataFromEntity[spawningFromEntityList[index]]; //Get our Bolt position/rotation BoltMoveData boltMoveData = boltMoveDataFromEntity[spawnedBoltEntityArray[index]]; Position boltPosition = boltPositionFromEntity[spawnedBoltEntityArray[index]]; Rotation boltRotation = boltRotationFromEntity[spawnedBoltEntityArray[index]]; //Set our initial values boltMoveData.forwardDirection = spawnBoltData.spawnDirection; boltPosition.Value = spawnBoltData.spawnPosition; boltRotation.Value = quaternion.LookRotation(new float3(0, -1, 0), new float3(0, 0, 1)); boltMoveDataFromEntity[spawnedBoltEntityArray[index]] = boltMoveData; boltPositionFromEntity[spawnedBoltEntityArray[index]] = boltPosition; boltRotationFromEntity[spawnedBoltEntityArray[index]] = boltRotation; }
JobHandle SpawnBoltFromEntityList(NativeList <Entity> entityList, Entity prefabEntity, bool isboltFromPlayerList, JobHandle jobDepency) { JobHandle jobDepencyToReturn = jobDepency; if (entityList.Length == 0) { return(jobDepencyToReturn); } UnityEngine.Profiling.Profiler.BeginSample("SpawnBoltFromEntityList"); Entity boltCopy = EntityManager.Instantiate(prefabEntity); EntityManager.RemoveComponent <EntityPrefabData>(boltCopy); //Allocate the amount of entities we need in one shot NativeArray <Entity> newSpawnedBoltEntityArray = new NativeArray <Entity>(entityList.Length, Allocator.TempJob); EntityManager.Instantiate(boltCopy, newSpawnedBoltEntityArray); EntityManager.DestroyEntity(boltCopy); //If the bolts are from players we just set the BoltMoveData directly, they are not enough generated to warrant creating a job if (isboltFromPlayerList) { //For players bolt just set the new bolt data directly //(the cost of starting a job is not work the low amount of data to set) for (int i = 0; i < entityList.Length; i++) { PlayerSpawnBoltData spawnBoltData = EntityManager.GetComponentData <PlayerSpawnBoltData>(entityList[i]); BoltMoveData moveData = EntityManager.GetComponentData <BoltMoveData>(newSpawnedBoltEntityArray[i]); moveData.position = spawnBoltData.spawnPosition; moveData.forwardDirection = spawnBoltData.spawnDirection; EntityManager.SetComponentData <BoltMoveData>(newSpawnedBoltEntityArray[i], moveData); } newSpawnedBoltEntityArray.Dispose(); } else { //For AI bolts, create a job to set the boltMoveData of the new entity //Use GetComponentDataFromEntity the get the components we need SetAIBoltMoveDataJob setAiBoldMoveDataJob = new SetAIBoltMoveDataJob { spawningFromEntityList = entityList, spawnedBoltEntityArray = newSpawnedBoltEntityArray, aiSpawnBoltDataFromEntity = GetComponentDataFromEntity <AISpawnBoltData>(), boldMoveDataFromEntity = GetComponentDataFromEntity <BoltMoveData>(), }; jobDepencyToReturn = setAiBoldMoveDataJob.Schedule(newSpawnedBoltEntityArray.Length, MonoBehaviourECSBridge.Instance.GetJobBatchCount(newSpawnedBoltEntityArray.Length), jobDepency); } UnityEngine.Profiling.Profiler.EndSample(); return(jobDepencyToReturn); }
JobHandle SpawnBoltFromEntityList(NativeList <Entity> entityList, NativeArray <Entity> newSpawnedBoltEntityArray, bool isboltFromPlayerList, JobHandle jobDepency) { JobHandle jobDepencyToReturn = jobDepency; if (entityList.Length == 0) { return(jobDepencyToReturn); } UnityEngine.Profiling.Profiler.BeginSample("SpawnBoltFromEntityList"); //If the bolts are from players we just set the BoltMoveData directly, they are not enough generated to warrant creating a job if (isboltFromPlayerList) { //For players bolt just set the new bolt data directly //(the cost of starting a job is not work the low amount of data to set) for (int i = 0; i < entityList.Length; i++) { PlayerSpawnBoltData spawnBoltData = EntityManager.GetComponentData <PlayerSpawnBoltData>(entityList[i]); Position newPosition = new Position() { Value = spawnBoltData.spawnPosition, }; EntityManager.SetComponentData <Position>(newSpawnedBoltEntityArray[i], newPosition); Rotation newRotation = new Rotation() { Value = quaternion.LookRotation(new float3(0, -1, 0), new float3(0, 0, 1)), }; EntityManager.SetComponentData <Rotation>(newSpawnedBoltEntityArray[i], newRotation); BoltMoveData boltMoveData = EntityManager.GetComponentData <BoltMoveData>(newSpawnedBoltEntityArray[i]); boltMoveData.forwardDirection = spawnBoltData.spawnDirection; EntityManager.SetComponentData <BoltMoveData>(newSpawnedBoltEntityArray[i], boltMoveData); } newSpawnedBoltEntityArray.Dispose(); } else { //For AI bolts, create a job to set the boltMoveData of the new entity //Use GetComponentDataFromEntity the get the components we need SetAIBoltMoveDataJob setAiBoldMoveDataJob = new SetAIBoltMoveDataJob { spawningFromEntityList = entityList, spawnedBoltEntityArray = newSpawnedBoltEntityArray, aiSpawnBoltDataFromEntity = GetComponentDataFromEntity <AISpawnBoltData>(), boltMoveDataFromEntity = GetComponentDataFromEntity <BoltMoveData>(), boltPositionFromEntity = GetComponentDataFromEntity <Position>(), boltRotationFromEntity = GetComponentDataFromEntity <Rotation>(), }; jobDepencyToReturn = setAiBoldMoveDataJob.Schedule(newSpawnedBoltEntityArray.Length, MonoBehaviourECSBridge.Instance.GetJobBatchCount(newSpawnedBoltEntityArray.Length), jobDepency); } UnityEngine.Profiling.Profiler.EndSample(); return(jobDepencyToReturn); }