public void SaveMapData(string name)
        {
            if (!MapDataManager.Save(_data, name))
            {
                return;
            }

            savePopup.Hide();
            interactable = true;
        }
Пример #2
0
        public virtual void LoadMapData(FileInfo fileInfo)
        {
            var mapData = MapDataManager.Load(fileInfo);

            if (mapData is null)
            {
                Debug.LogError("Error loading map!");
                return;
            }

            _data = mapData;
            tilemap.ClearAllTiles();
            foreach (var collider in _destinationColliders)
            {
                collider.SetActive(false);
            }
            destinations.Clear();
            foreach (var collider in _trapColliders)
            {
                collider.SetActive(false);
            }
            traps.Clear();
            startingPoint         = Vector3Int.zero;
            isStartingPointExists = false;

            foreach (var key in _data.Keys)
            {
                var position = new Vector3Int(key.x, key.y, 0);
                var tile     = tiles.FirstOrDefault(t => t.tileType == _data[key]);
                tilemap.SetTile(position, tile.tile);

                if (tile.tileType == TileType.StartingPoint)
                {
                    OnStartingPointTileAdded(position);
                }
                else if (tile.tileType == TileType.Destination)
                {
                    OnDestinationTileAdded(position);
                }
                else if (tile.tileType == TileType.Trap)
                {
                    OnTrapAdded(position);
                }
            }

            interactable = true;
        }