public override void OnSceneGUI() { Bounds editBounds = new Bounds(); bool updateVegetation = false; _terrain = (Terrain)target; int buttonIndex = GetActiveButton(); Event current = Event.current; int controlId = GUIUtility.GetControlID(EditorInstance.GetHashCode(), FocusType.Passive); var currentEventType = current.GetTypeForControl(controlId); if (buttonIndex <= 3) { switch (currentEventType) { case EventType.MouseDown: case EventType.MouseUp: case EventType.MouseDrag: if (current.button == 0) { var size = EditorPrefs.GetInt("TerrainBrushSize"); Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit raycastHit; if (_terrain.GetComponent <Collider>().Raycast(ray, out raycastHit, float.PositiveInfinity)) { var pos = raycastHit.point; float sizeScale = 5f; editBounds = new Bounds(pos, new Vector3(size * sizeScale, size, size * sizeScale)); updateVegetation = true; } } break; } if (currentEventType == EventType.MouseDown) { _combindedBounds = new Bounds(editBounds.center, editBounds.size); } else if (currentEventType == EventType.MouseDrag || currentEventType == EventType.MouseUp) { _combindedBounds.Encapsulate(editBounds); } } base.OnSceneGUI(); if (updateVegetation) { if (buttonIndex < 3) { if (currentEventType == EventType.MouseUp) { _combindedBounds.Expand(4f); VegetationStudioManager.RefreshTerrainHeightmap(_combindedBounds); } } else { editBounds.Expand(1f); VegetationStudioManager.ClearCache(editBounds); } } }