-
Notifications
You must be signed in to change notification settings - Fork 15
/
BoardController.cs
62 lines (54 loc) · 1.9 KB
/
BoardController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using HexBoardGame.SharedData;
using Tools.Extensions.Arrays;
using UnityEngine;
using UnityEngine.Tilemaps;
namespace HexBoardGame.Runtime.GameBoard
{
public class BoardController : MonoBehaviour
{
public BoardDataShape boardShape;
[SerializeField] private Tilemap tileMap;
public IBoard Board { get; private set; }
public IBoardManipulation BoardManipulation { get; private set; }
public event Action<IBoard> OnCreateBoard = board => { };
private void Start()
{
CreateBoard();
var start = new Vector3Int(0, 0, 0);
var end = new Vector3Int(3, 0, -3);
var path = BoardManipulation.GetPathBreadthSearch(start, end);
path.Print();
}
private void CreateBoard()
{
//using the tile map orientation to pick the default value
if (tileMap.orientation == Tilemap.Orientation.XY)
CreateBoardPointy();
else
CreateBoardFlat();
BoardManipulation = new BoardManipulationOddR(boardShape);
}
public void SetBoarDataAndCreate(BoardDataShape boardDataShape)
{
boardShape = boardDataShape;
CreateBoard();
}
public void CreateBoardFlat()
{
tileMap.orientation = Tilemap.Orientation.YX;
tileMap.layoutGrid.cellSwizzle = GridLayout.CellSwizzle.YXZ;
Board = new Board(this, boardShape, Orientation.FlatTop);
}
public void CreateBoardPointy()
{
tileMap.orientation = Tilemap.Orientation.XY;
tileMap.layoutGrid.cellSwizzle = GridLayout.CellSwizzle.XYZ;
Board = new Board(this, boardShape, Orientation.PointyTop);
}
public void DispatchCreateBoard(IBoard board)
{
OnCreateBoard(board);
}
}
}