Unity Tilemap을 이용해서 원하는 크기의 격자맵 그리기

2023. 9. 30. 22:20·개발툴/Unity

Unity Tilemap의 SetTile을 사용하면 타일 설정이 가능하다.

참고자료

https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.SetTile.html

 

Unity - Scripting API: Tilemaps.Tilemap.SetTile

Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close

docs.unity3d.com

활용 코드

using UnityEngine;
using UnityEngine.Tilemaps;

public class Board : MonoBehaviour
{
    public Tilemap tilemap { get; private set; }

    private void Awake()
    {
        tilemap = GetComponent<Tilemap>();
    }

    /// <summary>
    /// state의 행과 열의 크기만큼 tilemap을 설정한다.
    /// </summary>
    public void Draw(Cell[,] state)
    {
        int width = state.GetLength(0); // 행의 개수
        int height = state.GetLength(1); // 열의 개수

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                Cell cell = state[x, y];
                tilemap.SetTile(cell.position, GetTile(cell));
            }
        }
    }

    private Tile GetTile(Cell cell)
    {
        //...원하는 타일을 리턴한다.
        return tile;
    }

}

'개발툴 > Unity' 카테고리의 다른 글

Reflex (Github Readme 번역)  (1) 2023.12.18
Unity에서 ChatGPT 사용하기  (0) 2023.10.24
IL2CPP  (0) 2023.09.30
Null 레퍼런스 예외 해결방법  (0) 2023.07.28
<시간 및 프레임 속도 관리>  (0) 2023.07.16
'개발툴/Unity' 카테고리의 다른 글
  • Reflex (Github Readme 번역)
  • Unity에서 ChatGPT 사용하기
  • IL2CPP
  • Null 레퍼런스 예외 해결방법
가든_
가든_
  • 가든_
    Code Garden
    가든_
  • 전체
    오늘
    어제
    • 글 목록 (60)
      • 프로그래밍 언어 (11)
        • JAVA (0)
        • C++ (2)
        • C# (9)
      • 개발툴 (24)
        • Visual Studio (0)
        • Visual Studio Code (1)
        • Eclipse (1)
        • Unity (19)
        • Unreal (0)
        • Spring (1)
        • SpringBoot (0)
        • Vue (2)
      • 디자인 패턴 (6)
      • 백엔드 (4)
        • MySQL (1)
        • Servlet (3)
      • 프론트엔드 (4)
        • HTML (3)
        • CSS (0)
        • Javascript (1)
      • 알고리즘 (10)
        • 공식 (3)
        • 백준 (6)
        • SW Expert Academy (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    swea2112
    Abstract Factory 패턴
    12738
    Java
    클래스 어댑터
    MVC
    스택
    컴파일 상수
    UniRX
    Adapter 패턴
    구조패턴
    ()=>
    DI
    HTML
    Factory 패턴
    Adaptee
    구조적 UML 다이어그램
    c#
    Reflex
    런타임 상수
    Proxy 패턴
    RDBM
    Unity
    다이어그램 그리기
    오브젝터 어댑터
    SetTile
    FixedUpdate
    행동 UML 다이어그램
    상태공간트리
    chatGPT
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
가든_
Unity Tilemap을 이용해서 원하는 크기의 격자맵 그리기
상단으로

티스토리툴바