private Vector3 MidpointHandle(Vector3 localPos, Vector3 localTangent, Vector3 localBinormal, Matrix4x4 transform, bool isCameraInsideBox) { Color color = Handles.color; float alphaFactor = 1f; this.AdjustMidpointHandleColor(localPos, localTangent, localBinormal, transform, alphaFactor, isCameraInsideBox); int controlID = GUIUtility.GetControlID(this.m_ControlIdHint, FocusType.Keyboard); if (alphaFactor > 0f) { Handles.DrawCapFunction drawMethodForHandles; Func <Vector3, float> getHandleSizeMethod; Vector3 normalized = Vector3.Cross(localTangent, localBinormal).normalized; if (this.drawMethodForHandles != null) { drawMethodForHandles = this.drawMethodForHandles; } else { drawMethodForHandles = new Handles.DrawCapFunction(BoxEditor.DefaultMidPointDrawFunc); } if (this.getHandleSizeMethod != null) { getHandleSizeMethod = this.getHandleSizeMethod; } else { getHandleSizeMethod = new Func <Vector3, float>(BoxEditor.DefaultMidpointGetSizeFunc); } localPos = Slider1D.Do(controlID, localPos, normalized, getHandleSizeMethod(localPos), drawMethodForHandles, SnapSettings.scale); } Handles.color = color; return(localPos); }
/// <summary> /// Draws position handles with predefined cap function. /// </summary> /// <param name="nodeGlobalPositions"></param> /// <param name="handleSize"></param> /// <param name="curveColor"></param> /// <param name="callback"></param> public static void DrawCustomPositionHandles( List <Vector3> nodeGlobalPositions, float handleSize, Color curveColor, Action <int, Vector3> callback) { // Cap function used to draw handle. Handles.DrawCapFunction capFunction = Handles.CircleCap; // For each node.. for (var i = 0; i < nodeGlobalPositions.Count; i++) { var handleColor = curveColor; // Draw position handle. var newGlobalPos = DrawCustomPositionHandle( nodeGlobalPositions[i], handleSize, handleColor, capFunction); // If node was moved.. if (newGlobalPos != nodeGlobalPositions[i]) { callback(i, newGlobalPos); } } }
#pragma warning disable 618 public static Vector3 Do( int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.DrawCapFunction drawFunc, Vector2 snap, bool drawHelper) #pragma warning restore 618 { bool orgGuiChanged = GUI.changed; GUI.changed = false; Vector2 delta = CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, drawFunc, snap, drawHelper); if (GUI.changed) { handlePos = s_StartPosition + slideDir1 * delta.x + slideDir2 * delta.y; } GUI.changed |= orgGuiChanged; return(handlePos); }
public static Rect ResizeRect(Rect rect, Handles.DrawCapFunction capFunc, float snap) { Vector3[] rectangleCorners = { rect.min, // Bottom Left new Vector2(rect.xMax, rect.y), // Bottom Right rect.max, // Top Right new Vector2(rect.x, rect.yMax) // Top Left }; Vector2[] handlePoints = { // rectangleCorners[0], //Bottom Left new Vector2(rect.center.x, rect.y), // Bottom // rectangleCorners[1], new Vector2(rect.xMax, rect.center.y), // Right // rectangleCorners[2], new Vector2(rect.center.x, rect.yMax), // Top // rectangleCorners[3], new Vector2(rect.x, rect.center.y) // Left }; Handles.Label(rectangleCorners[3] + Vector3.up, "Level Bounds"); Handles.DrawSolidRectangleWithOutline(rectangleCorners, Color.green * 0.2f, Color.green); for (int i = 0; i < handlePoints.Length; i++) { Vector2 p = handlePoints[i]; handlePoints[i] = Handles.Slider(p, p - rect.center, 0.45f, capFunc, snap); } return(new Rect(handlePoints[3].x, handlePoints[0].y, handlePoints[1].x - handlePoints[3].x, handlePoints[2].y - handlePoints[0].y)); }
private void DoResetModeHandles(Ferr2D_Path path, Ferr2DT_PathTerrain terrain, int i, Matrix4x4 mat, Matrix4x4 invMat, Transform camTransform) { int nextId = i == path.Count - 1?(path.closed?i % path.Count:i - 1):i + 1; Vector3 pos = mat.MultiplyPoint3x4(path.pathVerts[i]); Vector3 posNext = mat.MultiplyPoint3x4(path.pathVerts[nextId]); Vector3 normal = -(Vector3)Ferr2D_Path.GetNormal(path.pathVerts, i, path.closed); Vector3 posStart = pos; bool isSelected = false; if (selectedPoints != null) { isSelected = selectedPoints.Contains(i); } float handleScale = HandleScale(posStart); Handles.DrawCapFunction cap = (isSelected || selectedPoints.Count <= 0) ? (Handles.DrawCapFunction)CapDotMinusSelected : (Handles.DrawCapFunction)CapDotMinus; if (Handles.Button(posStart, camTransform.rotation, handleScale, handleScale, cap)) { EnsureVertSelected(i, ref isSelected); deleteSelected = true; GUI.changed = true; } else { handleScale = handleScale * 0.5f; // do scaling Vector3 displayPos = pos + normal * terrain.vertScales[i]; if (IsVisible(displayPos) && Handles.Button(displayPos, camTransform.rotation, handleScale, handleScale, CapDotReset)) { EnsureVertSelected(i, ref isSelected); Undo.RecordObject(terrain, "Scale Path Vert"); for (int s = 0; s < selectedPoints.Count; s++) { terrain.vertScales[selectedPoints[s]] = 1; } EditorUtility.SetDirty(terrain); GUI.changed = true; } // do edge overrides displayPos = GetOverridePos(i, path, mat, pos, posNext); if (IsVisible(displayPos) && Handles.Button(displayPos, camTransform.rotation, handleScale, handleScale, CapDotReset)) { EnsureVertSelected(i, ref isSelected); Undo.RecordObject(terrain, "Override Vert Direction"); for (int s = 0; s < selectedPoints.Count; s++) { terrain.directionOverrides[selectedPoints[s]] = Ferr2DT_TerrainDirection.None; } EditorUtility.SetDirty(terrain); GUI.changed = true; } } }
private SplinePointHandle.Result DrawDragHandle(SplineRenderer renderer, Vector3 position, float scale, bool hasSelectionMargin) { Handles.DrawCapFunction dcf = Handles.CircleCap; float size = HandleUtility.GetHandleSize(position) * 2.0f * m_pointSizeConst; Vector2 guiPosition = HandleUtility.WorldToGUIPoint(position); if (Vector2.Distance(guiPosition, Event.current.mousePosition) > 15 * renderer.PointSize * scale || IsControlPointDrag || Event.current.alt) { size *= 0; } float selectionSize; if (hasSelectionMargin) { selectionSize = size * (renderer.PointSize + renderer.SelectionMargin) * scale; } else { selectionSize = size * renderer.PointSize * scale; } SplinePointHandle.Result result = SplinePointHandle.DragHandleGUI(position, Quaternion.LookRotation(Camera.current.transform.forward), size * renderer.PointSize * scale, selectionSize, dcf, renderer.SelectionColor); return(result); }
/// <summary> /// Displays a line slider. /// </summary> /// <returns>The new value.</returns> /// <param name="id">Control identifier</param> /// <param name="val">Value.</param> /// <param name="origin">Origin.</param> /// <param name="direction">Direction.</param> /// <param name="label">Label.</param> /// <param name="color">Color.</param> /// <param name="capScale">A scale factor for the slider cap.</param> /// <param name="capFunction">Cap function to use. If <see langword="null"/> then defaults to dot.</param> public static float Line( int id, float val, Vector3 origin, Vector3 direction, string label = "", float capScale = 1f, Handles.DrawCapFunction capFunction = null ) { return(Slider(id, val, origin, direction, label, capScale, DisplayMode.Line, capFunction)); }
private Vector3 EdgeHandle(Vector3 handlePos, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, Matrix4x4 transform) { Color color = Handles.color; bool flag = true; if (Camera.current) { Vector3 b = Handles.matrix.inverse.MultiplyPoint(Camera.current.transform.position); Vector3 normalized = (handlePos - b).normalized; Vector3 lhs = Vector3.Cross(slideDir1, slideDir2); float f = Vector3.Dot(lhs, normalized); if (Mathf.Acos(Mathf.Abs(f)) > 1.51843643f) { flag = false; } } float num = (!flag) ? 0f : 1f; this.AdjustEdgeHandleColor(handlePos, slideDir1, slideDir2, transform, num); int controlID = GUIUtility.GetControlID(this.m_ControlIdHint, FocusType.Keyboard); if (num > 0f) { int arg_F4_0 = controlID; Vector3 arg_F4_1 = handlePos; float arg_F4_5 = HandleUtility.GetHandleSize(handlePos) * 0.03f; if (BoxEditor.< > f__mg$cache2 == null) { BoxEditor.< > f__mg$cache2 = new Handles.DrawCapFunction(Handles.DotCap); } handlePos = Slider2D.Do(arg_F4_0, arg_F4_1, handleDir, slideDir1, slideDir2, arg_F4_5, BoxEditor.< > f__mg$cache2, SnapSettings.scale, true); } Handles.color = color; return(handlePos); }
/// <summary> /// Displays a button with a cap function. /// </summary> /// <returns><see langword="true"/> if cap button was clicked; otherwise, <see langword="false"/>.</returns> /// <param name="id">Identifier for the control.</param> /// <param name="position">Position.</param> /// <param name="orientation">Orientation.</param> /// <param name="size">Size.</param> /// <param name="cap">Cap draw function.</param> /// <param name="clickColor">Color to use when the cap is clicked.</param> private static bool DisplayCapButton( int id, Vector3 position, Quaternion orientation, float size, Handles.DrawCapFunction cap, Color clickColor ) { bool result = false; Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if ( ( (HandleUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2) ) && GUIUtility.hotControl == 0 ) { GUIUtility.keyboardControl = id; GUIUtility.hotControl = id; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); result = true; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { GUI.changed = true; current.Use(); } break; case EventType.Repaint: { // TODO: implement click color cap(id, position, orientation, size); break; } case EventType.Layout: HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.2f)); break; } return(result); }
protected void DrawAdaptiveButton(Vector3 position, Quaternion direction, float size, float pickSize, Handles.DrawCapFunction capFunc, Action callback) { var scale = GetHandleSize(position); if (Handles.Button(position, direction, size * scale, pickSize * scale, capFunc)) { Undo.RecordObject(target, "Click Button"); callback.Invoke(); MarkSceneDirty(); } }
protected void DrawFreeMoveHandle(Vector3 position, Quaternion rotation, float size, Vector3 snap, Handles.DrawCapFunction capFunc, Action<Vector3> callback) { EditorGUI.BeginChangeCheck(); var newPosition = Handles.FreeMoveHandle(position, Quaternion.identity, GetHandleSize(position) * size, snap, capFunc); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Move Handle"); callback.Invoke(newPosition); MarkSceneDirty(); } }
protected bool HandleAnchor(ref Vector3 position, bool isConnectedAnchor) { if (Joint2DEditorBase.s_Styles == null) { Joint2DEditorBase.s_Styles = new Joint2DEditorBase.Styles(); } Handles.DrawCapFunction drawFunc = (!isConnectedAnchor) ? new Handles.DrawCapFunction(Joint2DEditorBase.AnchorCap) : new Handles.DrawCapFunction(Joint2DEditorBase.ConnectedAnchorCap); int id = this.target.GetInstanceID() + ((!isConnectedAnchor) ? 0 : 1); EditorGUI.BeginChangeCheck(); position = Handles.Slider2D(id, position, Vector3.back, Vector3.right, Vector3.up, 0f, drawFunc, Vector2.zero); return(EditorGUI.EndChangeCheck()); }
#pragma warning disable 618 public static Vector3 Do( int id, Vector3 handlePos, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.DrawCapFunction drawFunc, float snap, bool drawHelper) #pragma warning restore 618 { return(Do(id, handlePos, new Vector3(0, 0, 0), handleDir, slideDir1, slideDir2, handleSize, drawFunc, new Vector2(snap, snap), drawHelper)); }
protected bool HandleAnchor(ref Vector3 position, bool isConnectedAnchor) { if (anchor == null) { anchor = "U2D.pivotDot"; anchorActive = "U2D.pivotDotActive"; connectedAnchor = "U2D.dragDot"; connectedAnchorActive = "U2D.dragDotActive"; } Handles.DrawCapFunction drawFunc = (!isConnectedAnchor) ? new Handles.DrawCapFunction(AnchorCap) : new Handles.DrawCapFunction(ConnectedAnchorCap); int id = this.target.GetInstanceID() + ((!isConnectedAnchor) ? 0 : 1); EditorGUI.BeginChangeCheck(); position = Handles.Slider2D(id, position, Vector3.back, Vector3.right, Vector3.up, 0f, drawFunc, Vector2.zero); return(EditorGUI.EndChangeCheck()); }
private Vector3 MidpointHandle(Vector3 localPos, Vector3 localTangent, Vector3 localBinormal, Matrix4x4 transform, bool isCameraInsideBox) { Color color = Handles.color; float num = 1f; this.AdjustMidpointHandleColor(localPos, localTangent, localBinormal, transform, num, isCameraInsideBox); int controlID = GUIUtility.GetControlID(this.m_ControlIdHint, FocusType.Keyboard); if (num > 0f) { Vector3 normalized = Vector3.Cross(localTangent, localBinormal).normalized; Handles.DrawCapFunction drawFunc = this.drawMethodForHandles ?? new Handles.DrawCapFunction(BoxEditor.DefaultMidPointDrawFunc); Func <Vector3, float> func = this.getHandleSizeMethod ?? new Func <Vector3, float>(BoxEditor.DefaultMidpointGetSizeFunc); localPos = Slider1D.Do(controlID, localPos, normalized, func(localPos), drawFunc, SnapSettings.scale); } Handles.color = color; return(localPos); }
private void DoNormalModeHandles(MapPolygon path, int i, Matrix4x4 mat, Matrix4x4 invMat, Transform camTransform) { List <Vector3> pathVerts = path.GetVertsRaw(); int nextId = i == path.GetVertsRaw().Count - 1?0:i + 1; Vector3 pos = mat.MultiplyPoint3x4(pathVerts[i]); Vector3 posNext = mat.MultiplyPoint3x4(pathVerts[nextId]); bool isSelected = false; if (selectedPoints != null) { isSelected = selectedPoints.Contains(i); } // check for moving the point Handles.DrawCapFunction cap = CapDot; cap = isSelected ? (Handles.DrawCapFunction)CapDotSelected : (Handles.DrawCapFunction)CapDot; Vector3 result = Handles.FreeMoveHandle(pos, Quaternion.Euler(Vector3.zero), HandleScale(pos), snap, cap); Handles.Label(pos, i.ToString(), EditorStyles.boldLabel); if (result != pos) { EnsureVertSelected(i, ref isSelected); for (int s = 0; s < selectedPoints.Count; s++) { path.UpdateVerts(selectedPoints [s], invMat.MultiplyPoint3x4(result)); //pathVerts [selectedPoints [s]] = invMat.MultiplyPoint3x4 (result); } } // make sure we can add new point at the midpoints!s Vector3 mid = (pos + posNext) / 2f; float handleScale = HandleScale(mid); if (Handles.Button(mid, camTransform.rotation, handleScale, handleScale, CapDotPlus)) { Vector3 pt = invMat.MultiplyPoint3x4(mid); path.AddPointAt(nextId, pt); } }
public static void DrawPointSceneGUI(BezierPoint3D point, Handles.DrawCapFunction drawPointFunc, Handles.DrawCapFunction drawHandleFunc) { // Draw a label for the point Handles.color = Color.black; Handles.Label(point.Position + new Vector3(0f, HandleUtility.GetHandleSize(point.Position) * 0.4f, 0f), point.gameObject.name); // Draw the center of the control point Handles.color = Color.yellow; Vector3 newPointPosition = Handles.FreeMoveHandle(point.Position, point.transform.rotation, HandleUtility.GetHandleSize(point.Position) * BezierPoint3DEditor.pointCapSize, Vector3.one * 0.5f, drawPointFunc); if (point.Position != newPointPosition) { Undo.RegisterCompleteObjectUndo(point.transform, "Move Point"); point.Position = newPointPosition; } // Draw the left and right handles Handles.color = Color.white; Handles.DrawLine(point.Position, point.LeftHandlePosition); Handles.DrawLine(point.Position, point.RightHandlePosition); Handles.color = Color.cyan; Vector3 newLeftHandlePosition = Handles.FreeMoveHandle(point.LeftHandlePosition, point.transform.rotation, HandleUtility.GetHandleSize(point.LeftHandlePosition) * BezierPoint3DEditor.handleCapSize, Vector3.zero, drawHandleFunc); if (point.LeftHandlePosition != newLeftHandlePosition) { Undo.RegisterCompleteObjectUndo(point, "Move Left Handle"); point.LeftHandlePosition = newLeftHandlePosition; } Vector3 newRightHandlePosition = Handles.FreeMoveHandle(point.RightHandlePosition, point.transform.rotation, HandleUtility.GetHandleSize(point.RightHandlePosition) * BezierPoint3DEditor.handleCapSize, Vector3.zero, drawHandleFunc); if (point.RightHandlePosition != newRightHandlePosition) { Undo.RegisterCompleteObjectUndo(point, "Move Right Handle"); point.RightHandlePosition = newRightHandlePosition; } }
#pragma warning disable 618 public static Vector3 Do( int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.DrawCapFunction drawFunc, Vector2 snap, bool drawHelper) #pragma warning restore 618 { bool orgGuiChanged = GUI.changed; GUI.changed = false; Vector2 delta = CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, drawFunc, snap, drawHelper); if (GUI.changed) { handlePos = s_StartPosition + slideDir1 * delta.x + slideDir2 * delta.y; if (EditorSnapSettings.gridSnapActive) { var normal = Vector3.Cross(slideDir1, slideDir2); if (Snapping.IsCardinalDirection(normal)) { var worldSpace = Handles.matrix.MultiplyPoint(handlePos); worldSpace = Snapping.Snap(worldSpace, GridSettings.size, (SnapAxis) ~new SnapAxisFilter(normal)); handlePos = Handles.inverseMatrix.MultiplyPoint(worldSpace); } } } GUI.changed |= orgGuiChanged; return(handlePos); }
private static void Repaint(Quaternion rotation, float handleSize, Handles.DrawCapFunction capFunc, Color selectionColor, int id, Vector3 screenPosition, Matrix4x4 cachedMatrix) { Color currentColor = Handles.color; if (id != m_dragCtrlId) { if (id == GUIUtility.hotControl) { Handles.color = selectionColor; } if (id == HandleUtility.nearestControl) { Handles.color = selectionColor; } } Handles.matrix = Matrix4x4.identity; capFunc(id, screenPosition, rotation, handleSize); Handles.matrix = cachedMatrix; Handles.color = currentColor; }
private static Vector3 DrawCustomPositionHandle( Vector3 nodePosition, float handleSize, Color handleColor, Handles.DrawCapFunction capFunction) { // Set handle color. Handles.color = handleColor; // Get handle size. var movementHandleSize = HandleUtility.GetHandleSize(nodePosition); var sphereSize = movementHandleSize * handleSize; // Draw handle. var newPos = Handles.FreeMoveHandle( nodePosition, Quaternion.identity, sphereSize, Vector3.zero, capFunction); return(newPos); }
private void DoResetModeHandles(MapPolygon path, int i, Matrix4x4 mat, Matrix4x4 invMat, Transform camTransform) { List <Vector3> pathVerts = path.GetVertsRaw(); int nextId = i == pathVerts.Count - 1?i % pathVerts.Count:i + 1; Vector3 pos = mat.MultiplyPoint3x4(pathVerts[i]); Vector3 posNext = mat.MultiplyPoint3x4(pathVerts[nextId]); Vector3 posStart = pos; bool isSelected = false; if (selectedPoints != null) { isSelected = selectedPoints.Contains(i); } float handleScale = HandleScale(posStart); Handles.DrawCapFunction cap = (isSelected || selectedPoints.Count <= 0) ? (Handles.DrawCapFunction)CapDotMinusSelected : (Handles.DrawCapFunction)CapDotMinus; if (Handles.Button(posStart, camTransform.rotation, handleScale, handleScale, cap)) { EnsureVertSelected(i, ref isSelected); deleteSelected = true; GUI.changed = true; } }
public static Vector3 DragHandle(Vector3 position, float handleSize, Handles.DrawCapFunction capFunc, Color colorSelected, out DragHandleResult result) { int id = GUIUtility.GetControlID(s_DragHandleHash, FocusType.Passive); lastDragHandleID = id; Vector3 screenPosition = Handles.matrix.MultiplyPoint(position); Matrix4x4 cachedMatrix = Handles.matrix; result = DragHandleResult.none; switch (Event.current.GetTypeForControl(id)) { case EventType.MouseDown: if (HandleUtility.nearestControl == id && (Event.current.button == 0 || Event.current.button == 1)) { GUIUtility.hotControl = id; s_DragHandleMouseCurrent = s_DragHandleMouseStart = Event.current.mousePosition; s_DragHandleWorldStart = position; s_DragHandleHasMoved = false; Event.current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); if (Event.current.button == 0) { result = DragHandleResult.LMBPress; } else if (Event.current.button == 1) { result = DragHandleResult.RMBPress; } } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (Event.current.button == 0 || Event.current.button == 1)) { // GUIUtility.hotControl = 0; Event.current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); if (Event.current.button == 0) { result = DragHandleResult.LMBRelease; } else if (Event.current.button == 1) { result = DragHandleResult.RMBRelease; } if (Event.current.mousePosition == s_DragHandleMouseStart) { bool doubleClick = (s_DragHandleClickID == id) && (Time.realtimeSinceStartup - s_DragHandleClickTime < s_DragHandleDoubleClickInterval); s_DragHandleClickID = id; s_DragHandleClickTime = Time.realtimeSinceStartup; if (Event.current.button == 0) { result = doubleClick ? DragHandleResult.LMBDoubleClick : DragHandleResult.LMBClick; } else if (Event.current.button == 1) { result = doubleClick ? DragHandleResult.RMBDoubleClick : DragHandleResult.RMBClick; } } } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { s_DragHandleMouseCurrent += new Vector2(Event.current.delta.x, -Event.current.delta.y); Vector3 position2 = Camera.current.WorldToScreenPoint(Handles.matrix.MultiplyPoint(s_DragHandleWorldStart)) + (Vector3)(s_DragHandleMouseCurrent - s_DragHandleMouseStart); position = Handles.matrix.inverse.MultiplyPoint(Camera.current.ScreenToWorldPoint(position2)); if (Camera.current.transform.forward == Vector3.forward || Camera.current.transform.forward == -Vector3.forward) { position.z = s_DragHandleWorldStart.z; } if (Camera.current.transform.forward == Vector3.up || Camera.current.transform.forward == -Vector3.up) { position.y = s_DragHandleWorldStart.y; } if (Camera.current.transform.forward == Vector3.right || Camera.current.transform.forward == -Vector3.right) { position.x = s_DragHandleWorldStart.x; } if (Event.current.button == 0) { result = DragHandleResult.LMBDrag; } else if (Event.current.button == 1) { result = DragHandleResult.RMBDrag; } s_DragHandleHasMoved = true; GUI.changed = true; Event.current.Use(); } break; case EventType.Repaint: Color currentColour = Handles.color; if (id == GUIUtility.hotControl && s_DragHandleHasMoved) { Handles.color = colorSelected; } Handles.matrix = Matrix4x4.identity; capFunc(id, screenPosition, Quaternion.identity, handleSize); Handles.matrix = cachedMatrix; Handles.color = currentColour; break; case EventType.Layout: Handles.matrix = Matrix4x4.identity; HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(screenPosition, handleSize)); Handles.matrix = cachedMatrix; break; } return(position); }
public static float AngularSlider(Vector3 position, Vector3 forward, Vector3 right, Vector3 up, float angle, float radius, Handles.DrawCapFunction capFunction, float offset = 0.0f, float handleSize = 1.0f) // Create an angular slider for the given transform { Vector3 angleVector = PlanarAngleVector(forward, right, angle) * radius; Vector3 directionVector = Vector3.Cross(angleVector, up) * -1; Vector3 sliderPosition = position + angleVector + angleVector.normalized * offset; Vector3 changeVector = Handles.Slider(sliderPosition, directionVector, handleSize, capFunction, 1.0f) - sliderPosition; return(angle + (Vector3.Angle(directionVector, changeVector) > 90.0f ? changeVector.magnitude * -1.0f : changeVector.magnitude)); }
public static Vector3 TinyHandle2D(int id, Vector3 pos, Vector3 forward, Vector3 up, Vector3 right, float size, Handles.DrawCapFunction func = null) #endif { return(Handles.Slider2D(id, pos, forward, up, right, HandleUtility.GetHandleSize(pos) * size, func, SnapSettings.Move)); }
public static Vector3 TinyHandle2D(int id, Transform transform, float size, Handles.DrawCapFunction func = null) #endif { return(TinyHandle2D(id, transform.position, transform.forward, transform.up, transform.right, size, func)); }
public static Vector3 TinyHandle2D(int id, Vector3 position, Quaternion rotation, float size, Handles.DrawCapFunction func = null) #endif { return(TinyHandle2D(id, position, rotation * Vector3.forward, rotation * Vector3.up, rotation * Vector3.right, size, func)); }
public static bool Button(int id, Vector3 position, Quaternion direction, float size, float pickSize, bool useHandleSize, Handles.DrawCapFunction capFunc, Color hoverCol, out bool isHovering) #endif { Event current = Event.current; isHovering = false; if (useHandleSize) { float s = HandleUtility.GetHandleSize(position); size *= s; pickSize *= s; } switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (HandleUtility.nearestControl == id) { GUIUtility.hotControl = id; current.Use(); } break; case EventType.MouseUp: if ((current.button == 0 || current.button == 2) && GUIUtility.hotControl == id) { GUIUtility.hotControl = 0; current.Use(); if (HandleUtility.nearestControl == id) { return(true); } } break; case EventType.MouseMove: if ((HandleUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2)) { HandleUtility.Repaint(); } break; case EventType.Repaint: { Color color = Handles.color; if (HandleUtility.nearestControl == id && GUI.enabled) { isHovering = true; Handles.color = hoverCol; } #if UNITY_5_6_OR_NEWER capFunc(id, position, Quaternion.identity, size, EventType.Repaint); #else capFunc(id, position, direction, size); #endif Handles.color = color; break; } case EventType.Layout: if (GUI.enabled) { HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, pickSize)); } break; } return(false); }
//static bool s_DragHandleHasMoved; public static Vector3 DragHandle <K>(Vector3 position, float handleSize, Handles.DrawCapFunction capFunc, Color colorSelected, string label, K userData, EditorGUILayoutEx.EventCallback <K> onEvent, GUIContent[] displayOptions = null, IList <K> values = null, EditorGUILayoutEx.MenuCallback <K> onSelection = null) { int id = GUIUtility.GetControlID(HANDLESEX_HASH, FocusType.Passive); Vector3 screenPosition = Handles.matrix.MultiplyPoint(position); Matrix4x4 cachedMatrix = Handles.matrix; switch (Event.current.GetTypeForControl(id)) { case EventType.KeyDown: if (GUIUtility.hotControl == id) { if (onEvent != null) { onEvent(id, Event.current, userData); } } break; case EventType.MouseDown: if (HandleUtility.nearestControl == id && (Event.current.button == 0 || Event.current.button == 1)) { GUIUtility.hotControl = id; MOUSE_POS_CURRENT = MOUSE_POS_AT_START = Event.current.mousePosition; HANDLE_POS_WORLD = position; //s_DragHandleHasMoved = false; //Event.current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); if (Event.current.type == EventType.ContextClick && displayOptions != null && values != null) { // Now create the menu, add items and show it GenericMenu menu = new GenericMenu(); GUIContent content; int len = displayOptions.Length; for (int i = 0; i < len; i++) { content = displayOptions [i]; // null mean AddSeparator if (content == null) { menu.AddSeparator(""); } // "*" at the end => mean AddDisabledItem else if (content.text.LastIndexOf('*', content.text.Length - 1) > -1) { content.text = content.text.Remove(content.text.Length - 1); menu.AddDisabledItem(content); } else { menu.AddItem(content, false, (obj) => { int inx = (int)obj; //dispatch selected if (onSelection != null) { onSelection(inx, values [inx], id); } }, i); } } menu.ShowAsContext(); } if (onEvent != null) { onEvent(id, Event.current, userData); } } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (Event.current.button == 0 || Event.current.button == 1)) { //GUIUtility.hotControl = 0; //Event.current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); if (onEvent != null) { onEvent(id, Event.current, userData); } } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { MOUSE_POS_CURRENT += new Vector2(Event.current.delta.x, -Event.current.delta.y); Vector3 position2 = Camera.current.WorldToScreenPoint(Handles.matrix.MultiplyPoint(HANDLE_POS_WORLD)) + (Vector3)(MOUSE_POS_CURRENT - MOUSE_POS_AT_START); position = Handles.matrix.inverse.MultiplyPoint(Camera.current.ScreenToWorldPoint(position2)); if (Camera.current.transform.forward == Vector3.forward || Camera.current.transform.forward == -Vector3.forward) { position.z = HANDLE_POS_WORLD.z; } if (Camera.current.transform.forward == Vector3.up || Camera.current.transform.forward == -Vector3.up) { position.y = HANDLE_POS_WORLD.y; } if (Camera.current.transform.forward == Vector3.right || Camera.current.transform.forward == -Vector3.right) { position.x = HANDLE_POS_WORLD.x; } if (onEvent != null) { onEvent(id, Event.current, userData); } //s_DragHandleHasMoved = true; GUI.changed = true; //Event.current.Use(); } break; case EventType.Repaint: Color currentColour = Handles.color; //if (id == GUIUtility.hotControl && s_DragHandleHasMoved) if (id == GUIUtility.hotControl) { Handles.color = colorSelected; } Handles.matrix = Matrix4x4.identity; capFunc(id, screenPosition, Quaternion.identity, handleSize); Handles.matrix = cachedMatrix; Handles.color = currentColour; Handles.Label(position + Vector3.up, label); break; case EventType.Layout: Handles.matrix = Matrix4x4.identity; HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(screenPosition, handleSize)); Handles.matrix = cachedMatrix; break; } return(position); }
public static float AngleSlider(Vector3 centrP, Vector3 normalV, Vector3 forward, float prevAngle, float radius, Handles.DrawCapFunction capF, bool horizontal, Quaternion rot) { int controlId = GUIUtility.GetControlID(FocusType.Passive); Vector3 startPos = Quaternion.AngleAxis(prevAngle, normalV) * (forward * radius) + centrP; float controlSize = HandleUtility.GetHandleSize(startPos) / 5.0f; float newAngle = prevAngle; switch (Event.current.GetTypeForControl(controlId)) { // Cause mouse dragging case EventType.MouseDrag: if (GUIUtility.hotControl == controlId) { Plane raycastablePlane = new Plane(normalV, centrP); float dist = 0f; Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); ray.origin = Handles.matrix.inverse.MultiplyPoint3x4(ray.origin); ray.direction = Handles.matrix.inverse.MultiplyVector(ray.direction); raycastablePlane.Raycast(ray, out dist); Vector3 closestPoint = ray.GetPoint(dist); Vector3 direction = closestPoint - centrP; newAngle = Vector3.Angle(forward, direction); if (horizontal) { if (Vector3.Cross(forward, direction).y < 0) { if (prevAngle < 90f) { newAngle = -newAngle; } else { newAngle = 360 - Mathf.Abs(newAngle); } } else { if (prevAngle < -120f) { newAngle = -180 - (180 - newAngle); } else if (prevAngle > 330f) { newAngle = newAngle + 360f; } } } else { if (Vector3.Cross(forward, direction).x < 0) { if (prevAngle < 90f) { newAngle = -newAngle; } else { newAngle = 360 - Mathf.Abs(newAngle); } } else { if (prevAngle < -130f) { newAngle = -180 - (180 - newAngle); } } } GUI.changed = true; Event.current.Use(); } break; case EventType.Layout: HandleUtility.AddControl(controlId, HandleUtility.DistanceToCircle(startPos, controlSize)); break; case EventType.Repaint: Color oldCol = Handles.color; if (GUIUtility.hotControl == controlId) { Handles.color = Color.yellow; } if (!horizontal) { Vector3 rot2 = rot.eulerAngles; rot2.z += 90f; capF(controlId, startPos, Quaternion.Euler(rot2), controlSize); } else { capF(controlId, startPos, rot, controlSize); } Handles.color = oldCol; break; case EventType.MouseDown: if ((HandleUtility.nearestControl == controlId) && (Event.current.button == 0)) { GUIUtility.hotControl = controlId; Event.current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlId) { GUIUtility.hotControl = 0; Event.current.Use(); } break; } return(newAngle); }
public override void OnSceneGUI(NavGraph target) { Event e = Event.current; var graph = target as GridGraph; Matrix4x4 matrixPre = graph.matrix; graph.GenerateMatrix(); if (e.type == EventType.MouseDown) { isMouseDown = true; } else if (e.type == EventType.MouseUp) { isMouseDown = false; } if (!isMouseDown) { savedMatrix = graph.boundsMatrix; } Handles.matrix = savedMatrix; if ((graph is GridGraph && graph.nodes == null) || (graph.uniformWidthDepthGrid && graph.depth * graph.width != graph.nodes.Length) || graph.matrix != matrixPre) { //Rescan the graphs if (AutoScan()) { GUI.changed = true; } } Matrix4x4 inversed = savedMatrix.inverse; Handles.color = AstarColor.BoundsHandles; Handles.DrawCapFunction cap = Handles.CylinderCap; Vector2 extents = graph.unclampedSize * 0.5F; Vector3 center = inversed.MultiplyPoint3x4(graph.center); if (Tools.current == Tool.Scale) { const float HandleScale = 0.1f; EditorGUI.BeginChangeCheck(); Vector3 p1 = Handles.Slider(center + new Vector3(extents.x, 0, 0), Vector3.right, HandleScale * HandleUtility.GetHandleSize(center + new Vector3(extents.x, 0, 0)), cap, 0); Vector3 p2 = Handles.Slider(center + new Vector3(0, 0, extents.y), Vector3.forward, HandleScale * HandleUtility.GetHandleSize(center + new Vector3(0, 0, extents.y)), cap, 0); Vector3 p4 = Handles.Slider(center + new Vector3(-extents.x, 0, 0), -Vector3.right, HandleScale * HandleUtility.GetHandleSize(center + new Vector3(-extents.x, 0, 0)), cap, 0); Vector3 p5 = Handles.Slider(center + new Vector3(0, 0, -extents.y), -Vector3.forward, HandleScale * HandleUtility.GetHandleSize(center + new Vector3(0, 0, -extents.y)), cap, 0); Vector3 p6 = Handles.Slider(center, Vector3.up, HandleScale * HandleUtility.GetHandleSize(center), cap, 0); var r1 = new Vector3(p1.x, p6.y, p2.z); var r2 = new Vector3(p4.x, p6.y, p5.z); if (EditorGUI.EndChangeCheck()) { graph.center = savedMatrix.MultiplyPoint3x4((r1 + r2) / 2F); Vector3 tmp = r1 - r2; graph.unclampedSize = new Vector2(tmp.x, tmp.z); } } else if (Tools.current == Tool.Move) { if (Tools.pivotRotation == PivotRotation.Local) { EditorGUI.BeginChangeCheck(); center = Handles.PositionHandle(center, Quaternion.identity); if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit) { graph.center = savedMatrix.MultiplyPoint3x4(center); } } else { Handles.matrix = Matrix4x4.identity; EditorGUI.BeginChangeCheck(); center = Handles.PositionHandle(graph.center, Quaternion.identity); if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit) { graph.center = center; } } } else if (Tools.current == Tool.Rotate) { //The rotation handle doesn't seem to be able to handle different matrixes of some reason Handles.matrix = Matrix4x4.identity; EditorGUI.BeginChangeCheck(); var rot = Handles.RotationHandle(Quaternion.Euler(graph.rotation), graph.center); if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit) { graph.rotation = rot.eulerAngles; } } Handles.matrix = Matrix4x4.identity; }
internal static Vector3 Do(int id, Vector3 position, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.DrawCapFunction drawFunc, float snap) { Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if ((((HandleUtility.nearestControl == id) && (current.button == 0)) || ((GUIUtility.keyboardControl == id) && (current.button == 2))) && (GUIUtility.hotControl == 0)) { int num = id; GUIUtility.keyboardControl = num; GUIUtility.hotControl = num; s_CurrentMousePosition = s_StartMousePosition = current.mousePosition; s_StartPosition = position; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); } return position; case EventType.MouseUp: if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2))) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } return position; case EventType.MouseMove: case EventType.KeyDown: case EventType.KeyUp: case EventType.ScrollWheel: return position; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { s_CurrentMousePosition += current.delta; float num2 = Handles.SnapValue(HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, slideDirection), snap); Vector3 vector = Handles.matrix.MultiplyVector(slideDirection); Vector3 v = Handles.s_Matrix.MultiplyPoint(s_StartPosition) + ((Vector3) (vector * num2)); position = Handles.s_InverseMatrix.MultiplyPoint(v); GUI.changed = true; current.Use(); } return position; case EventType.Repaint: { Color white = Color.white; if ((id == GUIUtility.keyboardControl) && GUI.enabled) { white = Handles.color; Handles.color = Handles.selectedColor; } drawFunc(id, position, Quaternion.LookRotation(handleDirection), size); if (id == GUIUtility.keyboardControl) { Handles.color = white; } return position; } case EventType.Layout: if (<>f__mg$cache0 == null) { <>f__mg$cache0 = new Handles.DrawCapFunction(Handles.ArrowCap); }
private static Vector2 CalcDeltaAlongDirections(int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.DrawCapFunction drawFunc, Vector2 snap, bool drawHelper) { Vector2 vector = new Vector2(0f, 0f); Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if ((((HandleUtility.nearestControl == id) && (current.button == 0)) || ((GUIUtility.keyboardControl == id) && (current.button == 2))) && (GUIUtility.hotControl == 0)) { Plane plane = new Plane(Handles.matrix.MultiplyVector(handleDir), Handles.matrix.MultiplyPoint(handlePos)); Ray ray = HandleUtility.GUIPointToWorldRay(current.mousePosition); float enter = 0f; plane.Raycast(ray, out enter); int num2 = id; GUIUtility.keyboardControl = num2; GUIUtility.hotControl = num2; s_CurrentMousePosition = current.mousePosition; s_StartPosition = handlePos; Vector3 lhs = Handles.s_InverseMatrix.MultiplyPoint(ray.GetPoint(enter)) - handlePos; s_StartPlaneOffset.x = Vector3.Dot(lhs, slideDir1); s_StartPlaneOffset.y = Vector3.Dot(lhs, slideDir2); current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); } return vector; case EventType.MouseUp: if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2))) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } return vector; case EventType.MouseMove: case EventType.KeyDown: case EventType.KeyUp: case EventType.ScrollWheel: return vector; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { s_CurrentMousePosition += current.delta; Vector3 a = Handles.matrix.MultiplyPoint(handlePos); Vector3 normalized = Handles.matrix.MultiplyVector(slideDir1).normalized; Vector3 vector7 = Handles.matrix.MultiplyVector(slideDir2).normalized; Ray ray2 = HandleUtility.GUIPointToWorldRay(s_CurrentMousePosition); Plane plane2 = new Plane(a, a + normalized, a + vector7); float num3 = 0f; if (plane2.Raycast(ray2, out num3)) { Vector3 point = Handles.s_InverseMatrix.MultiplyPoint(ray2.GetPoint(num3)); vector.x = HandleUtility.PointOnLineParameter(point, s_StartPosition, slideDir1); vector.y = HandleUtility.PointOnLineParameter(point, s_StartPosition, slideDir2); vector -= s_StartPlaneOffset; if ((snap.x > 0f) || (snap.y > 0f)) { vector.x = Handles.SnapValue(vector.x, snap.x); vector.y = Handles.SnapValue(vector.y, snap.y); } GUI.changed = true; } current.Use(); } return vector; case EventType.Repaint: if (drawFunc != null) { Vector3 position = handlePos + offset; Quaternion rotation = Quaternion.LookRotation(handleDir, slideDir1); Color white = Color.white; if (id == GUIUtility.keyboardControl) { white = Handles.color; Handles.color = Handles.selectedColor; } drawFunc(id, position, rotation, handleSize); if (id == GUIUtility.keyboardControl) { Handles.color = white; } if (drawHelper && (GUIUtility.hotControl == id)) { Vector3[] verts = new Vector3[4]; float num4 = handleSize * 10f; verts[0] = position + ((Vector3) ((slideDir1 * num4) + (slideDir2 * num4))); verts[1] = verts[0] - ((Vector3) ((slideDir1 * num4) * 2f)); verts[2] = verts[1] - ((Vector3) ((slideDir2 * num4) * 2f)); verts[3] = verts[2] + ((Vector3) ((slideDir1 * num4) * 2f)); Color color = Handles.color; Handles.color = Color.white; float r = 0.6f; Handles.DrawSolidRectangleWithOutline(verts, new Color(1f, 1f, 1f, 0.05f), new Color(r, r, r, 0.4f)); Handles.color = color; } return vector; } return vector; case EventType.Layout: if (<>f__mg$cache0 == null) { <>f__mg$cache0 = new Handles.DrawCapFunction(Handles.ArrowCap); }