For me
[Unity] 2) Block , Cell 배치 (초기화) 본문
플레이 영상
개발 기간 : 1주
버그나 이상한 곳에서 특수 블럭이 나오긴 하지만..
어떻게 진행했는지 정리하면 좋을것 같아 글 작성
Board Controller Init : 블럭 , 셀 설치
- board를 WIDTH 와 HEIGHT 값으로 초기화
- Cell 배치 (XML 파일에서 셀 맵 정보를 받아와 Cell 값 불러오기)
- Block 배치 (XML 파일에서 블럭 맵 정보 받아와 Block 값 불러오기 (NEVER일 경우 나타나지 않음)
더보기
#region Init
public void Init()
{
board = new Board(WIDTH, HEIGHT);
for (int i = 0; i < WIDTH; i++)
{
for (int j = 0; j < HEIGHT; j++)
{
Vector2 temp = new Vector2(i, j);
InstatntiateCell(temp);
InstatntiateBlock(temp);
}
}
// 최종 목표
Score = 4;
// 먼치킨 블럭 생성
board._blocks[4+ 4*HEIGHT].ChangeType(PieceType.Munchkin, BlockType.PIECE, ColorType.None);
//셔플
InitBoardMatch(BFSMode.SUFFLE);
}
void InstatntiateCell(Vector2 temp)
{
GameObject cellInstantiate = Instantiate(cellPrefab, new Vector2(-400 + (temp.x * 100), 300 - (temp.y * 100)), Quaternion.identity, cellParent);
CellController cellCon = cellInstantiate.GetComponent<CellController>();
CellType cellType = (CellType)(Managers.Data.Stage6.Cells[(int)temp.x + (int)temp.y * HEIGHT] - '0');
cellCon.Init(temp.x, temp.y, cellType);
cellInstantiate.name = "cell" + cellCon.info.X.ToString() + " , " + cellCon.info.Y.ToString();
board._cells[cellCon.info.X, cellCon.info.Y] = cellInstantiate.transform;
}
void InstatntiateBlock(Vector2 temp)
{
GameObject blockInstantiate = Instantiate(blockPrefab, new Vector2(-400 + (temp.x * 100), 300 - (temp.y * 100)), Quaternion.identity, blockParent);
BlockController blockCon = blockInstantiate.GetComponent<BlockController>();
if (board._cells[(int)temp.x,(int)temp.y].GetComponent<CellController>().info.cellType == CellType.BASIC)
blockCon.Init(temp.x, temp.y);
else
blockCon.NoBlockInit(temp.x, temp.y,BlockType.NEVER);
blockInstantiate.name = "block" + blockCon.info.X.ToString() + " , " + blockCon.info.Y.ToString();
board._blocks[blockCon.info.index] = blockCon;
}
Block Init : 좌표 , Input , Type 정보
더보기
public void Init(float x, float y)
{
boardController = FindObjectOfType<BoardController>();
InitEventTrigger(); // Input
info = new Block(x,y);
ChangeColor();
}
Cell Init : Color, 정보값 탐색해서 이미지 입력
더보기
public void Init(float x, float y, CellType cellType)
{
info = new Cell(x, y, cellType);
Vector4 vec4 = info.Y % 2 == info.X % 2 ? new Vector4(0.0f, 0.0f, 0.2f, 1f) : new Vector4(0.0f, 0.0f, 0.4f, 1f);
GetComponent<Image>().color = vec4;
if (cellType == CellType.BLOCKER)
image.sprite = blackhole;
}
'Unity > 3Match' 카테고리의 다른 글
[Unity] 6) Block Respawn (0) | 2023.02.20 |
---|---|
[Unity] 5) Block Down (0) | 2023.02.20 |
[Unity] 4) Block Match (0) | 2023.02.20 |
[Unity] 3) Input / 블럭 Swap (0) | 2023.02.19 |
[Unity] 1) 3Match 구성 (0) | 2023.02.16 |