コード例 #1
0
    public void LoadFromFile(string path)
    {
        Reset();
        if (!File.Exists(path))           //arquivo nem existe!
        {
            Debug.Log("Mapa não existe!");
            return;
        }

        string[] tiles = File.ReadAllLines(path);

        for (int i = 0; i < tiles.Length; i++)
        {
            GameObject obj = new GameObject();
            obj.transform.parent = this.transform;
            float x, y;
            float.TryParse(tiles[i].Split(' ')[0], out x);
            float.TryParse(tiles[i].Split(' ')[1], out y);
            obj.transform.localPosition = new Vector2(x, y);            //y invertido pro (0, 0) ficar no topo
            obj.name = "tile(" + x.ToString("0") + " " + (-y).ToString("0") + ")";

            TilemapTile newTile = obj.AddComponent <TilemapTile>();
            newTile.manager = this;
            int type = 0;
            int.TryParse(tiles[i].Split(' ')[2], out type);
            newTile.SetTileType(type);
        }
    }
コード例 #2
0
    public TilemapTile CreateTile(int x, int y)
    {
        GameObject obj = new GameObject("tile(" + x + " " + y + ")");

        obj.transform.parent        = this.transform;
        obj.transform.localPosition = new Vector2((float)x * tileSize.x, (float)y * tileSize.y);        //y invertido pro (0, 0) ficar no topo

        TilemapTile newTile = obj.AddComponent <TilemapTile>();

        newTile.manager = this;
        newTile.SetTileType(0);

        return(newTile);
    }
コード例 #3
0
    public void SaveToFile(string path)
    {
        List <string> tiles = new List <string>();

        for (int i = 0; i < transform.childCount; i++)
        {
            TilemapTile tile = transform.GetChild(i).GetComponent <TilemapTile>();
            if (tile == null)           //pula pois tile é nulo
            {
                continue;
            }
            tiles.Add(tile.transform.localPosition.x.ToString("0.00") + " "
                      + tile.transform.localPosition.y.ToString("0.00") + " "
                      + tile.myTypeIndex.ToString("0"));
        }
        var dirPath = path.Substring(0, path.Length - path.Split('/')[path.Split('/').Length - 1].Length);

        if (!Directory.Exists(dirPath))
        {
            Directory.CreateDirectory(dirPath);
        }
        File.WriteAllLines(path, tiles.ToArray());
    }
コード例 #4
0
    public override void OnInspectorGUI()
    {
        TilemapTile[] myScripts = new TilemapTile[targets.Length];
        for (int i = 0; i < myScripts.Length; i++)
        {
            myScripts[i] = targets[i] as TilemapTile;
        }

        string[] ops = new string[myScripts[0].manager.tiles.Length];
        for (int i = 0; i < ops.Length; i++)
        {
            ops[i] = myScripts[0].manager.tiles[i].name;
        }

        desejo = EditorGUILayout.Popup(desejo, ops);
        if (GUILayout.Button("Aplicar"))
        {
            SceneView.RepaintAll();
            for (int i = 0; i < myScripts.Length; i++)
            {
                myScripts[i].SetTileType(desejo);
            }
        }
    }