コード例 #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");
    }
コード例 #2
0
        protected virtual void Awake()
        {
            Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
            assetsPath = Application.streamingAssetsPath;

            if (m_tileMeshSettings == null)
            {
                m_tileMeshSettings = new TileMeshSettings(2, 2, 16, 1f, MeshMode.SingleQuad);
            }

            if (m_tileSheet == null)
            {
                m_tileSheet = ScriptableObject.CreateInstance <TileSheet>();
            }

            if (m_chunkManager == null)
            {
                m_chunkManager = new TileChunkManager();
                m_chunkManager.Initialize(this, m_tileMeshSettings);
            }

            if (m_tileMapData == null)
            {
                m_tileMapData = new TileMapData();
                m_tileMapData.SetSize(m_tileMeshSettings.TilesX, m_tileMeshSettings.TilesY);
            }

            if (Application.isPlaying || m_activeInEditMode)
            {
                CreateMesh();
            }
        }
コード例 #3
0
        protected virtual void Awake()
        {
            if (m_tileMeshSettings == null)
            {
                m_tileMeshSettings = new TileMeshSettings(2, 2, 16, 1f, MeshMode.SingleQuad);
            }

            if (m_tileSheet == null)
            {
                m_tileSheet = ScriptableObject.CreateInstance <TileSheet>();
            }

            if (m_chunkManager == null)
            {
                m_chunkManager = new TileChunkManager();
                m_chunkManager.Initialize(this, m_tileMeshSettings);
            }

            if (m_tileMapData == null)
            {
                m_tileMapData = new TileMapData();
                m_tileMapData.SetSize(m_tileMeshSettings.TilesX, m_tileMeshSettings.TilesY);
            }

            if (Application.isPlaying || m_activeInEditMode)
            {
                CreateMesh();
            }
        }
コード例 #4
0
 public void Initialize(TileMapBehaviour parent, TileMeshSettings settings)
 {
     if (Initialized)
     {
         throw new InvalidOperationException("Already initialized");
     }
     m_parent    = parent;
     m_settings  = settings;
     Initialized = true;
 }
コード例 #5
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!
    }
コード例 #6
0
ファイル: Demo2Script.cs プロジェクト: ntl92bk/UnityTileMap
    // 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);
    }
コード例 #7
0
        protected virtual void Awake()
        {
            if (m_tileMeshSettings == null)
                m_tileMeshSettings = new TileMeshSettings(2, 2, 16, 1f, MeshMode.SingleQuad);

            if (m_tileSheet == null)
                m_tileSheet = ScriptableObject.CreateInstance<TileSheet>();

            if (m_chunkManager == null)
            {
                m_chunkManager = new TileChunkManager();
                m_chunkManager.Initialize(this, m_tileMeshSettings);
            }

            if (m_tileMapData == null)
            {
                m_tileMapData = new TileMapData();
                m_tileMapData.SetSize(m_tileMeshSettings.TilesX, m_tileMeshSettings.TilesY);
            }

            if (Application.isPlaying || m_activeInEditMode)
                CreateMesh();
        }
コード例 #8
0
 public void Initialize(TileMapBehaviour parent, TileMeshSettings settings)
 {
     if (Initialized)
         throw new InvalidOperationException("Already initialized");
     m_parent = parent;
     m_settings = settings;
     Initialized = true;
 }
コード例 #9
0
ファイル: LevelBehaviour.cs プロジェクト: CatNigiri/Keen
    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;
        }

	   itens = GameObject.Find("Itens");
		
		if (itens == null)
		{
			Debug.LogError("itens not found");
			return;
		}

		blocks = GameObject.Find("Blocks");
		
		if (blocks == null)
		{
			Debug.LogError("blocks not found");
			return;
		}

		mapPrefab= GameObject.Find("Map");
		
		if (mapPrefab == null)
		{
			Debug.LogError("Map not found");
			return;
		}


		enemies = GameObject.Find ("Enemies");

		if (enemies == null)
		{
			Debug.LogError("Enemies not found");
			return;
		}

 
		tmx_map = GameObject.Find ("TMX - MAP");
		
		if (enemies == null)
		{
			Debug.LogError("tmx map 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.Totem, "Totem");
		m_tiles.Map(TileType.Totem1, "Totem1");
		m_tiles.Map(TileType.Totem2, "Totem2");
		m_tiles.Map(TileType.ALWAYS_CLOSED_DOOR, "ALWAYS_CLOSED_DOOR");
		m_tiles.Map(TileType.ALWAYS_OPEN_DOOR, "ALWAYS_OPEN_DOOR");
		m_tiles.Map(TileType.LOCALLY_CLOSED_DOOR, "LOCALLY_CLOSED_DOOR");
		m_tiles.Map(TileType.KEY_RECQUIRING_DOOR, "KEY_RECQUIRING_DOOR");
		m_tiles.Map(TileType.GEM, "GEM");
		m_tiles.Map(TileType.BIG_CRYSTAL, "BIG_CRYSTAL");
		m_tiles.Map(TileType.SMALL_CRYSTAL, "SMALL_CRYSTAL");
		m_tiles.Map(TileType.CLIPPING, "CLIPPING"); 
		m_tiles.Map(TileType.ONE_HP_REFILL, "ONE_HP_REFILL");
		m_tiles.Map(TileType.ENEMY_INSTANCE, "ENEMY_INSTANCE");	 
		m_tiles.Map(TileType.COLLECTIBLE_INSTANCE, "COLLECTIBLE_INSTANCE");
		m_tiles.Map(TileType.KEY, "KEY");
 
 
    }