void Start() { _Matrix = new PathNode[32, 32]; for (int i = 0, length = _Matrix.GetUpperBound(0) + 1; i < length; i++) { for (int j = 0, max = _Matrix.GetUpperBound(1) + 1; j < max; j++) { if ((i == 2 && j >= 5 && j <= 16) || (i == 4 && j >= 5 && j <= 31) || (j == 2 && i >= 16 && i <= 20) || (j == 14 && i >= 9 && i <= 31)) { _Matrix[i, j] = new PathNode { _X = i, _Y = j, _CanWalk = false }; } else { _Matrix[i, j] = new PathNode { _X = i, _Y = j, _CanWalk = true }; } } } _PathFinder.Init(_Matrix); _StartNode = new PathNode(0, 5); _EndNode = new PathNode(10, 31); var nodes = _PathFinder.FindPath(ToPoint2D(_StartNode), ToPoint2D(_EndNode)); // for test. draw grids. for (int i = 0, length = _Matrix.GetUpperBound(0) + 1; i < length; i++) { for (int j = 0, max = _Matrix.GetUpperBound(1) + 1; j < max; j++) { if (!_Matrix[i, j]._CanWalk) { AddGrid(_Barriers, i, j); } AddGrid(_Map, i, j); } } //Debug.Log("nodes.Count=" + nodes.Count); for (int i = 0, length = nodes.Count; i < length; i++) { var n = nodes[i]; AddGrid(_Path, n._X, n._Y); //Debug.LogFormat("node {0}={1}", i, nodes[i]); } }
public void SetData(BaseCharacter character) { _Character = character; _Matrix = new PathNode[(int)(MapManager.instance.CurMapSize.x / _GridSize), (int)(MapManager.instance.CurMapSize.y / _GridSize)]; for (int x = 0, length = _Matrix.GetUpperBound(0) + 1; x < length; x++) { for (int y = 0, max = _Matrix.GetUpperBound(1) + 1; y < max; y++) { _Matrix[x, y] = new PathNode { _X = x, _Y = y, _CanWalk = true }; var barrier = Physics2D.OverlapBox(ConvertVector3FromGrid(x, y), Vector2.one * _GridSize, 0, LayerMask.GetMask("Barrier")); if (barrier != null) { _Matrix[x, y]._CanWalk = false; } } } _PathFinder.Init(_Matrix); }