コード例 #1
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;
                }
            }
        }
    }