Beispiel #1
0
 private void LoadLevel()
 {
     AreTileLoaded = false;
     InitTerrainTiles();
     InitStructuresTiles();
     InitPredictedTiles();
     AskForSpecificManagers();
     AreTileLoaded = true;
     OnTilesLoaded?.Invoke();
     InitState = InitializationState.Ready;
 }
    IEnumerator SetUpGameAndTiles()
    {
        aiGameState = (player == GameState.PLAYERO) ? GameState.PLAYERX : GameState.PLAYERO;
        if (player == GameState.PLAYERX)
        {
            playerWin = GameState.WINX;
        }
        else if (player == GameState.PLAYERO)
        {
            playerWin = GameState.WINO;
        }
        for (int j = 1; j >= -1; j--)
        {
            for (int i = -1; i < Mathf.Sqrt(tiles.Length) - 1; i++)
            {
                tiles[i + 1, j + 1] = Instantiate(Tile, canvas).GetComponent <Tile>();
                tiles[i + 1, j + 1].gameObject.transform.localPosition = new Vector3((float)(dist * i), (float)(dist * j), 0f);
                tiles[i + 1, j + 1].gameObject.SetActive(false);
                if (showDebugTileIndex)
                {
                    tiles[i + 1, j + 1].SetUpTile($"{i + 1} | {j + 1}");
                }
                else
                {
                    tiles[i + 1, j + 1].SetUpTile();
                }
            }
        }
        yield return(new WaitForEndOfFrame());

        OnTilesLoaded?.Invoke();

        //Invokes a function when all Tiles are loaded to prevent other scripts, depending on the tiles from gettin null refferences
        for (int j = 1; j >= -1; j--)
        {
            for (int i = -1; i < Mathf.Sqrt(tiles.Length) - 1; i++)
            {
                tiles[i + 1, j + 1].gameObject.SetActive(true);
                yield return(new WaitForSeconds(setUpTimer));
            }
        }

        foreach (Tile tile in tiles)
        {
            tile.OnPlayerAction += Tile_OnPlayerAction;
        }
        inSelectionMenu = false;
        activeGameState = GameState.PLAYERX;
        OnGameStateChange?.Invoke(activeGameState);
    }