Adaid's Workroom
[IC] Isometric 타일맵 에디터 제작기 (4) - 맵 그리드와 스냅 그리드 분리 본문
18.01.05
맵 그리드와 스냅 그리드 분리하여 Draw
맵 그리드와 스냅 그리드
맵 그리드가 맵을 타일 단위로 보여준다면 스냅 그리드는 그와 별개로 수치를 입력받아 보여준다.
타일 크기 128, (스냅) 그리드 크기 64이면 아래과 같이 보여지는 식.
점선이 스냅 그리드이다.
수정 & 추가된 함수들.
void OnSceneGUI() { SceneView.RepaintAll(); //그리드 상수 업데이트 mapGridWidth = mapManager.tileSize * gridConst * 0.5f; mapGridHeight = mapManager.tileSize * gridConst * 0.25f; snapGridWidth = mapManager.gridSize * gridConst * 0.5f; snapGridHeight = mapManager.gridSize * gridConst * 0.25f; initialPosition = mapManager.transform.position; initialPosition.y += mapGridHeight; //그리드 Draw DrawMapGrid(); DrawSnapGrid(); //마우스 입력 관련 ... }
private void DrawMapGrid() { //그리드 선 색 설정 Handles.color = mapManager.mapGridColor; //왼쪽 아래 방향 그리드 Draw Vector2 startPos = initialPosition; Vector2 endPos = initialPosition; endPos.x -= mapManager.mapHeight * mapGridWidth; endPos.y -= mapManager.mapHeight * mapGridHeight; for (int i = 0; i < (mapManager.mapWidth + 1); i++) { Handles.DrawLine(startPos, endPos); startPos.x += mapGridWidth; startPos.y -= mapGridHeight; endPos.x += mapGridWidth; endPos.y -= mapGridHeight; } //오른쪽 아래 방향 그리드 Draw startPos = initialPosition; endPos = initialPosition; endPos.x += mapManager.mapWidth * mapGridWidth; endPos.y -= mapManager.mapWidth * mapGridHeight; for (int i = 0; i < (mapManager.mapHeight + 1); i++) { Handles.DrawLine(startPos, endPos); startPos.x -= mapGridWidth; startPos.y -= mapGridHeight; endPos.x -= mapGridWidth; endPos.y -= mapGridHeight; } }
private void DrawSnapGrid() { int snapWidthCount = Mathf.FloorToInt(mapManager.mapWidth * (mapGridWidth / snapGridWidth)) + 1; int snapHeightCount = Mathf.FloorToInt(mapManager.mapHeight * (mapGridHeight / snapGridHeight)) + 1; //그리드 선 색 설정 Handles.color = mapManager.snapGridColor; //왼쪽 아래 방향 그리드 Draw Vector2 startPos = initialPosition; Vector2 endPos = initialPosition; endPos.x -= mapManager.mapHeight * mapGridWidth; endPos.y -= mapManager.mapHeight * mapGridHeight; for (int i = 0; i < snapWidthCount; i++) { Handles.DrawDottedLine(startPos, endPos, 2f); startPos.x += snapGridWidth; startPos.y -= snapGridHeight; endPos.x += snapGridWidth; endPos.y -= snapGridHeight; } //오른쪽 아래 방향 그리드 Draw startPos = initialPosition; endPos = initialPosition; endPos.x += mapManager.mapWidth * mapGridWidth; endPos.y -= mapManager.mapWidth * mapGridHeight; for (int i = 0; i < snapHeightCount; i++) { Handles.DrawDottedLine(startPos, endPos, 2f); startPos.x -= snapGridWidth; startPos.y -= snapGridHeight; endPos.x -= snapGridWidth; endPos.y -= snapGridHeight; } }
변경점중 하나는 약간의 최적화 및 코드 간결화를 initialPosition을 미리 계산하여 사용한것이다.
여튼 위와 같이 개선하여 맵과 스냅의 그리드를 각각 따로 보여주었다.
'프로젝트 > Infinite Cocktail' 카테고리의 다른 글
[IC] Isometric 타일맵 에디터 제작기 (6) - MouseOver된 타일 표시 (0) | 2018.01.05 |
---|---|
[IC] Isometric 타일맵 에디터 제작기 (5) - 편집모드 전환 버튼 (0) | 2018.01.05 |
[IC] Isometric 타일맵 에디터 제작기 (3) - Isometric 타일 좌표 계산 (0) | 2018.01.05 |
[IC] Isometric 타일맵 에디터 제작기 (2) - Isometric 에디터 그리드 (2) | 2018.01.05 |
[IC] Isometric 타일맵 에디터 제작기 (1) - Isometric 기능 구현 (1) | 2018.01.05 |
Comments