Esempio n. 1
0
    private void Awake()
    {
        // Find the tilemap game object and cache the behaviour.
        m_tileMap = GameObject.Find("TileMap").GetComponent <TileMapBehaviour>();
        if (m_tileMap == null)
        {
            Debug.LogError("TileMapBehaviour not found");
            return;
        }

        // Rather than hardcode the resolution of a tile, use the size of the first sprite.
        var tileSheet = m_tileMap.TileSheet;

        if (tileSheet.Count == 0)
        {
            Debug.LogError("Add some sprites before running the game");
            return;
        }
        var spriteSize = tileSheet.Get(0).rect;

        // Define and apply the settings for the tilemap.
        var settings = new TileMeshSettings(SizeX, SizeY, (int)spriteSize.width);

        m_tileMap.MeshSettings = settings;

        // Map type of tile to sprite
        m_tiles = new TileEnumMapper <TileType>(m_tileMap);
        m_tiles.Map(TileType.Wall, "Wall2");
        m_tiles.Map(TileType.Floor, "Floor");
        m_tiles.Map(TileType.StairsUp, "StairsUp");
        m_tiles.Map(TileType.StairsDown, "StairsDown");
    }
    private void Start()
    {
        m_cam              = GameObject.FindGameObjectWithTag("MapEditorCamera").GetComponent <Camera>();
        m_tileMapGrid      = FindObjectOfType <TileMapGrid>();
        m_tileMap          = FindObjectOfType <TileMapBehaviour>();
        m_tileSheet        = m_tileMap.TileSheet;
        m_tempTexture      = new Texture2D(64, 64);
        m_tileSheetIds     = m_tileSheet.Ids.ToArray();
        m_tileMeshSettings = m_tileMap.MeshSettings;

        m_tileMap.GetComponentInChildren <TileMeshBehaviour>().transform.localPosition = Vector3.zero;

        RefreshTiles();

        StartCoroutine(IUpdateMouseHit());

        // FormatMap();
    }
Esempio n. 3
0
    private void Start()
    {
        // Size of dungeon.
        int sizeX = 20;
        int sizeY = 8;

        // Rather than hardcode the resolution of a tile, use the size of the first sprite.
        var tileSheet  = m_tileMap.TileSheet;
        var spriteSize = tileSheet.Get(0).rect;

        // Define and apply the settings for the tilemap.
        var settings = new TileMeshSettings(sizeX, sizeY, (int)spriteSize.width);

        m_tileMap.MeshSettings = settings;

        // The level generator uses an enum to define each type of tile.
        // UnityTileMap doesn't (and shouldn't) know about the enum,
        // so we need a way to translate each enum value (type of tile) to a sprite.
        var tileTypes = new Dictionary <LevelGenerator.TileType, int>();

        tileTypes[LevelGenerator.TileType.Wall]  = tileSheet.Lookup("Green");
        tileTypes[LevelGenerator.TileType.Floor] = tileSheet.Lookup("Blue");

        // Generate the level.
        var level = LevelGenerator.Generate(sizeX, sizeY);

        // Loop through the level and set each tile.
        // This might look very different depending on how the generator/loader returns the level.
        foreach (KeyValuePair <Vector2, LevelGenerator.TileType> pair in level)
        {
            var x    = (int)pair.Key.x;
            var y    = (int)pair.Key.y;
            var tile = pair.Value;

            // Use our cached lookup, which sprite represents this type of tile?
            var spriteId = tileTypes[tile];

            // Set one tile.
            m_tileMap[x, y] = spriteId;
        }

        // Done!
    }
Esempio n. 4
0
    // Use this for initialization
    private void Start()
    {
        // Create settings
        var meshSettings = new TileMeshSettings
        {
            // The number of tiles on the x axis
            TilesX = 2,
            // The number of tiles on the y axis
            TilesY = 2,
            // The number of pixels along each axis on a tile
            TileResolution = 16,
            // The size of one tile in Unity units
            TileSize = 1f
        };

        // Apply settings, resizing the TileMap
        m_tileMapBehaviour.MeshSettings = meshSettings;

        // Draw a checker pattern
        m_tileMapBehaviour.PaintTile(0, 0, Color.white);
        m_tileMapBehaviour.PaintTile(1, 0, Color.black);
        m_tileMapBehaviour.PaintTile(0, 1, Color.black);
        m_tileMapBehaviour.PaintTile(1, 1, Color.white);
    }