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;
            }
        void RestartGame()
        {
            gameOver          = false;
            restart           = false;
            timeSinceGameOver = 0.0f;

            //Spawn player 1
            Entity         newPlayer      = EntityManager.Instantiate(MonoBehaviourECSBridge.Instance.playerEntityPrefab);
            PlayerMoveData playerMoveData = EntityManager.GetComponentData <PlayerMoveData>(newPlayer);

            playerMoveData.position         = MonoBehaviourECSBridge.Instance.playerStartPosition[playerGroup.Length].position;
            playerMoveData.forwardDirection = new float3(0.0f, 0.0f, 1.0f);
            playerMoveData.rightDirection   = new float3(1.0f, 0.0f, 0.0f);
            EntityManager.SetComponentData <PlayerMoveData>(newPlayer, playerMoveData);

            //Recreate the enemy spawner for the player
            if (!EntityManager.Exists(gameplaySpawnerEntity))
            {
                gameplaySpawnerEntity = EntityManager.Instantiate(MonoBehaviourECSBridge.Instance.gameplaySpawnerPrefab);

                SpawnerPositionData positionData = EntityManager.GetComponentData <SpawnerPositionData>(gameplaySpawnerEntity);
                positionData.position.y = playerMoveData.position.y;
                EntityManager.SetComponentData <SpawnerPositionData>(gameplaySpawnerEntity, positionData);

                SpawnerHazardData hazardData = EntityManager.GetComponentData <SpawnerHazardData>(gameplaySpawnerEntity);
                hazardData.hazardIndexArrayLength = MonoBehaviourECSBridge.Instance.hazards.Length;
                hazardData.isBackgroundSpawner    = 0;
                EntityManager.SetComponentData <SpawnerHazardData>(gameplaySpawnerEntity, hazardData);
            }
        }
Esempio n. 3
0
            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;
                }
            }
Esempio n. 4
0
            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;
                }
            }
            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;
            }
Esempio n. 6
0
        void RestartGame()
        {
            gameOver = false;
            restart = false;
            timeSinceGameOver = 0.0f;

            EntityArray currentPlayerEntities = playerGroup.GetEntityArray();
            
            Entity newPlayer = EntityManager.Instantiate(MonoBehaviourECSBridge.Instance.playerEntityPrefab);

            float3 forwardDirection = new float3(0.0f, 0.0f, 1.0f);
            
            Position newPosition = new Position()
            {
                Value = MonoBehaviourECSBridge.Instance.playerStartPosition[currentPlayerEntities.Length].position,
            };
            EntityManager.SetComponentData<Position>(newPlayer, newPosition);

            Rotation newRotation = new Rotation()
            {
                Value = quaternion.LookRotation(forwardDirection, new float3(0.0f, 1.0f, 0.0f)),
            };
            EntityManager.SetComponentData<Rotation>(newPlayer, newRotation);
            
            PlayerMoveData playerMoveData = EntityManager.GetComponentData<PlayerMoveData>(newPlayer);
            playerMoveData.forwardDirection = forwardDirection;
            playerMoveData.rightDirection = new float3(1.0f, 0.0f, 0.0f);
                   
            EntityManager.SetComponentData<PlayerMoveData>(newPlayer, playerMoveData);

            //Recreate the enemy spawner for the player
            if(!EntityManager.Exists(gameplaySpawnerEntity))
            {
                gameplaySpawnerEntity = EntityManager.Instantiate(MonoBehaviourECSBridge.Instance.gameplaySpawnerPrefab);

                SpawnerPositionData positionData = EntityManager.GetComponentData<SpawnerPositionData>(gameplaySpawnerEntity);
                positionData.position.y = newPosition.Value.y;
                EntityManager.SetComponentData<SpawnerPositionData>(gameplaySpawnerEntity, positionData);

                SpawnerHazardData hazardData = EntityManager.GetComponentData<SpawnerHazardData>(gameplaySpawnerEntity);
                hazardData.hazardIndexArrayLength = MonoBehaviourECSBridge.Instance.hazards.Length;
                hazardData.isBackgroundSpawner = 0;
                EntityManager.SetComponentData<SpawnerHazardData>(gameplaySpawnerEntity, hazardData);
            }
        }