Example #1
0
 public void AddTile(EditorTile tile)
 {
     if (!_tiles.Contains(tile))
     {
         _tiles.Add(tile);
     }
 }
Example #2
0
        public void LoadTiles(int width, int height)
        {
            this.Width  = width;
            this.Height = height;
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    EditorTile tile = new EditorTile("ocean1", new Vector2(i * 50, j * 50), blockChooser.Find("ocean1").Sprite.Texture, TileType.Block);
                    this.AddTile(tile);
                }
            }


            EditorManager.currentTile = new Tile(grassButton.Name, Vector2.Zero, grassButton.normalTexture, TileType.Normal);
        }
Example #3
0
        private GameObject InstantiateTile(TileCreator.TileTypes type, int x, int y, float xOffset = 0f, float yOffset = 0f)
        {
            GameObject floor   = GameObject.Find($"Floor {_selectedFloor.ToString()}");
            GameObject tile    = Instantiate(boardTile, floor.transform, true);
            Vector3    tilePos = tile.transform.position;

            tile.transform.position = new Vector3(tilePos.x + xOffset, tilePos.y + yOffset, -_selectedFloor);

            EditorTile editorTile = tile.GetComponent <EditorTile>();

            editorTile.GridEditor = _gridEditor;
            // Made on purpose
            editorTile.x     = y;
            editorTile.y     = x;
            editorTile.floor = _selectedFloor;
            editorTile.type  = type;
            editorTile.SetName();

            Selection.activeGameObject = tile;

            return(tile);
        }
Example #4
0
        public void ImportLevel(string path)
        {
            string[]         splitPath = Regex.Split(path, @"/Resources/")[1].Split('.');
            TextAsset        levelJson = Resources.Load <TextAsset>(splitPath[0]);
            LevelData        levelData = JsonUtility.FromJson <LevelData>(levelJson.text);
            List <LevelInfo> levelInfo = levelData.data;

            _boardInfo.GetBoardSpecs(levelInfo, out int tc);
            _gridEditor.Width  = (int)_boardInfo.BoardSize.x;
            _gridEditor.Height = (int)_boardInfo.BoardSize.y;
            _gridEditor.CreateGrid();

            for (int i = 0; i < levelInfo.Count; i++)
            {
                int f = levelInfo[i].floor;
                _floorEditor.AddNewFloor();
                List <LevelTiles> levelTiles = levelInfo[i].rows;
                for (int j = 0; j < levelTiles.Count; j++)
                {
                    List <int> tiles = levelTiles[j].tiles;
                    for (int k = 0; k < tiles.Count; k++)
                    {
                        TileCreator.TileTypes type = (TileCreator.TileTypes)tiles[k];
                        if (type == TileCreator.TileTypes.Empty ||
                            type == TileCreator.TileTypes.DummyH ||
                            type == TileCreator.TileTypes.DummyV)
                        {
                            continue;
                        }
                        GameObject tile       = _tileEditor.CreateTile(type, f, k, j);
                        EditorTile editorTile = tile.GetComponent <EditorTile>();
                        _boardEditor.AddTile(editorTile);
                    }
                }
            }
        }
Example #5
0
 public void RemoveTile(EditorTile tile)
 {
     _tiles.Remove(tile);
     DestroyImmediate(tile.gameObject);
 }
Example #6
0
		public TileValidator(int[,,] tiles, EditorTile et)
		{
			_tiles = tiles;
			_et = et;
		}
Example #7
0
        void Load(string filename)
        {
            // load the map
            Map map = Map.LoadFromFile(filename);

            this.parent.LoadTiles(map.Width, map.Height);

            this.parent.ClearTiles(); // clear the parent tiles

            foreach (Tile tile in map.Tiles)
            {
                EditorTile newTile = new EditorTile("", Vector2.Zero, EditorManager.defaultTile, TileType.Empty);
                // handle normal tiles
                if (tile.TileType == TileType.Normal)
                {
                    newTile = new EditorTile(tile.Name, tile.Transform.Position, AssetLoader.LoadTexture("Textures/" + tile.Name + ".png"), tile.TileType);
                }
                else if (tile.TileType == TileType.Block)
                {
                    newTile = new EditorTile(tile.Name, tile.Transform.Position, AssetLoader.LoadTexture("Textures/blocks/" + tile.Name + ".png"), tile.TileType);
                }
                else if (tile.TileType == TileType.Door)
                {
                    newTile = new EditorTile(tile.Name, tile.Transform.Position, AssetLoader.LoadTexture("Textures/doors/" + tile.Name + ".png"), tile.TileType);
                }

                // set depth
                newTile.Depth = tile.Depth;
                // set data
                newTile.Data = tile.Data;

                // get rotation
                newTile.Transform.Rotation = tile.Transform.Rotation;

                // add the new tile
                if (newTile.Name != "")
                {
                    this.parent.AddTile(newTile);
                }
            }

            foreach (MapMarker marker in map.Markers)
            {
                // try and find the tile owner
                var tileOwner = this.parent.tiles.Find(x => x.Transform.Position == marker.StartingPosition) as EditorTile;

                if (tileOwner != null)
                {
                    // find the type of tile and load the map marker
                    if (marker.MarkerType == MarkerType.PlayerSpawnPoint)
                    {
                        tileOwner.SetMarker(new MapMarker(marker.Name, tileOwner.StartingPosition, AssetLoader.LoadTexture("textures/objects/" + marker.Name + ".png"), marker.MarkerType));
                    }
                    else if (marker.MarkerType == MarkerType.SpawnPoint)
                    {
                        tileOwner.SetMarker(new MapMarker(marker.Name, tileOwner.StartingPosition, AssetLoader.LoadTexture("textures/monsters/" + marker.Name + ".png"), marker.MarkerType));
                    }
                    else if (marker.MarkerType == MarkerType.NPCSpawnPoint)
                    {
                        tileOwner.SetMarker(new MapMarker(marker.Name, tileOwner.StartingPosition, AssetLoader.LoadTexture("textures/npcs/" + marker.Name + ".png"), marker.MarkerType));
                    }
                    else if (marker.MarkerType == MarkerType.LightSource)
                    {
                        tileOwner.SetMarker(new MapMarker(marker.Name, tileOwner.StartingPosition, AssetLoader.LoadTexture("textures/lights/" + marker.Name + ".png"), marker.MarkerType));
                    }
                }
            }
        }