public PathfindingGraph() { grid = PathfindingGrid.instance; marker = grid.GetWaypointMarkerPrefab(); numCellsAcross = grid.GetCellsAcross(); numClustersAcross = grid.GetClustersAcross(); cellSize = grid.GetCellSize(); clusterSize = grid.GetClusterSize(); gridCapacity = numCellsAcross * numCellsAcross; neighbourOffsetArray = new NativeArray <int2>(8, Allocator.Persistent); neighbourOffsetArray[0] = new int2(-1, 0); neighbourOffsetArray[1] = new int2(+1, 0); neighbourOffsetArray[2] = new int2(0, -1); neighbourOffsetArray[3] = new int2(0, +1); neighbourOffsetArray[4] = new int2(-1, -1); neighbourOffsetArray[5] = new int2(+1, -1); neighbourOffsetArray[6] = new int2(-1, +1); neighbourOffsetArray[7] = new int2(+1, +1); CreateGraph(); //for ( int i = 0; i < 500; i++ ) //Object.Instantiate( marker , new Vector3( edgePathNodePositions[ i ].x * cellSize , 2 , edgePathNodePositions[ i ].y * cellSize ) , Quaternion.identity ); }
private static void FindCover(int x, int y, PathfindingGrid flyable, List <ProjectileCover> result) { foreach (Vector2 direction in directions) { int adjX = (int)direction.x + x; int adjY = (int)direction.y + y; if (flyable.IsInside(adjX, adjY) && flyable.GetCell(adjX, adjY) == null) { Vector2 offset = new Vector2(-direction.y, direction.x); offset.x *= flyable.GetCellSize().x * 0.5f; offset.y *= flyable.GetCellSize().y * 0.5f; Vector2 center = (flyable.CellCenter(x, y) + flyable.CellCenter((int)direction.x + x, (int)direction.y + y)) * 0.5f; result.Add(new ProjectileCover(center + offset, center - offset)); } } }
public PathfindingGraph() { grid = PathfindingGrid.instance; marker = grid.GetWaypointMarkerPrefab(); numCellsAcross = grid.GetCellsAcross(); numClustersAcross = grid.GetClustersAcross(); cellSize = grid.GetCellSize(); clusterSize = grid.GetClusterSize(); gridCapacity = numCellsAcross * numCellsAcross; neighbourOffsetArray = new NativeArray <int2>(8, Allocator.Persistent); neighbourOffsetArray[0] = new int2(-1, 0); neighbourOffsetArray[1] = new int2(+1, 0); neighbourOffsetArray[2] = new int2(0, -1); neighbourOffsetArray[3] = new int2(0, +1); neighbourOffsetArray[4] = new int2(-1, -1); neighbourOffsetArray[5] = new int2(+1, -1); neighbourOffsetArray[6] = new int2(-1, +1); neighbourOffsetArray[7] = new int2(+1, +1); CreateGraph(); /*for ( int i = 0; i < pathKeysPerEdge.Length; i++ ) * { * int2 pathKey = pathKeysPerEdge[ i ]; * * if ( pathKey.y - pathKey.x > 0 ) * { * Debug.Log( "Number of paths per edge " + ( pathKey.y - pathKey.x ) ); * * for ( int j = pathKey.x; j < pathKey.y; j++ ) * { * int2 pathPositionKey = edgePaths[ j ]; * int count = 0; * * for ( int k = pathPositionKey.x; k < pathPositionKey.y; k++ ) * { * count++; * } * * Debug.Log( "PathLength " + count ); * } * * } * }*/ /*for ( int i = 0; i < edgePathPositions.Length; i++ ) * { * Object.Instantiate( marker , new Vector3( edgePathPositions[ i ].x , 2 , edgePathPositions[ i ].y ) , Quaternion.identity ); * }*/ }