public void ModeChanged(PrefabPainter.Mode mode) { if (mode == PrefabPainter.Mode.Brush) { brushDistribution.CreatePreviewPrefab(); } else { brushDistribution.DestroyPreviewPrefab(); } }
private void DrawBrush(PrefabPainter.Mode mode, BrushSettings brushSettings, Vector3 position, Vector3 normal, float radius, BrushMode brushMode) { // set default colors Color innerColor = GUIStyles.BrushNoneInnerColor; Color outerColor = GUIStyles.BrushNoneOuterColor; // set colors depending on brush mode switch (brushMode) { case BrushMode.None: innerColor = GUIStyles.BrushNoneInnerColor; outerColor = GUIStyles.BrushNoneOuterColor; break; case BrushMode.ShiftKey: case BrushMode.ShiftPressed: case BrushMode.ShiftDrag: innerColor = GUIStyles.BrushAddInnerColor; outerColor = GUIStyles.BrushAddOuterColor; break; case BrushMode.ShiftCtrlKey: case BrushMode.ShiftCtrlPressed: case BrushMode.ShiftCtrlDrag: innerColor = GUIStyles.BrushRemoveInnerColor; outerColor = GUIStyles.BrushRemoveOuterColor; break; } switch (mode) { case PrefabPainter.Mode.Brush: DrawPaintBrush(brushSettings, position, normal, radius, innerColor, outerColor, brushMode); break; case PrefabPainter.Mode.Interaction: DrawInteractionBrush(brushSettings, position, normal, radius, innerColor, outerColor); break; case PrefabPainter.Mode.Spline: case PrefabPainter.Mode.Container: default: Debug.LogError($"Not supported $mode"); break; } }
public void ModeChanged(PrefabPainter.Mode mode) { }
public bool DrawBrush(PrefabPainter.Mode mode, BrushSettings brushSettings, out BrushMode brushMode, out RaycastHit mouseHit) { brushMode = BrushMode.None; mouseHit = new RaycastHit(); float radius = brushSettings.brushSize / 2f; Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); // create layer mask without ignore raycast on which the preview gameobject is LayerMask layerMask = LayerUtils.GetPreviewLayerMask(brushSettings.layerMask); if (Physics.Raycast(ray.origin, ray.direction, out RaycastHit hit, Mathf.Infinity, layerMask)) { mouseHit = hit; /// /// process mouse events /// // brush size & rotation: control key pressed if (Event.current.control) { // mouse wheel up/down changes the radius if (Event.current.type == EventType.ScrollWheel) { // ctrl + shift + scroll = brush rotation if (Event.current.shift) { int rotationStepSize = 10; int rotationMin = 0; // TODO: find out of to get that from Range int rotationMax = 360; // TODO: find out of to get that from Range // scroll up if (Event.current.delta.y > 0) { brushSettings.brushRotation += rotationStepSize; if (brushSettings.brushRotation > rotationMax) { brushSettings.brushRotation = rotationMin + rotationStepSize; } Event.current.Use(); } // scroll down else if (Event.current.delta.y < 0) { brushSettings.brushRotation -= rotationStepSize; if (brushSettings.brushRotation < rotationMin) { brushSettings.brushRotation = rotationMax - rotationStepSize; } Event.current.Use(); } } // ctrl + scroll = brush size else { // scroll up if (Event.current.delta.y > 0) { brushSettings.brushSize++; Event.current.Use(); } // scroll down else if (Event.current.delta.y < 0) { brushSettings.brushSize--; // TODO: slider if (brushSettings.brushSize < 1) { brushSettings.brushSize = 1; } Event.current.Use(); } } } } // default: nothing pressed brushMode = BrushMode.None; // mouse pressed state: unity editor acts only on events, so we need to keep track of the click state if (Event.current.isMouse && Event.current.button == 0) { if (Event.current.type == EventType.MouseDown) { mousePressed = true; } else if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseLeaveWindow) { mousePressed = false; } } // keyboard only case if (Event.current.shift) { brushMode = BrushMode.ShiftKey; if (Event.current.control) { brushMode = BrushMode.ShiftCtrlKey; } } // check if mouse button is being pressed without dragging; if (mousePressed) { if (Event.current.shift) { brushMode = BrushMode.ShiftPressed; if (Event.current.control) { brushMode = BrushMode.ShiftCtrlPressed; } } } // keyboard + mouse case if (Event.current.isMouse) { // left button = 0; right = 1; middle = 2 if (Event.current.button == 0) { // drag case if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) { if (Event.current.shift) { brushMode = BrushMode.ShiftDrag; if (Event.current.control) { brushMode = BrushMode.ShiftCtrlDrag; } } } } } // draw brush gizmo if (Event.current.type == EventType.Repaint) { DrawBrush(mode, brushSettings, hit.point, hit.normal, radius, brushMode); } } return(brushMode != BrushMode.None); }