/// <summary>
        /// Take the supplied data and transform to the required array format required by the builder
        /// CSV file data should be comma separated for each map cell and a newline for each row, e.g.
        ///     1,1,2,3
        ///     4,2,1,3
        ///
        ///  CSV string data supplied should be comma separated as CSV file but each row separated by pipe ('|')
        ///  The map may be 0 or 1 indexed for the first item so ensure the start index value is set
        /// </summary>
        /// <param name="csvData">Tilemap data in string format. More for debugging but may be useful.</param>
        /// <param name="csvFile">Tilemap data as a file</param>
        /// <returns></returns>
        private static int[,] GetInputData(TileMapBuilder tb, string csvData, string csvFile)
        {
            string[] rowData;
            if (csvData == null && csvFile == null)
            {
                return(null);
            }
            if (csvData != null)
            {
                rowData = csvData.Split('|');
            }
            else if (csvFile != null)
            {
                rowData = File.ReadAllLines(csvFile);
            }
            else
            {
                return(null);
            }

            int[,] data;
            try
            {
                data = tb.TransformInputData(rowData);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(data);
        }
示例#2
0
    private void Awake()
    {
        tileMapBuilder = GetComponentInChildren <TileMapBuilder>();
        tilemapReader  = GetComponentInChildren <TilemapReader>();
        pathfinding    = GetComponentInChildren <Pathfinding>();
        levelManager   = GetComponent <LevelManager>();

        ProjectileHolder = this.transform.Find("Projectile");

        tileMapBuilder.SetUp();
    }
示例#3
0
    private static void Json2Map()
    {
        GameObject  map         = GameObject.FindGameObjectWithTag("Map");
        MetaTileMap metaTileMap = map.GetComponentInChildren <MetaTileMap>();

        metaTileMap.ClearAllTiles();

        TilemapConverter converter = new TilemapConverter();

        TileMapBuilder builder = new TileMapBuilder(metaTileMap, true);

        Dictionary <string, TilemapLayer> layers = DeserializeJson();

        List <Tuple <Vector3Int, ObjectTile> > objects = new List <Tuple <Vector3Int, ObjectTile> >();

        foreach (KeyValuePair <string, TilemapLayer> layer in layers)
        {
            List <Vector3Int> positions =
                layer.Value.TilePositions.ConvertAll(coord => new Vector3Int(coord.X, coord.Y, 0));

            for (int i = 0; i < positions.Count; i++)
            {
                Vector3Int  position = positions[i];
                GenericTile tile     = converter.DataToTile(layer.Value.Tiles[i]);

                if (tile is ObjectTile)
                {
                    if (!objects.Exists(t => t.Item1.Equals(position) && t.Item2 == tile))
                    {
                        objects.Add(new Tuple <Vector3Int, ObjectTile>(position, (ObjectTile)tile));
                    }
                }
                else
                {
                    builder.PlaceTile(position, tile);
                }
            }
        }

        foreach (Tuple <Vector3Int, ObjectTile> tuple in objects)
        {
            Vector3Int position = tuple.Item1;
            ObjectTile obj      = tuple.Item2;

            Matrix4x4 matrix = obj.Rotatable ? FindObjectPosition(metaTileMap, ref position, obj) : Matrix4x4.identity;

            builder.PlaceTile(position, obj, matrix);
        }

        // mark as dirty, otherwise the scene can't be saved.
        EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
        Logger.Log("Import kinda finished");
    }
示例#4
0
    public void SetUp(TilemapReader tilemapReader, TileMapBuilder tileMapBuilder)
    {
        _tilemapReader = tilemapReader;
        waveIndex      = -1;
        total_aiUnit   = new List <AIUnit>();

        player.SetUp(tileMapBuilder, projectileHolder, tileMapBuilder.bspMap.startRoom.spaceRect.center);
        enemyHolder = transform.Find("Unit/EnemyHolder");

        PreparePoolingObject(themeObject);

        player.OnChangeRoom += OnPlayerEnterRoom;
    }
        private void GenerateSceneFile()
        {
            string[]       rowData;
            TileMapBuilder tb = new TileMapBuilder();

            if (CSVString.Text.Trim() != "")
            {
                rowData = CSVString.Text.Trim().Split('|');
            }
            else if (CSVImport.Text.Trim() != "")
            {
                rowData = File.ReadAllLines(CSVImport.Text.Trim());
            }
            else
            {
                rowData = null;
            }

            try
            {
                tb.SetMapData(tb.TransformInputData(rowData));
            }
            catch (Exception e)
            {
                MessageBox.Show($"Failed: {e.Message}");
            }

            string sceneFile = tb
                               .SetCellSizePixels(uint.Parse(CellWidth.Text), uint.Parse(CellHeight.Text))
                               .SetTileSheetSizeUnits(uint.Parse(UnitWidth.Text), uint.Parse(UnitHeight.Text))
                               .SetTileSheetStartIndex(uint.Parse(StartCellIndex.Text))
                               .SetTileSheet(ImportSheet.Text)
                               .SetFormat(int.Parse(InternalFormat.Text))
                               .SetLoadSteps(int.Parse(InternalSteps.Text))
                               .SetNodeType(InternalMapClass.Text)
                               .SetTileSetType(InternalTileClass.Text)
                               .SetGodotTileWidth(uint.Parse(InternalMapWidth.Text))
                               .SetMapDataEmptyCellIndex(int.Parse(MapIgnoreCell.Text))
                               .SetNodeName(NodeName.Text)
                               .Build();

            try
            {
                File.WriteAllText(OutFile.Text, sceneFile);
                MessageBox.Show($"File written to:\n {OutFile.Text}");
            }
            catch (Exception e)
            {
                MessageBox.Show($"Failed to write output file: {OutFile.Text}\n\n{e.Message}");
            }
        }
示例#6
0
    public void SetUp(TileMapBuilder tilemapBuilder, Transform p_projectileHolder, Vector3 startPosition)
    {
        this.tilemapBuilder = tilemapBuilder;
        projectileHolder    = p_projectileHolder;

        this.unitSprite      = GetComponent <SpriteRenderer>();
        this.spriteBoundSize = this.unitSprite.bounds.size;

        if (weaponSprite != null)
        {
            weaponAnim      = weaponSprite.GetComponentInChildren <Animator>();
            swordInteractor = weaponSprite.GetComponentInChildren <SwordInteractor>();
            swordInteractor.SetUp(this, ReverseBullet);
        }

        this.transform.position = startPosition;

        base.Init();
    }
        /// <summary>
        /// Sample command line program to use the tilemap builder
        /// Will take various input values and create a scene file for a tileset and tilemap.
        /// If no parameters are supplied, help with be shown.
        ///
        /// Usage:
        /// <code>TileMapConsole -out myfile.tscn -ir spritesheet.png -cw 10 -ch 10</code>
        /// </summary>
        /// <param name="args">Refer to DisplayHelp</param>
        static void Main(string[] args)
        {
            Header();

            try
            {
                string sceneFormat    = GetArgument(args, "-sf");
                string loadSteps      = GetArgument(args, "-ls");
                string nodeType       = GetArgument(args, "-nt");
                string setType        = GetArgument(args, "-st");
                string cellIndex      = GetArgument(args, "-ci");
                string nodeName       = GetArgument(args, "-nn");
                string cellWidth      = GetArgument(args, "-cw");
                string cellHeight     = GetArgument(args, "-ch");
                string imageWidth     = GetArgument(args, "-iw");
                string imageHeight    = GetArgument(args, "-ih");
                string imageFile      = GetArgument(args, "-ir");
                string godotWidth     = GetArgument(args, "-gw");
                string mapIgnoreIndex = GetArgument(args, "-ms");
                string csvData        = GetArgument(args, "-csd");
                string csvFile        = GetArgument(args, "-csv");
                string outFile        = GetArgument(args, "-out");

                if (outFile == null || ((csvData != null && csvFile != null)))
                {
                    throw new Exception("An output file and either CSV data or a CSV file must be supplied, as follows");
                }

                TileMapBuilder tb = new TileMapBuilder();

                if (sceneFormat != null)
                {
                    tb.SetFormat(Convert.ToInt32(sceneFormat));
                }
                if (loadSteps != null)
                {
                    tb.SetLoadSteps(Convert.ToInt32(loadSteps));
                }
                if (nodeType != null)
                {
                    tb.SetNodeType(nodeType);
                }
                if (setType != null)
                {
                    tb.SetTileSetType(setType);
                }
                if (nodeName != null)
                {
                    tb.SetNodeName(nodeName);
                }
                if (cellIndex != null)
                {
                    tb.SetTileSheetStartIndex(Convert.ToUInt32(cellIndex));
                }
                if (cellHeight != null || cellWidth != null)
                {
                    //will error if either not supplied
                    tb.SetCellSizePixels(Convert.ToUInt32(cellWidth), Convert.ToUInt32(cellHeight));
                }
                if (imageWidth != null | imageHeight != null)
                {
                    tb.SetTileSheetSizeUnits(Convert.ToUInt32(imageWidth), Convert.ToUInt32(imageHeight));
                }
                if (imageFile != null)
                {
                    tb.SetTileSheet(imageFile);
                }
                if (godotWidth != null)
                {
                    tb.SetGodotTileWidth(Convert.ToUInt32(godotWidth));
                }
                if (mapIgnoreIndex != null)
                {
                    tb.SetMapDataEmptyCellIndex(Convert.ToInt32(mapIgnoreIndex));
                }

                try
                {
                    int[,] data = GetInputData(tb, csvData, csvFile);
                    tb.SetMapData(data);

                    string sceneFile = tb.Build();
                    Console.WriteLine(sceneFile);
                    File.WriteAllText(outFile, sceneFile);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Failed: {e.Message}");
                }
                //Console.ReadKey();
                Console.WriteLine($"Success. Scene file written to {outFile}");
            }
            catch (Exception e)
            {
                DisplayHelp(e.Message);
            }
        }