void OnSceneGUI() { if (tgs == null || Application.isPlaying || !tgs.enableGridEditor) { return; } if (tgs.terrain != null) { // prevents terrain from being selected HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } Event e = Event.current; bool gridHit = tgs.CheckRay(HandleUtility.GUIPointToWorldRay(e.mousePosition)); if (cellHighlightedIndex != tgs.cellHighlightedIndex) { cellHighlightedIndex = tgs.cellHighlightedIndex; SceneView.RepaintAll(); } int controlID = GUIUtility.GetControlID(FocusType.Passive); EventType eventType = e.GetTypeForControl(controlID); if ((eventType == EventType.MouseDown && e.button == 0) || (eventType == EventType.MouseMove && e.shift)) { if (gridHit) { e.Use(); } if (cellHighlightedIndex < 0) { return; } if (!e.shift && cellSelectedIndices.Contains(cellHighlightedIndex)) { cellSelectedIndices.Remove(cellHighlightedIndex); } else { if (!e.shift || (e.shift && !cellSelectedIndices.Contains(cellHighlightedIndex))) { if (!e.shift && !e.control) { cellSelectedIndices.Clear(); } cellSelectedIndices.Add(cellHighlightedIndex); if (textureMode > 0) { tgs.CellToggleRegionSurface(cellHighlightedIndex, true, Color.white, false, textureMode); SceneView.RepaintAll(); } if (cellHighlightedIndex >= 0) { cellTerritoryIndex = tgs.CellGetTerritoryIndex(cellHighlightedIndex); cellColor = tgs.CellGetColor(cellHighlightedIndex); if (cellColor.a == 0) { cellColor = Color.white; } cellTextureIndex = tgs.CellGetTextureIndex(cellHighlightedIndex); cellTag = tgs.CellGetTag(cellHighlightedIndex); } } } EditorUtility.SetDirty(target); } int count = cellSelectedIndices.Count; for (int k = 0; k < count; k++) { int index = cellSelectedIndices [k]; Vector3 pos = tgs.CellGetPosition(index); Handles.color = colorSelection; // Handle size Rect rect = tgs.CellGetRect(index); Vector3 min = tgs.transform.TransformPoint(rect.min); Vector3 max = tgs.transform.TransformPoint(rect.max); float dia = Vector3.Distance(min, max); float handleSize = dia * 0.05f; Handles.DrawSolidDisc(pos, tgs.transform.forward, handleSize); } }