void OnGUI() { // Do autoresizing of GUI layer GUIResizer.AutoResize(); GUI.Label(new Rect(10, 10, 300, 30), "Click 3 or more matching cells to remove them!", labelStyle); }
// Use this for initialization void Start() { tgs = TerrainGridSystem.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.normal.textColor = Color.white; isSelectingStart = true; Random.InitState(2); // Draw some blocked areas for (int i = 0; i < 25; i++) { int row = Random.Range(2, tgs.rowCount - 3); int col = Random.Range(2, tgs.columnCount - 3); for (int j = -2; j <= 2; j++) { for (int k = -2; k <= 2; k++) { int cellIndex = tgs.CellGetIndex(row + j, col + k); tgs.CellSetGroup(cellIndex, CELL_OBSTACLE); tgs.CellToggleRegionSurface(cellIndex, true, Color.white); } } } // Example: sets crossing costs for hexagon sides and draw a line int barrierCost = 10000; Color barrierColor = Color.blue; float barrierWidth = 5f; for (int k = 0; k < 10; k++) { int cellIndex = tgs.CellGetIndex(10, k + 20); if (!tgs.cells [cellIndex].canCross) { continue; } if (tgs.cells [cellIndex].column % 2 == 0) { // Assign a crossing cost to barrier for path-finding purposes tgs.CellSetSideCrossCost(cellIndex, CELL_SIDE.Top, barrierCost); tgs.CellSetSideCrossCost(cellIndex, CELL_SIDE.TopLeft, barrierCost); tgs.CellSetSideCrossCost(cellIndex, CELL_SIDE.TopRight, barrierCost); // Make the barrier block LOS (Line-Of-Sight) tgs.CellSetSideBlocksLOS(cellIndex, CELL_SIDE.Top, true); tgs.CellSetSideBlocksLOS(cellIndex, CELL_SIDE.TopLeft, true); tgs.CellSetSideBlocksLOS(cellIndex, CELL_SIDE.TopRight, true); // Draw the barrier tgs.DrawLine(cellIndex, CELL_SIDE.Top, barrierColor, barrierWidth); tgs.DrawLine(cellIndex, CELL_SIDE.TopLeft, barrierColor, barrierWidth); tgs.DrawLine(cellIndex, CELL_SIDE.TopRight, barrierColor, barrierWidth); } else { // Assign a crossing cost to barrier for path-finding purposes tgs.CellSetSideCrossCost(cellIndex, CELL_SIDE.Top, barrierCost); // Make the barrier block LOS (Line-Of-Sight) tgs.CellSetSideBlocksLOS(cellIndex, CELL_SIDE.Top, true); // Draw the barrier tgs.DrawLine(cellIndex, CELL_SIDE.Top, barrierColor, barrierWidth); } } // Hook into cell click event to toggle start selection or draw a computed path using A* path finding algorithm tgs.OnCellClick += (cellIndex, buttonIndex) => BuildPath(cellIndex); tgs.OnCellEnter += (cellIndex) => ShowLineOfSight(cellIndex); }