private void OnSceneGUI() { HandleUtility.nearestControl = GUIUtility.GetControlID(FocusType.Passive); Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit raycastHit; if (world.transform.hasChanged == true) { world.transform.localScale = new Vector3(world.transform.localScale.x, world.transform.localScale.x, world.transform.localScale.x); world.transform.localRotation = Quaternion.identity; world.Generate(); world.transform.hasChanged = false; } if (Event.current.type == EventType.MouseDown) { if (Event.current.button == 0) { leftButtonDown = true; } else if (Event.current.button == 1) { rightButtonDown = true; } else if (Event.current.button == 2) { middleButtonDown = true; } } else if (Event.current.type == EventType.MouseUp) { if (Event.current.button == 0) { leftButtonDown = false; } else if (Event.current.button == 1) { rightButtonDown = false; } else if (Event.current.button == 2) { middleButtonDown = false; } } if (world.editMode == true) { if ((Event.current.shift == false || world.terrainMode == World.TerrainMode.Line)) { // Brushes if (Physics.Raycast(ray, out raycastHit, 1000, LayerMask.GetMask("Chunk"))) { if (raycastHit.transform.GetComponent <Chunk>() != null) { World world = raycastHit.transform.parent.GetComponent <World>(); if (world.terrainMode == World.TerrainMode.Modify) { Handles.color = Color.white; if (world.alwaysFaceUpwards == true) { Handles.DrawWireDisc(raycastHit.point, Vector3.up, world.range); } else { Handles.DrawWireDisc(raycastHit.point, raycastHit.normal, world.range); } if ((leftButtonDown == true || rightButtonDown == true) && (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag)) { bool raise = true; if (rightButtonDown == true) { raise = false; } if (world.alwaysFaceUpwards == true) { TerrainEditor.ModifyTerrain(world, raycastHit.point, Vector3.up, raise); } else { TerrainEditor.ModifyTerrain(world, raycastHit.point, raycastHit.normal, raise); } } } else if (world.terrainMode == World.TerrainMode.Set) { Handles.color = Color.white; Handles.DrawWireDisc(raycastHit.point, Vector3.up, world.range); if (leftButtonDown == true && (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag)) { TerrainEditor.SetTerrain(world, raycastHit.point); } else if (middleButtonDown == true) { world.targetHeight = (raycastHit.point.y - raycastHit.transform.position.y) / world.transform.lossyScale.x + 0.5f; } } else if (world.terrainMode == World.TerrainMode.Line) { if (world.startPosition != new Vector3(float.MaxValue, float.MaxValue, float.MaxValue) && world.endPosition != new Vector3(float.MaxValue, float.MaxValue, float.MaxValue)) { Vector3 forward = world.startPosition - world.endPosition; Vector3 left = new Vector3(-forward.z, 0, forward.x).normalized; Handles.zTest = UnityEngine.Rendering.CompareFunction.Less; Handles.color = world.settings.FindProperty("linePreviewColour").colorValue; Handles.DrawLine(world.startPosition - left * world.range, world.endPosition - left * world.range / 2); Handles.DrawLine(world.startPosition + left * world.range, world.endPosition + left * world.range / 2); Handles.zTest = UnityEngine.Rendering.CompareFunction.Disabled; } if (Event.current.shift == false) { if (leftButtonDown == true) { world.startPosition = raycastHit.point; } else if (rightButtonDown == true) { world.endPosition = raycastHit.point; } } } else if (world.terrainMode == World.TerrainMode.Smooth) { Handles.color = Color.white; Handles.DrawWireDisc(raycastHit.point, (ray.origin - raycastHit.point).normalized, world.range); if (leftButtonDown == true) { TerrainEditor.SmoothTerrain(world, raycastHit.point, (ray.origin - raycastHit.point).normalized); } } else if (world.terrainMode == World.TerrainMode.Paint) { Handles.color = Color.white; Handles.DrawWireDisc(raycastHit.point, raycastHit.normal, world.range); if (leftButtonDown == true && (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag)) { TerrainEditor.PaintTerrain(world, raycastHit.point); } else if (middleButtonDown == true) { if (Event.current.control == true) { world.colourMask = raycastHit.transform.GetComponent <MeshFilter>().sharedMesh.colors[raycastHit.transform.GetComponent <MeshFilter>().sharedMesh.triangles[raycastHit.triangleIndex * 3]]; } else { world.colour = raycastHit.transform.GetComponent <MeshFilter>().sharedMesh.colors[raycastHit.transform.GetComponent <MeshFilter>().sharedMesh.triangles[raycastHit.triangleIndex * 3]]; } } } } } } } SceneView.currentDrawingSceneView.Repaint(); }