public void OnSceneGUI() { Vox.VoxelEditor editor = (Vox.VoxelEditor)target; if (editor.selectedMode != 1) { return; } if (editor.pathPoints != null && editor.pathPoints.Length > 0 && editor.isSelectedBrushPathable() && editor.showPositionHandles) { for (int i = 0; i < editor.pathPoints.Length; ++i) { editor.pathPoints[i] = UnityEditor.Handles.PositionHandle(editor.pathPoints[i], Quaternion.identity); } } int controlId = GUIUtility.GetControlID(FocusType.Passive); switch (UnityEngine.Event.current.GetTypeForControl(controlId)) { case EventType.MouseDown: if (UnityEngine.Event.current.button == 0) { GUIUtility.hotControl = controlId; applyBrush(editor, HandleUtility.GUIPointToWorldRay(UnityEngine.Event.current.mousePosition)); UnityEngine.Event.current.Use(); } break; case EventType.MouseUp: if (UnityEngine.Event.current.button == 0) { GUIUtility.hotControl = 0; UnityEngine.Event.current.Use(); } break; case EventType.MouseMove: SceneView.RepaintAll(); break; case EventType.KeyDown: if (UnityEngine.Event.current.keyCode == KeyCode.Escape) { editor.pathPoints = null; } break; } }
protected void applyBrush(Vox.VoxelEditor editor, Ray mouseLocation) { // get point clicked on System.Nullable <Vector3> point = editor.getBrushPoint(mouseLocation); if (point == null) { return; } // check if control pressed. If so, add point to pathList if (editor.isPathing()) { editor.addPathPoint(point.Value); return; } // check for showPositionHandles if (editor.showPositionHandles && editor.isSelectedBrushPathable() && editor.pathPoints != null && editor.pathPoints.Length > 0) { return; } // create mutator Vox.Mutator mutator = buildMutator(editor, point.Value); // apply mutator if (mutator == null) { return; } Vox.LocalMutator localMutator = mutator as Vox.LocalMutator; if (localMutator != null && editor.pathPoints != null && editor.pathPoints.Length > 0) { editor.addPathPoint(point.Value); mutator = new Vox.LineMutator(editor.pathPoints, localMutator); editor.pathPoints = null; } mutator.apply(editor); }