protected override void OnGUIMain() { if (mBlackLabel == null) { // Need to initialize shared style. mBlackLabel = new GUIStyle(GUI.skin.label); mBlackLabel.normal.textColor = Color.black; mBlackLabel.fontStyle = FontStyle.Bold; } TileSelection selection = Context.Selection; selection.Validate(); TileBuildData tdata = Context.Build.BuildData; if (tdata == null) { return; } Rect mainArea = Context.MainArea; // The box and shift makes it look better. GUI.Box(mainArea, ""); mainArea.x += MarginSize; mainArea.y += MarginSize; // Draw the status grid. // Note: View is expanded by one grid size in order to minimize // grid/slider overlap. Rect view = new Rect(0, 0, tdata.Width * GridCellSize + GridCellSize , tdata.Depth * GridCellSize + GridCellSize); mScrollPos = GUI.BeginScrollView(mainArea, mScrollPos, view); OnGUIStatusGrid(view.height - GridCellSize); GUI.EndScrollView(); OnGUIMainStandard(); if (IsBaseBusy) { return; } // Handle the mouse, including click selection. Event evt = Event.current; Vector2 mousePos = evt.mousePosition; if (mainArea.Contains(mousePos)) { Vector2 gridPos = mousePos; gridPos.x -= mainArea.xMin - mScrollPos.x; gridPos.y -= mainArea.yMin - mScrollPos.y; int x = Mathf.FloorToInt(gridPos.x / GridCellSize); // For the depth, we need to invert the y-axis. int z = tdata.Depth - Mathf.FloorToInt(gridPos.y / GridCellSize) - 1; if (x < tdata.Width && z >= 0 && z < tdata.Depth) { GUI.Label(new Rect(mousePos.x - 20, mousePos.y - 20, 120, 25) , "(" + x + "," + z + "): " + tdata.GetState(x, z) , mBlackLabel); mMouseX = x; mMouseZ = z; if (evt.type == EventType.MouseDown && evt.button == 0) { if (selection.SelectedX == mMouseX && selection.SelectedZ == mMouseZ) { // Clicked on same tile. Deselect. selection.ClearSelection(); } else { selection.SetSelection(mMouseX, mMouseZ); } } } else { mMouseX = TileSelection.NoSelection; mMouseZ = TileSelection.NoSelection; } } else { mMouseX = TileSelection.NoSelection; mMouseZ = TileSelection.NoSelection; } }