/// <summary>
    /// Editor method. Add a new preset.
    /// </summary>
    static void AddNewPreset(TileWorldConfiguration _config)
    {
        //blocks.Add(new TileSets());
        _config.presets.Add(new TileWorldConfiguration.PresetsConfiguration());

        ResizeStringArray(false, _config.presets.Count - 1, _config);
    }
    /// <summary>
    /// Editor method. Duplicate a preset
    /// </summary>
    /// <param name="_index"></param>
    static void DuplicatePreset(int _index, TileWorldConfiguration _config)
    {
        AddNewPreset(_config);

        if (_config.presets[_index].tiles.Count > 1)
        {
            for (int t1 = 0; t1 < _config.presets[_index].tiles.Count - 1; t1++)
            {
                _config.presets[_config.presets.Count - 1].tiles.Add(new TileWorldConfiguration.TileSets());
            }
        }


        for (int t2 = 0; t2 < _config.presets[_index].tiles.Count; t2++)
        {
            _config.presets[_config.presets.Count - 1].tiles[t2].tileI  = _config.presets[_index].tiles[t2].tileI;
            _config.presets[_config.presets.Count - 1].tiles[t2].tileC  = _config.presets[_index].tiles[t2].tileC;
            _config.presets[_config.presets.Count - 1].tiles[t2].tileCi = _config.presets[_index].tiles[t2].tileCi;
            _config.presets[_config.presets.Count - 1].tiles[t2].tileB  = _config.presets[_index].tiles[t2].tileB;
            _config.presets[_config.presets.Count - 1].tiles[t2].tileF  = _config.presets[_index].tiles[t2].tileF;

            _config.presets[_config.presets.Count - 1].tiles[t2].floorOffset = _config.presets[_index].tiles[t2].floorOffset;
            _config.presets[_config.presets.Count - 1].tiles[t2].blockOffset = _config.presets[_index].tiles[t2].blockOffset;

            _config.presets[_config.presets.Count - 1].tiles[t2].yRotationOffset = new float[_config.presets[_index].tiles[t2].yRotationOffset.Length];

            for (int f = 0; f < _config.presets[_index].tiles[t2].yRotationOffset.Length; f++)
            {
                _config.presets[_config.presets.Count - 1].tiles[t2].yRotationOffset[f] = _config.presets[_index].tiles[t2].yRotationOffset[f];
            }
        }
    }
    public bool[,] Generate(TileWorldConfiguration _config, out Vector3 _startPosition, out Vector3 _endPosition)
    {
        // Assign properties from config
        width  = _config.global.width;
        height = _config.global.height;

        linear            = _config.mazeAlgorithm.linear;
        useRandomStartPos = _config.mazeAlgorithm.useRandomStartPos;

        if (!_config.mazeAlgorithm.useRandomStartPos)
        {
            startPosition = new Vector3(_config.mazeAlgorithm.startPos.x, 0, _config.mazeAlgorithm.startPos.y);
        }

        mazeMap = new bool[width, height];
        mazeMap = GenerateMaze(height, width);

        _startPosition = startPosition;

        // Find end position after generation
        var _pos = FindEndPosition(mazeMap);

        _endPosition = new Vector3(_pos.x, 0, _pos.y);

        return(mazeMap);
    }
    // Implemented interface
    public bool[,] Generate(TileWorldConfiguration _config, out Vector3 _startPosition, out Vector3 _endPosition)
    {
        // Assign properties from config
        width  = _config.global.width;
        height = _config.global.height;

        createCircleRooms   = _config.simpleDungeonAlgorithm.createCircleRooms;
        minCircleRoomRadius = _config.simpleDungeonAlgorithm.minCircleRoomRadius;
        maxCircleRoomRadius = _config.simpleDungeonAlgorithm.maxCircleRoomRadius;

        roomCount              = _config.simpleDungeonAlgorithm.roomCount;
        minRoomSizeHeight      = _config.simpleDungeonAlgorithm.minRoomSizeHeight;
        minRoomSizeWidth       = _config.simpleDungeonAlgorithm.minRoomSizeWidth;
        maxRoomSizeHeight      = _config.simpleDungeonAlgorithm.maxRoomSizeHeight;
        maxRoomSizeWidth       = _config.simpleDungeonAlgorithm.maxRoomSizeWidth;
        allowRoomIntersections = _config.simpleDungeonAlgorithm.allowRoomIntersections;
        corridorWidth          = _config.simpleDungeonAlgorithm.minCorridorWidth;


        GenerateDungeonMap();

        _startPosition = startPosition;
        _endPosition   = endPosition;

        // return map
        return(dungeonMap);
    }
    static void ResizeStringArray(bool _remove, int _index, TileWorldConfiguration _config)
    {
        List <string> _tmpString = new List <string>();

        for (int i = 0; i < _config.ui.availablePresets.Length; i++)
        {
            _tmpString.Add(_config.ui.availablePresets[i]);
        }

        if (_remove)
        {
            _tmpString.RemoveAt(_index);

            _config.ui.availablePresets = new string[_tmpString.Count];

            for (int m = 0; m < _config.ui.availablePresets.Length; m++)
            {
                _config.ui.availablePresets[m] = _tmpString[m];
            }
        }
        else
        {
            _tmpString.Add("Preset: " + _config.ui.availablePresets.Length.ToString());


            _config.ui.availablePresets = new string[_tmpString.Count];
            for (int a = 0; a < _tmpString.Count; a++)
            {
                _config.ui.availablePresets[a] = "Preset: " + a;
            }
        }
    }
 /// <summary>
 /// Editor method. Delete preset
 /// </summary>
 /// <param name="_inx"></param>
 static void DeletePreset(int _inx, TileWorldConfiguration _config)
 {
     if (_inx != 0)
     {
         _config.presets.RemoveAt(_inx);
         ResizeStringArray(true, _inx, _config);
     }
 }
    public void OnEnable()
    {
        config = target as TileWorldConfiguration;

        //get all available algorithms by name
        TileWorldAlgorithmLookup.GetAlgorithmNames(out algorithmNames);

        LoadResources();
    }
    //Do Simulation steps
    //-------------------
    bool[,] DoSimulationStep(bool[,] oldMap, TileWorldConfiguration _config)
    {
        bool[,] newMap = new bool[_config.global.width, _config.global.height];

        //Loop over each row and column of the map
        for (int x = 0; x < oldMap.GetLength(0); x++)
        {
            for (int y = 0; y < oldMap.GetLength(1); y++)
            {
                int nbs = TileWorldNeighbourCounter.CountAllNeighbours(oldMap, x, y, 1, true);
                //The new value is based on our simulation rules
                //First, if a cell is alive but has too few neighbours, kill it.
                if (oldMap[x, y])
                {
                    if (nbs < _config.cellularAlgorithm.deathLimit)
                    {
                        newMap[x, y] = false;
                    }
                    else
                    {
                        newMap[x, y] = true;
                    }
                    //make sure the cavern is always closed on the border edges
                    if (_config.global.invert)
                    {
                        if (x < 1 || x >= _config.global.width - 1 || y >= _config.global.height - 1 || y < 1)
                        {
                            newMap[x, y] = true;
                        }
                    }
                }
                //Otherwise, if the cell is dead now, check if it has the right number of neighbours to be 'born'
                else
                {
                    if (nbs > _config.cellularAlgorithm.birthLimit)
                    {
                        newMap[x, y] = true;
                    }
                    else
                    {
                        newMap[x, y] = false;
                    }
                    //make sure the cavern is always closed on the border edges
                    if (_config.global.invert)
                    {
                        if (x < 1 || x >= _config.global.width - 1 || y >= _config.global.height - 1 || y < 1)
                        {
                            newMap[x, y] = true;
                        }
                    }
                }
            }
        }

        return(newMap);
    }
示例#9
0
    public bool[,] ApplyMask(bool[,] _map, TileWorldCreator _creator, TileWorldConfiguration _config)
    {
        //create a new temp map
        bool[,] _tmpMap = new bool[_map.GetLength(0), _map.GetLength(1)];
        //set the circle radius
        float _radius = 5;

        //loop through the maps x and y length
        for (int x = 0; x < _config.global.width; x++)
        {
            for (int y = 0; y < _config.global.height; y++)
            {
                //get center point of the map
                Vector2 _center = new Vector2(_config.global.width / 2, _config.global.height / 2);
                //current tile position
                Vector2 _currPos = new Vector2(x, y);
                //get distance from its current cell position to the center of the map
                float _dist = Vector2.Distance(_center, _currPos);

                //check if the current distance is not to far away from its radius
                //and set the appropriate values depending of if invert is set to false or true
                if (_dist <= _radius)
                {
                    if (!_config.global.invert)
                    {
                        _tmpMap[x, y] = false;
                    }
                    else
                    {
                        _tmpMap[x, y] = true;
                    }
                }
                else
                {
                    if (!_config.global.invert)
                    {
                        _tmpMap[x, y] = true;
                    }
                    else
                    {
                        _tmpMap[x, y] = false;
                    }
                }
            }
        }

        //return the map
        return(_tmpMap);
    }
示例#10
0
    public bool[,] ApplyMask(bool[,] _map, TileWorldCreator _creator, TileWorldConfiguration _config)
    {
        //create a temp map
        bool[,] _tmpMap = new bool[_map.GetLength(0), _map.GetLength(1)];

        //loop through the maps x and y length
        for (int y = 0; y < _map.GetLength(1); y++)
        {
            for (int x = 0; x < _map.GetLength(0); x++)
            {
                //here we are using the TileWorldNeighbourCounter to count
                //the neighbour cells of the current cell from the map.
                int _c = 0;
                _c = TileWorldNeighbourCounter.CountInnerTerrainBlocks(_map, x, y, 1, _config.global.invert);

                //if invert is set to false in the settings of TileWorldCreator
                if (!_config.global.invert)
                {
                    //if the current cell has got 8 neighbours
                    //then the cell is not located on the border of the island
                    if (_c == 8 || _map[x, y])
                    {
                        _tmpMap[x, y] = true;
                    }
                    //else we can be sure that the current cell is a border cell
                    else
                    {
                        _tmpMap[x, y] = false;
                    }
                }
                else
                {
                    //inverted tmpMap values when invert is set to true.
                    if (_c == 8)
                    {
                        _tmpMap[x, y] = false;
                    }
                    else
                    {
                        _tmpMap[x, y] = true;
                    }
                }
            }
        }

        //return the modified map
        return(_tmpMap);
    }
    public static void ShowConfigurationEditor(TileWorldConfiguration _config)
    {
        if (_config == null)
        {
            EditorGUILayout.HelpBox("Please create or load a configuration file.", MessageType.Info);
            return;
        }


        //Show global settings foldout
        ShowGlobalSettingsFoldout(_config);
        //Show preset settings foldout
        ShowPresetSettingsFoldout(_config);

        EditorUtility.SetDirty(_config);
    }
    static void ShowPresetSettingsFoldout(TileWorldConfiguration _config)
    {
        // Show preset settings
        GUI.color = colorGUIFoldout2;
        EditorGUILayout.BeginVertical("Box");
        GUI.color = Color.white;
        GUILayout.BeginHorizontal("Box");
        _config.ui.showPresetSettings = GUILayout.Toggle(_config.ui.showPresetSettings, ("Presets"), GUI.skin.GetStyle("foldout"), GUILayout.ExpandWidth(true), GUILayout.Height(18));

        if (GUILayout.Button(iconUndockWindow, "ToolbarButton", GUILayout.Width(25)))
        {
            TileWorldCreator _c = GameObject.FindObjectOfType <TileWorldCreator>();
            TileWorldCreatorEditorPresetsWindow.InitWindow(_c.gameObject);
        }

        GUILayout.EndHorizontal();

        if (_config.ui.showPresetSettings)
        {
            ShowPresetSettings(_config);
        }
        EditorGUILayout.EndVertical();
    }
    public static void ShowPresetSettings(TileWorldConfiguration _config)
    {
        GUILayout.BeginVertical("Box", GUILayout.ExpandWidth(false));


        if (GUILayout.Button("Add new preset"))
        {
            AddNewPreset(_config);
        }

        EditorGUILayout.BeginVertical("TextArea");


        for (int i = 0; i < _config.presets.Count; i++)
        //for (int i = 0; i < creator.blocks.Count; i ++)
        {
            GUI.color = guiBlue;
            GUILayout.BeginVertical("Box");
            GUI.color = Color.white;

            GUILayout.BeginHorizontal();

            _config.presets[i].showPresetEditor = GUILayout.Toggle(_config.presets[i].showPresetEditor, ("Preset: " + i), GUI.skin.GetStyle("foldout"), GUILayout.ExpandWidth(true), GUILayout.Height(18));

            //duplicate current preset
            if (GUILayout.Button(iconDuplicate, "ToolbarButton", GUILayout.Height(18), GUILayout.Width(25)))
            {
                DuplicatePreset(i, _config);
            }

            //delete current preset
            GUI.color = guiRed;
            if (i > 0)
            {
                if (GUILayout.Button("x", "ToolbarButton", GUILayout.Height(18), GUILayout.Width(25)))
                {
                    DeletePreset(i, _config);
                }
            }
            GUI.color = Color.white;

            GUILayout.EndHorizontal();

            if (i < _config.presets.Count)
            {
                if (_config.presets[i].showPresetEditor)
                {
                    GUILayout.BeginHorizontal();
                    //GUILayout.Label("");

                    if (GUILayout.Button("+ random tileset", GUILayout.Height(18), GUILayout.Width(120)))
                    {
                        AddNewTileSet(i, _config);
                    }

                    GUILayout.EndHorizontal();

                    //TILE SETS
                    //---------

                    for (int t = 0; t < _config.presets[i].tiles.Count; t++)
                    {
                        GUILayout.BeginVertical("TextArea");

                        //------------------------------------
                        GUILayout.BeginHorizontal("Box");

                        // Duplicate random tileset
                        if (GUILayout.Button(iconDuplicate, "MiniButton", GUILayout.Height(18), GUILayout.Width(20)))
                        {
                            DuplicateTileSet(i, t, _config);
                        }

                        GUI.color = guiRed;
                        if (t > 0)
                        {
                            if (GUILayout.Button("x", "MiniButton", GUILayout.Height(18), GUILayout.Width(20)))
                            {
                                DeleteTileSet(i, t, _config);
                            }
                        }
                        GUI.color = Color.white;

                        GUILayout.Label("Tileset: " + t);

                        GUILayout.EndHorizontal();
                        //--------------------------------------


                        DragDropArea(i, t, _config);


                        if (t < _config.presets[i].tiles.Count)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.BeginVertical();
                            GUILayout.Label(guiPresetImage1, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50));
                            _config.presets[i].tiles[t].tileI = EditorGUILayout.ObjectField(_config.presets[i].tiles[t].tileI, typeof(GameObject), false, GUILayout.MaxWidth(50)) as GameObject;
                            GUILayout.Label("yRotOff:");
                            _config.presets[i].tiles[t].yRotationOffset[0] = EditorGUILayout.FloatField("", _config.presets[i].tiles[t].yRotationOffset[0], GUILayout.Width(50));
                            GUILayout.EndVertical();
                            GUILayout.FlexibleSpace();
                            GUILayout.BeginVertical();
                            GUILayout.Label(guiPresetImage2, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50));
                            _config.presets[i].tiles[t].tileC = EditorGUILayout.ObjectField(_config.presets[i].tiles[t].tileC, typeof(GameObject), false, GUILayout.MaxWidth(50)) as GameObject;
                            GUILayout.Label("yRotOff:");
                            _config.presets[i].tiles[t].yRotationOffset[1] = EditorGUILayout.FloatField("", _config.presets[i].tiles[t].yRotationOffset[1], GUILayout.Width(50));
                            GUILayout.EndVertical();
                            GUILayout.FlexibleSpace();
                            GUILayout.BeginVertical();
                            GUILayout.Label(guiPresetImage3, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50));
                            _config.presets[i].tiles[t].tileCi = EditorGUILayout.ObjectField(_config.presets[i].tiles[t].tileCi, typeof(GameObject), false, GUILayout.MaxWidth(50)) as GameObject;
                            GUILayout.Label("yRotOff:");
                            _config.presets[i].tiles[t].yRotationOffset[2] = EditorGUILayout.FloatField("", _config.presets[i].tiles[t].yRotationOffset[2], GUILayout.Width(50));
                            GUILayout.EndVertical();
                            GUILayout.FlexibleSpace();
                            GUILayout.BeginVertical();
                            GUILayout.Label(guiPresetImage4, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50));
                            _config.presets[i].tiles[t].tileB = EditorGUILayout.ObjectField(_config.presets[i].tiles[t].tileB, typeof(GameObject), false, GUILayout.MaxWidth(50)) as GameObject;
                            GUILayout.Label("yRotOff:");
                            _config.presets[i].tiles[t].yRotationOffset[3] = EditorGUILayout.FloatField("", _config.presets[i].tiles[t].yRotationOffset[3], GUILayout.Width(50));
                            GUILayout.EndVertical();
                            GUILayout.FlexibleSpace();
                            GUILayout.BeginVertical();
                            GUILayout.Label(guiPresetImage5, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50));
                            _config.presets[i].tiles[t].tileF = EditorGUILayout.ObjectField(_config.presets[i].tiles[t].tileF, typeof(GameObject), false, GUILayout.MaxWidth(50)) as GameObject;
                            GUILayout.Label("yRotOff:");
                            _config.presets[i].tiles[t].yRotationOffset[4] = EditorGUILayout.FloatField("", _config.presets[i].tiles[t].yRotationOffset[4], GUILayout.Width(50));
                            GUILayout.EndVertical();
                            GUILayout.EndHorizontal();

                            GUILayout.Space(20);
                            _config.presets[i].tiles[t].blockOffset = EditorGUILayout.Vector3Field("block offset: ", _config.presets[i].tiles[t].blockOffset);
                            _config.presets[i].tiles[t].floorOffset = EditorGUILayout.Vector3Field("ground offset: ", _config.presets[i].tiles[t].floorOffset);
                        }

                        GUILayout.EndVertical();
                    }
                }
            }

            GUILayout.EndVertical();
        }
        GUILayout.EndVertical();


        GUILayout.EndVertical();
    }
    /// <summary>
    /// Implemented interface IAlgorithms
    /// </summary>
    public bool[,] Generate(TileWorldConfiguration _config, out Vector3 _startPosition, out Vector3 _endPosition)
    {
        //we do not set any start or end position for cellular map
        _startPosition = new Vector2(0, 0);
        _endPosition   = new Vector2(0, 0);

        //assign properties from config
        width              = _config.global.width;
        height             = _config.global.height;
        invert             = _config.global.invert;
        chanceToStartAlive = _config.cellularAlgorithm.chanceToStartAlive;

        cellularMap = new bool[width, height];

        cellularMap = initialiseMap(cellularMap);


        //run simulation step for number of steps
        //more steps results in smoother worlds
        for (int i = 0; i < _config.cellularAlgorithm.numberOfSteps; i++)
        {
            cellularMap = DoSimulationStep(cellularMap, _config);
        }

        // flood all smaller islands
        if (_config.cellularAlgorithm.floodUnjoined && (_config.global.width <= 150 || _config.global.height <= 150))
        {
            //count how many caverns our world has
            CountCaverns(cellularMap);

            cellularMap = FloodFill(cellularMap);
        }

        //flood holes floods all smaller holes inside of a map
        //Debug.Log(_config.cellularAlgorithm.floodHoles);
        if (_config.cellularAlgorithm.floodHoles && (_config.global.width <= 150 || _config.global.height <= 150))
        {
            CountWater(cellularMap);

            cellularMap = FloodFillWater(cellularMap);
        }


        // REMOVED DUE TO STACK OVERFLOW ISSUES
        //check if biggest island is big enough.
        //if not, regenerate map
        //bool _mapSizeOK = false;
        ////if (_config.global.randomSeed < 0)
        ////{
        //    if (islands.Count > 0)
        //    {
        //        for (int i = 0; i < islands.Count; i++)
        //        {
        //            if (islands[i].cellCount >= _config.cellularAlgorithm.minCellCount)
        //            {
        //                _mapSizeOK = true;
        //            }
        //        }
        //    }
        ////}

        //if (!_mapSizeOK)
        //{
        //    //Debug.Log("size to small");
        //    Generate(_config, out _startPosition, out _endPosition);
        //}

        return(cellularMap);
    }
示例#15
0
    public bool[,] Generate(TileWorldConfiguration _config, out Vector3 _startPosition, out Vector3 _endPosition)
    {
        _splitH = false;

        // assign values from config
        mapWidth    = _config.global.width;
        mapHeight   = _config.global.height;
        minHeight   = _config.bspDungeonAlgorithm.minBSPLeafHeight;
        minWidth    = _config.bspDungeonAlgorithm.minBSPLeafWidth;
        columnWidth = _config.bspDungeonAlgorithm.corridorWidth;

        dungeonMap = new bool[_config.global.width, _config.global.height];

        // Generate the BSP tree
        GenerateBSPTree();

        // assign rooms to map
        for (int r = 0; r < rooms.Count; r++)
        {
            for (int x = rooms[r].x; x < rooms[r].x + rooms[r].width; x++)
            {
                for (int y = rooms[r].y; y < rooms[r].y + rooms[r].height; y++)
                {
                    dungeonMap[x, y] = true;
                }
            }
        }

        // assign hallways to map
        for (int h = 0; h < hallways.Count; h++)
        {
            for (int x = hallways[h].x; x < hallways[h].x + hallways[h].width; x++)
            {
                for (int y = hallways[h].y; y < hallways[h].y + hallways[h].height; y++)
                {
                    dungeonMap[x, y] = true;
                }
            }
        }

        // clean up borders
        for (int x = 0; x < mapWidth; x++)
        {
            for (int y = 0; y < mapHeight; y++)
            {
                if (x == 0 || x == 1 || x == mapWidth - 1 || x == mapWidth - 2 || y == 0 || y == 1 || y == mapHeight - 1 || y == mapHeight - 2)
                {
                    dungeonMap[x, y] = false;
                }
            }
        }

        // assign start and end position
        // get random room as start position

        // use random start position
        //--------------------------------
        //var _rndStart = Random.Range(0, rooms.Count - 1);
        //_startPosition = new Vector3((rooms[_rndStart].width / 2) + rooms[_rndStart].x, 0, (rooms[_rndStart].height / 2) + rooms[_rndStart].y);
        //--------------------------------

        //use smallest room as start position
        //--------------------------------
        var _lastSquareSize = rooms[0].width * rooms[0].height;

        for (int r = 0; r < rooms.Count; r++)
        {
            var _squareSize = rooms[r].width * rooms[r].height;
            if (_squareSize < _lastSquareSize)
            {
                startPosition   = new Vector3((rooms[r].width / 2) + rooms[r].x, 0, (rooms[r].height / 2) + rooms[r].y);
                _lastSquareSize = _squareSize;
            }
        }
        //---------------------------------

        _startPosition = startPosition;

        // end position
        // instead of assigning the last room we will
        // get the room which is furthest away from the start position
        var _lastDistance = 0f;

        for (int r = 0; r < rooms.Count; r++)
        {
            var   _roomCenter = new Vector3((rooms[r].width / 2) + rooms[r].x, 0, (rooms[r].height / 2) + rooms[r].y);
            float _dist       = Vector3.Distance(_startPosition, _roomCenter);
            if (_dist > _lastDistance)
            {
                endPosition   = _roomCenter;
                _lastDistance = _dist;
            }
        }

        _endPosition = endPosition;

        return(dungeonMap);
    }
 /// <summary>
 /// Editor method. Duplicate tileset
 /// </summary>
 /// <param name="_presetIndex"></param>
 /// <param name="_tileIndex"></param>
 /// <param name="_config"></param>
 static void DuplicateTileSet(int _presetIndex, int _tileIndex, TileWorldConfiguration _config)
 {
     _config.presets[_presetIndex].tiles.Add(new TileWorldConfiguration.TileSets(_config.presets[_presetIndex].tiles[_tileIndex]));
 }
 /// <summary>
 /// Editor method. Delete tileset
 /// </summary>
 /// <param name="_presetIndex"></param>
 /// <param name="_tileIndex"></param>
 static void DeleteTileSet(int _presetIndex, int _tileIndex, TileWorldConfiguration _config)
 {
     _config.presets[_presetIndex].tiles.RemoveAt(_tileIndex);
 }
 /// <summary>
 /// Editor method. Add a new tileset to the given preset index
 /// </summary>
 /// <param name="_index"></param>
 static void AddNewTileSet(int _index, TileWorldConfiguration _config)
 {
     _config.presets[_index].tiles.Add(new TileWorldConfiguration.TileSets());
 }
    public bool[,] ApplyMask(bool[,] _map, TileWorldCreator _creator, TileWorldConfiguration _config)
    {
        bool[,] _tmpMap = new bool[_map.GetLength(0), _map.GetLength(1)];

        //get inner terrain cells
        for (int y = 0; y < _map.GetLength(1); y++)
        {
            for (int x = 0; x < _map.GetLength(0); x++)
            {
                int _c = 0;
                _c = TileWorldNeighbourCounter.CountInnerTerrainBlocks(_map, x, y, 1, _config.global.invert);

                if (!_config.global.invert)
                {
                    if (_c == 8)
                    {
                        _tmpMap[x, y] = false;
                    }
                    else
                    {
                        _tmpMap[x, y] = true;
                    }
                }
                else
                {
                    if (_c == 8)
                    {
                        _tmpMap[x, y] = true;
                    }
                    else
                    {
                        _tmpMap[x, y] = false;
                    }
                }
            }
        }

        //get random cells from inner terrain map
        bool[,] _newMap = new bool[_config.global.width, _config.global.height];
        for (int y = 0; y < _map.GetLength(1); y++)
        {
            for (int x = 0; x < _map.GetLength(0); x++)
            {
                float _rnd = Random.Range(0f, 1f);

                if (!_config.global.invert)
                {
                    //invert map if invert ist set to false
                    _newMap[x, y] = true;
                }


                if (_rnd < 0.3f)
                {
                    if (_config.global.invert)
                    {
                        if (_tmpMap[x, y])
                        {
                            _newMap[x, y] = true;
                        }
                    }
                    else
                    {
                        if (!_tmpMap[x, y])
                        {
                            _newMap[x, y] = false;
                        }
                    }
                }
            }
        }

        return(_newMap);
    }
    static void DragDropArea(int _i, int _t, TileWorldConfiguration _config)
    {
        Event evt       = Event.current;
        Rect  drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));

        GUI.Box(drop_area, "Drag and drop tile prefabs here for automatic assignment" + "\n (alphabetical order = tile assignment from left to right)");

        switch (evt.type)
        {
        case EventType.DragUpdated:
        case EventType.DragPerform:
            if (!drop_area.Contains(evt.mousePosition))
            {
                return;
            }

            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

            if (evt.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();

                var           a        = 0;
                Object[]      _obj     = DragAndDrop.objectReferences;
                List <Object> _objList = new List <Object>();
                for (int o = 0; o < _obj.Length; o++)
                {
                    _objList.Add(_obj[o]);
                }

                _objList.Sort(CompareByName);

                for (int i = 0; i < _objList.Count; i++)
                {
                    if (a == 0)
                    {
                        _config.presets[_i].tiles[_t].tileI = _objList[i] as GameObject;
                    }
                    else if (a == 1)
                    {
                        _config.presets[_i].tiles[_t].tileC = _objList[i] as GameObject;
                    }
                    else if (a == 2)
                    {
                        _config.presets[_i].tiles[_t].tileCi = _objList[i] as GameObject;
                    }
                    else if (a == 3)
                    {
                        _config.presets[_i].tiles[_t].tileB = _objList[i] as GameObject;
                    }
                    else if (a >= 4)
                    {
                        _config.presets[_i].tiles[_t].tileF = _objList[i] as GameObject;
                    }

                    a++;
                }
            }
            break;
        }
    }
    public static void ShowGlobalSettings(TileWorldConfiguration _config)
    {
        var _editor = Editor.CreateEditor(_config);

        GUILayout.BeginVertical("Box");
        _config.global.worldName = EditorGUILayout.TextField("Name:", _config.global.worldName);
        _config.global.invert    = EditorGUILayout.Toggle("Invert:", _config.global.invert);
        //_config.global.floodUnjoined = EditorGUILayout.Toggle("Flood unjoined:", _config.global.floodUnjoined);
        //_config.global.floodHoles = EditorGUILayout.Toggle("Flood holes:", _config.global.floodHoles);
        _config.global.buildGroundTiles = EditorGUILayout.Toggle("Build ground tiles:", _config.global.buildGroundTiles);
        _config.global.mapOrientation   = (TileWorldConfiguration.GlobalConfiguration.MapOrientations)EditorGUILayout.EnumPopup("Map orientation: ", _config.global.mapOrientation);
        GUILayout.EndVertical();


        GUILayout.BeginVertical("Box");
        _config.global.layerCount = EditorGUILayout.IntField("Number of layers:", _config.global.layerCount);
        _config.global.layerInset = EditorGUILayout.IntField("Layer inset:", _config.global.layerInset);

        if (_config.global.layerCount > 1)
        {
            _config.global.buildOverlappingTiles = EditorGUILayout.Toggle("Build overlapping tiles", _config.global.buildOverlappingTiles);
        }
        GUILayout.EndVertical();


        GUILayout.BeginVertical("Box");
        _config.global.width       = EditorGUILayout.IntField("Grid width:", _config.global.width);
        _config.global.height      = EditorGUILayout.IntField("Grid height:", _config.global.height);
        _config.global.globalScale = EditorGUILayout.Slider("Scale:", _config.global.globalScale, 1, 100);
        _config.global.scaleTiles  = EditorGUILayout.Toggle("Scale tiles:", _config.global.scaleTiles);
        GUILayout.EndVertical();

        //SELECT MAP ALGORITHM
        GUILayout.BeginVertical("Box");

        GUILayout.BeginHorizontal();
        GUILayout.Label("Selected algorithm: ");
        _config.global.selectedAlgorithm = EditorGUILayout.Popup(_config.global.selectedAlgorithm, algorithmNames);

        // change properties based on algorithms to make sure the algorithm works properly
        if (algorithmNames[_config.global.selectedAlgorithm] == "MazeAlgorithm")
        {
            _config.global.invert = false;
        }

        GUILayout.EndHorizontal();

        if (algorithmNames[_config.global.selectedAlgorithm] == "CellularAlgorithm")
        {
            if (_config.cellularAlgorithm.minCellCount >= (_config.global.width * _config.global.height) * 0.5f)
            {
                EditorGUILayout.HelpBox("Minimum cell count size can only be max 50% of the width * height size of the map." + "\n" +
                                        "Try to set a lower minimum cell count", MessageType.Warning);
                _config.cellularAlgorithm.minCellCount = (_config.global.width * _config.global.height) / 2;
            }
        }

        //draw default algorithm attributes
        EditorGUI.indentLevel = 1;
        _editor.DrawDefaultInspector();
        EditorGUI.indentLevel = 0;

        EditorGUILayout.BeginVertical("Box");
        _config.global.randomSeed = EditorGUILayout.IntField("Random seed:", _config.global.randomSeed);


        //_config.global.minSize = EditorGUILayout.IntField("Minimum size:", _config.global.minSize);



        EditorGUILayout.EndVertical();

        GUILayout.EndVertical();


        GUILayout.BeginVertical("Box");
        GUILayout.Label("Merge settings:");

        EditorGUILayout.HelpBox("Cluster size defines the square size in tiles of a cluster." + "\n" +
                                "Please note that when merging the map, TileWorldCreator tries to merge all tiles inside of each cluster. If the result exceeds the max allowed vertex count an error occurs - Try the Automatic setting instead.", MessageType.Info);

        EditorGUILayout.BeginVertical("Box");
        EditorGUILayout.LabelField("Cluster Size:");

        _config.global.automaticClustersize = EditorGUILayout.Toggle("Automatic:", _config.global.automaticClustersize);

        GUI.enabled = !_config.global.automaticClustersize;
        _config.global.clusterSize = EditorGUILayout.IntField("Size:", _config.global.clusterSize);
        GUI.enabled = true;

        EditorGUILayout.EndVertical();
        _config.global.createMultiMaterialMesh = EditorGUILayout.Toggle("Multi material mesh: ", _config.global.createMultiMaterialMesh);
        _config.global.addMeshCollider         = EditorGUILayout.Toggle("Add mesh collider: ", _config.global.addMeshCollider);
        GUILayout.EndVertical();
    }