Пример #1
0
    private void AddBackgroundSprites(SerialisableTile serialisableTile, InGameMazeTile tile)
    {
        InGameMazeTileBackgroundPlacer tileBackgroundPlacer = new InGameMazeTileBackgroundPlacer(tile);

        foreach (SerialisableTileBackground serialisableTileBackground in serialisableTile.TileBackgrounds)
        {
            Type type = Type.GetType(serialisableTileBackground.BackgroundType);

            if (type.Equals(typeof(SerialisableTilePathBackground)))
            {
                SerialisableTilePathBackground serialisableTilePathBackground = (SerialisableTilePathBackground)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type);
                tileBackgroundPlacer.PlacePath(new MazeLevelDefaultPathType(), new TileConnectionScoreInfo(serialisableTilePathBackground.TileConnectionScore));
            }
            else if (type.Equals(typeof(SerialisableTileBaseGround)))
            {
                SerialisableTileBaseGround serialisableTileBaseGround = (SerialisableTileBaseGround)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type);
                tileBackgroundPlacer.PlaceGround(new MazeLevelDefaultGroundType(), new TileConnectionScoreInfo(serialisableTileBaseGround.TileConnectionScore));
            }
            else if (type.Equals(typeof(SerialisableTileBaseWater)))
            {
                tileBackgroundPlacer.PlaceBackground <MazeTileBaseWater>();
            }
            else
            {
                Logger.Error($"Unknown TileBackgroundId {serialisableTileBackground.TileBackgroundId}");
            }
        }
    }
    private SerialisableTileBaseGround TryAddBaseBackgroundForNewOverworld(List <SerialisableTileBackground> tileBackgrounds, List <SerialisableTileAttribute> tileAttributes)
    {
        for (int i = 0; i < tileBackgrounds.Count; i++)
        {
            Type type = Type.GetType(tileBackgrounds[i].BackgroundType);
            if (type.Equals(typeof(SerialisableTilePathBackground)))
            {
                SerialisableTilePathBackground serialisableTilePathBackground = (SerialisableTilePathBackground)JsonUtility.FromJson(tileBackgrounds[i].SerialisedData, type);
                if (serialisableTilePathBackground.TileConnectionScore == 16)
                {
                    return(null);
                }
            }
        }

        SerialisableTileObstacleAttribute obstacleAttribute = tileAttributes.OfType <SerialisableTileObstacleAttribute>().FirstOrDefault();

        if (obstacleAttribute == null)
        {
            return(new SerialisableTileBaseGround(16));
        }

        if (obstacleAttribute.ConnectionScore == 16)
        {
            return(null);
        }

        return(new SerialisableTileBaseGround(16));
    }
Пример #3
0
    private ISerialisableTileBackground CreateSerialisableTileBackground(ITileBackground tileBackground)
    {
        if (tileBackground.GetType() == typeof(MazeTilePath) || tileBackground.GetType() == typeof(OverworldTilePath))
        {
            TilePath tilePath = tileBackground as TilePath;

            SerialisableTilePathBackground serialisableTilePathBackground = new SerialisableTilePathBackground(tilePath.ConnectionScore);
            return(serialisableTilePathBackground);
        }
        else if (tileBackground.GetType() == typeof(MazeTileBaseWater) || tileBackground.GetType() == typeof(OverworldTileBaseWater))
        {
            SerialisableTileBaseWater serialisableTileBaseWater = new SerialisableTileBaseWater();
            return(serialisableTileBaseWater);
        }
        else if (tileBackground.GetType() == typeof(MazeTileBaseGround) || (tileBackground.GetType() == typeof(OverworldTileBaseGround)))
        {
            TileBaseGround tileGround = tileBackground as TileBaseGround;

            SerialisableTileBaseGround serialisableTileBaseGround = new SerialisableTileBaseGround(tileGround.ConnectionScore);

            return(serialisableTileBaseGround);
        }
        else
        {
            Logger.Error($"Could not serialise the tile background {tileBackground.GetType()}");
            return(null);
        }
    }
Пример #4
0
    public void AddBackgroundSprites(SerialisableTile serialisableTile, EditorOverworldTile tile)
    {
        EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(tile);

        foreach (SerialisableTileBackground serialisableTileBackground in serialisableTile.TileBackgrounds)
        {
            Type type = Type.GetType(serialisableTileBackground.BackgroundType);

            if (type.Equals(typeof(SerialisableTilePathBackground)))
            {
                SerialisableTilePathBackground serialisableTilePathBackground = (SerialisableTilePathBackground)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type);
                tileBackgroundPlacer.PlacePath(new OverworldDefaultPathType(), new TileConnectionScoreInfo(serialisableTilePathBackground.TileConnectionScore));
            }
            else if (type.Equals(typeof(SerialisableTileBaseGround)))
            {
                SerialisableTileBaseGround serialisableTileBaseGround = (SerialisableTileBaseGround)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type);
                tileBackgroundPlacer.PlaceGround(new OverworldDefaultGroundType(), new TileConnectionScoreInfo(serialisableTileBaseGround.TileConnectionScore));
            }
            else if (type.Equals(typeof(SerialisableTileBaseWater)))
            {
                tileBackgroundPlacer.PlaceCoveringBaseWater();
                //tileBackgroundPlacer.PlaceBackground<OverworldTileBaseWater>();
            }
            else
            {
                Logger.Error($"Unknown TileBackgroundType {serialisableTileBackground.BackgroundType}");
            }
        }
    }
    public void GenerateTiles()
    {
        if (_gridWidth < 3)
        {
            Logger.Warning(Logger.Level, "Cannot generate a tile grid with a width of {0}. The minimum generatable grid width is 3", _gridWidth);
            return;
        }

        if (_gridWidth > 25)
        {
            Logger.Warning(Logger.Level, "Cannot generate a tile grid with a width of {0}. The maximum generatable grid width is 20", _gridWidth);
            return;
        }

        if (_gridHeight < 3)
        {
            Logger.Warning(Logger.Level, "Cannot generate a tile grid with a height of {0}. The minimum generatable grid height is 3", _gridHeight);
            return;
        }

        if (_gridHeight > 25)
        {
            Logger.Warning(Logger.Level, "Cannot generate a tile grid with a height of {0}. The maximum generatable grid height is 20", _gridHeight);
            return;
        }

        Logger.Log("Generate tile grid with a width of {0} and a height of {1}", _gridWidth, _gridHeight);

        // remove everything from the currently loaded level
        MazeLevelGameplayManager.Instance.UnloadLevel();

        // Create a new level from scratch with a obstacle ring at the edges
        List <SerialisableTile> tiles = new List <SerialisableTile>();

        for (int i = 0; i < _gridWidth; i++)
        {
            for (int j = 0; j < _gridHeight; j++)
            {
                string tileId = Guid.NewGuid().ToString();

                GridLocation gridLocation = new GridLocation(i, j);
                List <SerialisableTileAttribute>    tileAttributes    = new List <SerialisableTileAttribute>();
                List <SerialisableTileBackground>   tileBackgrounds   = new List <SerialisableTileBackground>();
                List <SerialisableTileCornerFiller> tileCornerFillers = new List <SerialisableTileCornerFiller>();

                SerialisableTileMainMaterial mainMaterial = new SerialisableTileMainMaterial("GroundMainMaterial", new SerialisableLandMaterial());

                SerialisableTileObstacleAttribute edgeObstacle = TryAddEdgeObstacle(gridLocation);

                if (edgeObstacle != null)
                {
                    tileAttributes.Add(new SerialisableTileAttribute(edgeObstacle.GetType().ToString(), edgeObstacle));
                }

                SerialisableTilePathBackground mazeTilePath = TryAddPathsForNewMaze(gridLocation, tileAttributes);

                if (mazeTilePath != null)
                {
                    tileBackgrounds.Add(new SerialisableTileBackground(mazeTilePath.GetType().ToString(), mazeTilePath));
                }

                SerialisableTileBaseGround baseBackground = TryAddBaseBackgroundForNewMaze(tileBackgrounds, tileAttributes);

                if (baseBackground != null)
                {
                    tileBackgrounds.Add(new SerialisableTileBackground(baseBackground.GetType().ToString(), baseBackground));
                }

                SerialisableTile tile = new SerialisableTile(tileId, mainMaterial, tileAttributes, tileBackgrounds, tileCornerFillers, gridLocation.X, gridLocation.Y);
                tiles.Add(tile);
            }
        }

        MazeLevelData newMazeLevelData = new MazeLevelData();

        newMazeLevelData.Tiles = tiles;

        MazeLevelLoader.LoadMazeLevelForEditor(newMazeLevelData);
    }