コード例 #1
0
    public void GenerateMap()
    {
        Vector3Int topLeftSpawnTileBottomTile   = StaticGridManager.GetSingleton().topLeftSpawnTile + Vector3Int.down;
        Vector3Int topLeftSpawnTileRightTile    = StaticGridManager.GetSingleton().topLeftSpawnTile + Vector3Int.right;
        Vector3Int topRightSpawnTileBottomTile  = StaticGridManager.GetSingleton().topRightSpawnTile + Vector3Int.down;
        Vector3Int topRightSpawnTileLeftTile    = StaticGridManager.GetSingleton().topRightSpawnTile + Vector3Int.left;
        Vector3Int bottomLeftSpawnTileTopTile   = StaticGridManager.GetSingleton().bottomLeftSpawnTile + Vector3Int.up;
        Vector3Int bottomLeftSpawnTileRightTile = StaticGridManager.GetSingleton().bottomLeftSpawnTile + Vector3Int.right;
        Vector3Int bottomRightSpawnTileTopTile  = StaticGridManager.GetSingleton().bottomRightSpawnTile + Vector3Int.up;
        Vector3Int bottomRightSpawnTileLeftTile = StaticGridManager.GetSingleton().bottomRightSpawnTile + Vector3Int.left;

        TileDef.TileType[,] tileTypes = new TileDef.TileType[StaticGridManager.GetSingleton().width, StaticGridManager.GetSingleton().height];

        for (int x = 0; x < StaticGridManager.GetSingleton().width; ++x)
        {
            for (int y = StaticGridManager.GetSingleton().height - 1; y >= 0; --y)
            {
                Vector3Int cellPosition = new Vector3Int(x, y, 0);
                if (!StaticGridManager.GetSingleton().collidableGroundTilemap.HasTile(cellPosition))
                {
                    Vector3 cellWorldPosition = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.GetCellCenterWorld(cellPosition);

                    bool isSpawnTile =
                        cellPosition == StaticGridManager.GetSingleton().topLeftSpawnTile ||
                        cellPosition == StaticGridManager.GetSingleton().topRightSpawnTile ||
                        cellPosition == StaticGridManager.GetSingleton().bottomLeftSpawnTile ||
                        cellPosition == StaticGridManager.GetSingleton().bottomRightSpawnTile ||
                        cellPosition == topLeftSpawnTileBottomTile ||
                        cellPosition == topLeftSpawnTileRightTile ||
                        cellPosition == topRightSpawnTileBottomTile ||
                        cellPosition == topRightSpawnTileLeftTile ||
                        cellPosition == bottomLeftSpawnTileTopTile ||
                        cellPosition == bottomLeftSpawnTileRightTile ||
                        cellPosition == bottomRightSpawnTileTopTile ||
                        cellPosition == bottomRightSpawnTileLeftTile;
                    if (!isSpawnTile && Random.value <= bricksProbability)
                    {
                        networkManager.AddObject((int)CustomNetworkManager.SpawnPrefabs.BricksTile, cellWorldPosition);
                    }
                    else
                    {
                        Vector3Int       topCellPosition = new Vector3Int(x, y + 1, 0);
                        TileDef.TileType topTileType     = tileTypes[topCellPosition.x, topCellPosition.y];

                        if (topTileType == TileDef.TileType.Bricks)
                        {
                            networkManager.AddObject((int)CustomNetworkManager.SpawnPrefabs.GrassWithShadowTile, cellWorldPosition);
                        }
                        else
                        {
                            networkManager.AddObject((int)CustomNetworkManager.SpawnPrefabs.GrassTile, cellWorldPosition);
                        }

                        tileTypes[x, y] = TileDef.TileType.Grass;
                    }
                }
            }
        }
    }
コード例 #2
0
    // 5) Prefab communicated to the server
    private void OnPrefabResponse(NetworkMessage netMsg)
    {
        MsgTypes.PlayerPrefabMsg msg = netMsg.ReadMessage <MsgTypes.PlayerPrefabMsg>();
        playerPrefab = spawnPrefabs[msg.prefabIndex];
        Player.PlayerColor playerColor    = (Player.PlayerColor)msg.prefabIndex;
        Vector3            playerPosition = StaticGridManager.GetSingleton().GetPlayerSpawnPosition(playerColor);
        GameObject         player         = (GameObject)Instantiate(playerPrefab, playerPosition, Quaternion.identity);

        player.GetComponent <Player>().color = playerColor;
        NetworkServer.AddPlayerForConnection(netMsg.conn, player, msg.controllerId);
    }
コード例 #3
0
    public void RemoveExplodingBricksTile(GameObject explodingBricksTileGameObject)
    {
        Vector3Int cellPosition                = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.WorldToCell(explodingBricksTileGameObject.transform.position);
        Vector3Int bottomNextCellPosition      = cellPosition + Vector3Int.down;
        Vector3    bottomNextCellWorldPosition = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.GetCellCenterWorld(bottomNextCellPosition);
        TileDef    bottomNextTileDef           = tileDefs[bottomNextCellPosition.x, bottomNextCellPosition.y];

        if (bottomNextTileDef != null && bottomNextTileDef.tileType == TileDef.TileType.Grass)
        {
            networkManager.RemoveObject(bottomNextTileDef.gameObject);
            networkManager.AddGridTile((int)CustomNetworkManager.SpawnPrefabs.GrassTile, bottomNextCellWorldPosition);
        }

        networkManager.RemoveObject(explodingBricksTileGameObject);
    }
コード例 #4
0
    public List <GameObject> GetPlayersOnTile(Vector3 position)
    {
        List <GameObject> playersOnTile = new List <GameObject>();
        Vector3Int        cellPosition  = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.WorldToCell(position);

        foreach (GameObject player in playerGameObjects)
        {
            Vector3Int playerCellPosition = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.WorldToCell(player.transform.position);
            if (cellPosition == playerCellPosition)
            {
                playersOnTile.Add(player);
            }
        }

        return(playersOnTile);
    }
コード例 #5
0
    void Start()
    {
        if (singleton != null)
        {
            Destroy(gameObject);
            return;
        }

        singleton = this;

        topLeftSpawnTile     = new Vector3Int(2, height - 1 - 1, 0);
        topRightSpawnTile    = new Vector3Int(width - 2 - 1, height - 1 - 1, 0);
        bottomLeftSpawnTile  = new Vector3Int(2, 1, 0);
        bottomRightSpawnTile = new Vector3Int(width - 2 - 1, 1, 0);

        CenterCamera();
    }
コード例 #6
0
    void Start()
    {
        if (singleton != null)
        {
            Destroy(gameObject);
            return;
        }

        singleton = this;

        NetworkManager mng = NetworkManager.singleton;

        networkManager = mng.GetComponent <CustomNetworkManager>();

        tileDefs          = new TileDef[StaticGridManager.GetSingleton().width, StaticGridManager.GetSingleton().height];
        playerGameObjects = new List <GameObject>();
    }
コード例 #7
0
ファイル: GridManager.cs プロジェクト: McWenker/Folk-Heroes
 public void InitSceneGrid(string sceneName)
 {
     instance.grid          = FindObjectOfType <Grid>().gameObject.GetComponent <GridLayout>();
     instance.groundTilemap = instance.grid.transform.Find("Tilemap_Ground").GetComponent <Tilemap>();
     instance.wallTilemap   = instance.grid.transform.Find("Tilemap_Wall").GetComponent <Tilemap>();
     instance.objectTilemap = instance.grid.transform.Find("Tilemap_Object").GetComponent <Tilemap>();
     if (StaticGridManager.CheckScene(sceneName))
     {
         instance.groundTiles = StaticGridManager.GetSceneDict(sceneName)[0];
         instance.wallTiles   = StaticGridManager.GetSceneDict(sceneName)[1];
         instance.objectTiles = StaticGridManager.GetSceneDict(sceneName)[2];
         UpdateWorldTiles();
     }
     else
     {
         instance.groundTiles = new Dictionary <Vector3, WorldTile>();
         instance.wallTiles   = new Dictionary <Vector3, WorldTile>();
         instance.objectTiles = new Dictionary <Vector3, WorldTile>();
         GetWorldTiles();
         Dictionary <Vector3, WorldTile>[] tileGrids = { instance.groundTiles, instance.wallTiles, instance.objectTiles };
         StaticGridManager.AddScene(sceneName, tileGrids);
     }
 }
コード例 #8
0
ファイル: GridManager.cs プロジェクト: McWenker/Folk-Heroes
 private void SaveGrid(Object sender, int index, string dest)
 {
     Dictionary <Vector3, WorldTile>[] tileGrids = { instance.groundTiles, instance.wallTiles, instance.objectTiles };
     StaticGridManager.UpdateScene(UnityEngine.SceneManagement.SceneManager.GetSceneByBuildIndex(index).name, tileGrids);
 }
コード例 #9
0
    public void SpawnExplosions(Player player, Vector3 position)
    {
        Vector3Int cellPosition            = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.WorldToCell(position);
        Vector3    cellCenterWorldPosition = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.GetCellCenterWorld(cellPosition);

        networkManager.AddExplosion(position, ExplosionController.Orientation.center);

        Vector3Int direction = Vector3Int.left;

        for (int i = 0; i < 4; ++i)
        {
            switch (i)
            {
            case 1:
            {
                direction = Vector3Int.right;
                break;
            }

            case 2:
            {
                direction = Vector3Int.up;
                break;
            }

            case 3:
            {
                direction = Vector3Int.down;
                break;
            }

            default:
            {
                break;
            }
            }

            for (int j = 1; j < player.sizeBombs + 1; ++j)
            {
                Vector3Int nextCellPosition      = cellPosition + direction * j;
                Vector3    nextCellWorldPosition = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.GetCellCenterWorld(nextCellPosition);
                TileDef    nextTileDef           = tileDefs[nextCellPosition.x, nextCellPosition.y];
                if (nextTileDef != null)
                {
                    if (nextTileDef.tileType == TileDef.TileType.Bricks)
                    {
                        networkManager.RemoveObject(nextTileDef.gameObject);
                        networkManager.AddGridTile((int)CustomNetworkManager.SpawnPrefabs.ExplodingBricksTile, nextCellWorldPosition);

                        Vector3Int topNextCellPosition = nextCellPosition + Vector3Int.up;
                        TileDef    topNextTileDef      = tileDefs[topNextCellPosition.x, topNextCellPosition.y];
                        if (topNextTileDef == null || topNextTileDef.tileType == TileDef.TileType.Bricks)
                        {
                            networkManager.AddGridTile((int)CustomNetworkManager.SpawnPrefabs.GrassWithShadowTile, nextCellWorldPosition);
                        }
                        else
                        {
                            networkManager.AddGridTile((int)CustomNetworkManager.SpawnPrefabs.GrassTile, nextCellWorldPosition);
                        }

                        break;
                    }
                    else if (nextTileDef.tileType == TileDef.TileType.Grass)
                    {
                        ExplosionController.Orientation orientation = ExplosionController.Orientation.center;
                        Vector3Int nextNextCellPosition             = nextCellPosition + direction;
                        TileDef    nextNextTileDef = tileDefs[nextNextCellPosition.x, nextNextCellPosition.y];

                        switch (i)
                        {
                        case 0:
                        {
                            if (nextNextTileDef == null || nextNextTileDef.tileType == TileDef.TileType.Bricks || j == player.sizeBombs)
                            {
                                orientation = ExplosionController.Orientation.left;
                            }
                            else
                            {
                                orientation = ExplosionController.Orientation.horizontal;
                            }
                            break;
                        }

                        case 1:
                        {
                            if (nextNextTileDef == null || nextNextTileDef.tileType == TileDef.TileType.Bricks || j == player.sizeBombs)
                            {
                                orientation = ExplosionController.Orientation.right;
                            }
                            else
                            {
                                orientation = ExplosionController.Orientation.horizontal;
                            }
                            break;
                        }

                        case 2:
                        {
                            if (nextNextTileDef == null || nextNextTileDef.tileType == TileDef.TileType.Bricks || j == player.sizeBombs)
                            {
                                orientation = ExplosionController.Orientation.top;
                            }
                            else
                            {
                                orientation = ExplosionController.Orientation.vertical;
                            }
                            break;
                        }

                        case 3:
                        {
                            if (nextNextTileDef == null || nextNextTileDef.tileType == TileDef.TileType.Bricks || j == player.sizeBombs)
                            {
                                orientation = ExplosionController.Orientation.bottom;
                            }
                            else
                            {
                                orientation = ExplosionController.Orientation.vertical;
                            }
                            break;
                        }

                        default:
                        {
                            break;
                        }
                        }

                        networkManager.AddExplosion(nextCellWorldPosition, orientation);
                    }
                }
                else
                {
                    break;
                }
            }
        }
    }
コード例 #10
0
    public void UpdateTile(GameObject tileGameObject)
    {
        Vector3Int cellPosition = StaticGridManager.GetSingleton().nonCollidableGroundTilemap.WorldToCell(tileGameObject.transform.position);

        tileDefs[cellPosition.x, cellPosition.y] = tileGameObject.GetComponent <TileDef>();
    }
コード例 #11
0
    void CmdAddBomb()
    {
        Vector3 bombPosition = StaticGridManager.GetSingleton().GetCellCenterWorldPosition(transform.position);

        networkManager.AddBomb(bombPosition, this);
    }