// Returns the new handlePos public static Vector3 Do( int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.CapFunction capFunction, float snap, bool drawHelper) { return(Do(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, capFunction, new Vector2(snap, snap), drawHelper)); }
public void ShowPointFreeMoveHandles() { foreach (var e in cm.designerNode) { Handles.color = Color.green; Handles.CapFunction customfunc = Handles.SphereHandleCap; customfunc += HandleRecorder.RecordHandles; e.site = Handles.FreeMoveHandle(e.site, Quaternion.identity, .25f, Vector3.zero, customfunc); HandleRecorder.CheckID(e); Handles.DrawWireDisc(e.site, Vector3.up, .5f); var newstyle = new GUIStyle(); newstyle.fontSize = 10; Handles.Label(e.site, e.id.ToString(), newstyle); } }
private static float SizeHandle(Vector3 localPos, Vector3 localPullDir, Matrix4x4 matrix, bool isEdgeHandle) { Vector3 vector = matrix.MultiplyVector(localPullDir); Vector3 vector2 = matrix.MultiplyPoint(localPos); float handleSize = HandleUtility.GetHandleSize(vector2); bool changed = GUI.changed; GUI.changed = false; Color color = Handles.color; float num = 0f; if (isEdgeHandle) { num = Mathf.Cos(0.7853982f); } float num2; if (Camera.current.orthographic) { num2 = Vector3.Dot(-Camera.current.transform.forward, vector); } else { num2 = Vector3.Dot((Camera.current.transform.position - vector2).normalized, vector); } if (num2 < -num) { Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, Handles.color.a * Handles.backfaceAlphaMultiplier); } Vector3 arg_119_0 = vector2; Vector3 arg_119_1 = vector; float arg_119_2 = handleSize * 0.03f; if (CharacterControllerEditor.< > f__mg$cache0 == null) { CharacterControllerEditor.< > f__mg$cache0 = new Handles.CapFunction(Handles.DotHandleCap); } Vector3 point = Handles.Slider(arg_119_0, arg_119_1, arg_119_2, CharacterControllerEditor.< > f__mg$cache0, 0f); float result = 0f; if (GUI.changed) { result = HandleUtility.PointOnLineParameter(point, vector2, vector); } GUI.changed |= changed; Handles.color = color; return(result); }
public static Rect ResizeRect(Rect rect, Handles.CapFunction capFunc, Color capCol, Color fillCol, float capSize, float snap) { Vector2 halfRectSize = new Vector2(rect.size.x * 0.5f, rect.size.y * 0.5f); Vector3[] rectangleCorners = { new Vector3(rect.position.x - halfRectSize.x, rect.position.y - halfRectSize.y, 0), // Bottom Left new Vector3(rect.position.x + halfRectSize.x, rect.position.y - halfRectSize.y, 0), // Bottom Right new Vector3(rect.position.x + halfRectSize.x, rect.position.y + halfRectSize.y, 0), // Top Right new Vector3(rect.position.x - halfRectSize.x, rect.position.y + halfRectSize.y, 0) // Top Left }; Handles.color = fillCol; Handles.DrawSolidRectangleWithOutline(rectangleCorners, new Color(fillCol.r, fillCol.g, fillCol.b, 0.25f), capCol); Vector3[] handlePoints = { new Vector3(rect.position.x - halfRectSize.x, rect.position.y, 0), // Left new Vector3(rect.position.x + halfRectSize.x, rect.position.y, 0), // Right new Vector3(rect.position.x, rect.position.y + halfRectSize.y, 0), // Top new Vector3(rect.position.x, rect.position.y - halfRectSize.y, 0) // Bottom }; Handles.color = capCol; var newSize = rect.size; var newPosition = rect.position; var leftHandle = Handles.Slider(handlePoints[0], -Vector3.right, capSize, capFunc, snap).x - handlePoints[0].x; var rightHandle = Handles.Slider(handlePoints[1], Vector3.right, capSize, capFunc, snap).x - handlePoints[1].x; var topHandle = Handles.Slider(handlePoints[2], Vector3.up, capSize, capFunc, snap).y - handlePoints[2].y; var bottomHandle = Handles.Slider(handlePoints[3], -Vector3.up, capSize, capFunc, snap).y - handlePoints[3].y; newSize = new Vector2( Mathf.Max(.1f, newSize.x - leftHandle + rightHandle), Mathf.Max(.1f, newSize.y + topHandle - bottomHandle)); newPosition = new Vector2( newPosition.x + leftHandle * .5f + rightHandle * .5f, newPosition.y + topHandle * .5f + bottomHandle * .5f); newPosition = Handles.FreeMoveHandle(newPosition, Quaternion.identity, capSize, new Vector3(newSize.x, newSize.y, 0.1f), capFunc); return(new Rect(newPosition.x, newPosition.y, newSize.x, newSize.y)); }
void Draw() { Handles.matrix = creator.transform.localToWorldMatrix; var rot = Tools.pivotRotation == PivotRotation.Local ? creator.transform.rotation : Quaternion.identity; var snap = Vector2.zero; Handles.CapFunction cap = Handles.CylinderHandleCap; for (int i = 0; i < path.NumPoints; i++) { var pos = path[i].position; var size = .1f; Handles.color = Color.red; Vector2 newPos = Handles.FreeMoveHandle(pos, rot, size, snap, cap); if (pos != newPos) { Undo.RecordObject(creator, "Move point position"); path.MovePoint(i, newPos); } pos = newPos; if (path.loop || i != 0) { var tanBack = pos + path[i].tangentBack; Handles.color = Color.black; Handles.DrawLine(pos, tanBack); Handles.color = Color.red; Vector2 newTanBack = Handles.FreeMoveHandle(tanBack, rot, size, snap, cap); if (tanBack != newTanBack) { Undo.RecordObject(creator, "Move point tangent"); path.MoveTangentBack(i, newTanBack - pos); } } if (path.loop || i != path.NumPoints - 1) { var tanFront = pos + path[i].tangentFront; Handles.color = Color.black; Handles.DrawLine(pos, tanFront); Handles.color = Color.red; Vector2 newTanFront = Handles.FreeMoveHandle(tanFront, rot, size, snap, cap); if (tanFront != newTanFront) { Undo.RecordObject(creator, "Move point tangent"); path.MoveTangentFront(i, newTanFront - pos); } } } }
private static void ShowPointTypeMode(Path2D aPathRaw, int aIndex, Selection aSelection, Matrix4x4 aTransform, Matrix4x4 aInvTransform, SerializedProperty aPath, Path2D.Plane aPlane, PathEditorVisuals aVisuals) { Handles.color = aVisuals.colorHandle * _activeHandleTint; Handles.CapFunction cap = aVisuals.capVertex; if (aVisuals.capVertexTypes != null) { cap = aVisuals.capVertexTypes[(int)aPathRaw.GetControls(aIndex).type]; } Vector3 v = aTransform.MultiplyPoint3x4(Plane(aPathRaw[aIndex], aPlane)); EditorGUIUtility.AddCursorRect(new Rect(0, 0, Screen.width, Screen.height), MouseCursor.RotateArrow); if (Handles.Button(v, SceneView.lastActiveSceneView.camera.transform.rotation, HandleUtility.GetHandleSize(v) * aVisuals.sizeVertexMode, HandleUtility.GetHandleSize(v) * aVisuals.sizeVertexMode, cap)) { PointType t = aPathRaw.GetControls(aIndex).type; if (t == PointType.Auto) { t = PointType.Locked; } else if (t == PointType.Free) { t = PointType.Locked; } else if (t == PointType.Locked) { t = PointType.CircleCorner; } else if (t == PointType.CircleCorner) { t = PointType.Sharp; } else if (t == PointType.Sharp) { t = PointType.Auto; } SerializedProperty pointControls = aPath.FindPropertyRelative("_pointControls"); aSelection.Each(aIndex, i => pointControls.GetArrayElementAtIndex(i).FindPropertyRelative("type").enumValueIndex = (int)t); _recentInteract = aIndex; GUI.changed = true; } }
public void ShowAreaFreeMoveHandles() { foreach (var e in cm.designerArea) { Handles.color = Color.green; Handles.CapFunction customfunc = Handles.CubeHandleCap; customfunc += HandleRecorder.RecordHandles; e.start = Handles.FreeMoveHandle(e.start, Quaternion.identity, .5f, Vector3.zero, customfunc); HandleRecorder.CheckID(e); e.end = Handles.FreeMoveHandle(e.end, Quaternion.identity, .5f, Vector3.zero, customfunc); HandleRecorder.CheckID(e); MapAux.DrawRectHandles(e.start, e.end); var newstyle = new GUIStyle(); newstyle.fontSize = 10; Handles.Label((e.start + e.end) / 2, e.id.ToString(), newstyle); } }
public static void ResizeRect(RectTransform rt, Handles.CapFunction capFunction, Color capColor, float capSize, float snap) { rt.localRotation = Quaternion.Euler(0, 0, 0); rt.localScale = new Vector3(1, 1, 1); Vector3 halfRectSize = new Vector3(rt.sizeDelta.x * 0.5f, rt.sizeDelta.y * 0.5f, 0); Vector3[] rectCorners = new Vector3[4]; rt.GetWorldCorners(rectCorners); Vector3[] handlePoints = { new Vector3(rectCorners[0].x, rectCorners[0].y + halfRectSize.y, 0), // Left new Vector3(rectCorners[0].x + rt.sizeDelta.x, rectCorners[0].y + +halfRectSize.y, 0), // Right new Vector3(rectCorners[0].x + halfRectSize.x, rectCorners[0].y + rt.sizeDelta.y, 0), // Top new Vector3(rectCorners[0].x + halfRectSize.x, rectCorners[0].y, 0), // Bottom new Vector3(rectCorners[0].x + halfRectSize.x, rectCorners[0].y + halfRectSize.y, 0), // Center }; Handles.color = capColor; Vector2 newSize = rt.sizeDelta; Vector3 newPosition = rt.localPosition; float leftHandle = Handles.Slider(handlePoints[0], -Vector3.right, capSize, capFunction, snap).x - handlePoints[0].x; float rightHandle = Handles.Slider(handlePoints[1], Vector3.right, capSize, capFunction, snap).x - handlePoints[1].x; float topHandle = Handles.Slider(handlePoints[2], Vector3.up, capSize, capFunction, snap).y - handlePoints[2].y; float bottomHandle = Handles.Slider(handlePoints[3], -Vector3.up, capSize, capFunction, snap).y - handlePoints[3].y; Vector3 positionHandle = Handles.FreeMoveHandle(handlePoints[4], Quaternion.identity, capSize * 1.2f, Vector3.one, Handles.SphereHandleCap); Vector3 bottomLeftHandle = Handles.FreeMoveHandle(rectCorners[0], Quaternion.identity, capSize, Vector3.one, capFunction); Vector3 bottomRightHandle = Handles.FreeMoveHandle(rectCorners[3], Quaternion.identity, capSize, Vector3.one, capFunction); Vector3 topLeftHandle = Handles.FreeMoveHandle(rectCorners[1], Quaternion.identity, capSize, Vector3.one, capFunction); Vector3 topRightHandle = Handles.FreeMoveHandle(rectCorners[2], Quaternion.identity, capSize, Vector3.one, capFunction); float sizeXFactor = (bottomRightHandle.x - newSize.x - rectCorners[0].x) + (topRightHandle.x - newSize.x - rectCorners[0].x) - (bottomLeftHandle.x - rectCorners[0].x) - (topLeftHandle.x - rectCorners[0].x); float sizeYFactor = (topLeftHandle.y - newSize.y - rectCorners[0].y) + (topRightHandle.y - newSize.y - rectCorners[0].y) - (bottomLeftHandle.y - rectCorners[0].y) - (bottomRightHandle.y - rectCorners[3].y); newSize = new Vector2(Mathf.Max(2.1f, newSize.x - leftHandle + rightHandle + sizeXFactor), Mathf.Max(2.1f, newSize.y + topHandle - bottomHandle + sizeYFactor)); Vector3 positionFactor = (positionHandle - handlePoints[4]) + (bottomLeftHandle - rectCorners[0]) + new Vector3(topLeftHandle.x - rectCorners[1].x, 0, 0) + new Vector3(0, bottomRightHandle.y - rectCorners[3].y, 0); newPosition = new Vector2(newPosition.x + leftHandle + positionFactor.x, newPosition.y + bottomHandle + positionFactor.y); rt.sizeDelta = newSize; rt.localPosition = newPosition; }
private void OnSceneGUI() { float penSize = HandleUtility.GetHandleSize(spawner.transform.position) * 0.25f; Handles.CapFunction capFunction = Handles.SphereHandleCap; foreach (var index in Enumerable.Range(0, spawner.spawnPosition.Count)) { Vector2 newPos = Handles.FreeMoveHandle(spawner.spawnPosition[index], Quaternion.identity, penSize, Vector3.one, capFunction); if (spawner.spawnPosition[index] != newPos) { Undo.RecordObject(spawner, "Move point"); spawner.spawnPosition[index] = newPos; } } }
protected bool HandleAnchor(ref Vector3 position, bool isConnectedAnchor) { if (anchor == null) { anchor = "U2D.pivotDot"; anchorActive = "U2D.pivotDotActive"; connectedAnchor = "U2D.dragDot"; connectedAnchorActive = "U2D.dragDotActive"; } Handles.CapFunction drawFunc = (!isConnectedAnchor) ? new Handles.CapFunction(AnchorCap) : new Handles.CapFunction(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 static Vector3 PivotHandleGUI(Rect rect, Vector3 pivot, Quaternion rotation) { int controlID = GUIUtility.GetControlID(RectTool.s_PivotHandleHash, FocusType.Passive); EventType typeForControl = Event.current.GetTypeForControl(controlID); if (GUI.color.a > 0f || GUIUtility.hotControl == controlID) { EventType eventType = typeForControl; EditorGUI.BeginChangeCheck(); int arg_94_0 = controlID; Vector3 arg_94_1 = pivot; Vector3 arg_94_2 = rotation * Vector3.forward; Vector3 arg_94_3 = rotation * Vector3.right; Vector3 arg_94_4 = rotation * Vector3.up; float arg_94_5 = HandleUtility.GetHandleSize(pivot) * 0.1f; if (RectTool.< > f__mg$cache1 == null) { RectTool.< > f__mg$cache1 = new Handles.CapFunction(RectHandles.PivotHandleCap); } Vector3 a = Handles.Slider2D(arg_94_0, arg_94_1, arg_94_2, arg_94_3, arg_94_4, arg_94_5, RectTool.< > f__mg$cache1, Vector2.zero); if (eventType == EventType.MouseDown && GUIUtility.hotControl == controlID) { RectTransformSnapping.CalculatePivotSnapValues(rect, pivot, rotation); } if (EditorGUI.EndChangeCheck()) { Vector2 vector = Quaternion.Inverse(rotation) * (a - pivot); vector.x /= rect.width; vector.y /= rect.height; Vector2 vector2 = new Vector2(-rect.x / rect.width, -rect.y / rect.height); Vector2 vector3 = vector2 + vector; Vector2 snapDistance = HandleUtility.GetHandleSize(pivot) * 0.05f * new Vector2(1f / rect.width, 1f / rect.height); vector3 = RectTransformSnapping.SnapToGuides(vector3, snapDistance); vector = vector3 - vector2; vector.x *= rect.width; vector.y *= rect.height; pivot += rotation * vector; } } ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPivot", typeForControl); return(pivot); }
public static void DrawPointSceneGUI(BezierPoint point, Handles.CapFunction drawPointFunc, Handles.CapFunction 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) * BezierPointEditor.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) * BezierPointEditor.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) * BezierPointEditor.handleCapSize, Vector3.zero, drawHandleFunc); if (point.RightHandlePosition != newRightHandlePosition) { Undo.RegisterCompleteObjectUndo(point, "Move Right Handle"); point.RightHandlePosition = newRightHandlePosition; } }
private void DrawCap(int i, Vector3 position, float boneSize, Color color, Handles.CapFunction cap) { if (selected == i) { Handles.color = tabOption.colorSelected; } else { Handles.color = color; } PSHandles.DragHandleResult dhResult = PSHandles.DragHandleResult.none; PSHandles.DragHandle(position, boneSize, cap, Handles.color, out dhResult); switch (dhResult) { case PSHandles.DragHandleResult.LMBClick: selected = i; break; } }
// Returns the new handlePos public static Vector3 Do( int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.CapFunction capFunction, Vector2 snap, bool drawHelper) { bool orgGuiChanged = GUI.changed; GUI.changed = false; Vector2 delta = CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, capFunction, 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); }
/*void OnSceneGUI () * { * Handles.BeginGUI (); * var tg = (MovingObject)target; * * var rect = ResizeRect ( * tg.Bounds, * Handles.CubeHandleCap, * Color.green, * Color.yellow, * HandleUtility.GetHandleSize (tg.transform.position), * .1f); * * tg.Bounds = rect; * Handles.EndGUI (); * }*/ static Rect ResizeRect(Rect rect, Handles.CapFunction capFunc, Color capCol, Color fillCol, float capSize, float snap) { Vector3[] rectangleCorners = { new Vector3(rect.min.x, rect.min.y, 0), // Bottom Left new Vector3(rect.max.x, rect.min.y, 0), // Bottom Right new Vector3(rect.max.x, rect.max.y, 0), // Top Right new Vector3(rect.min.x, rect.max.y, 0) // Top Left }; Handles.color = fillCol; Handles.DrawSolidRectangleWithOutline(rectangleCorners, new Color(fillCol.r, fillCol.g, fillCol.b, 0.25f), capCol); Vector3[] handlePoints = { new Vector3(rect.min.x, rect.center.y, 0), // Left new Vector3(rect.max.x, rect.center.y, 0), // Right new Vector3(rect.center.x, rect.min.y, 0), // Bottom new Vector3(rect.center.x, rect.max.y, 0) // Top }; Handles.color = capCol; Vector3 leftHandle = Handles.Slider(handlePoints[0], Vector3.right, capSize, capFunc, snap); leftHandle.x = Mathf.Min(leftHandle.x, handlePoints[1].x - 0.1f); Vector3 rightHandle = Handles.Slider(handlePoints[1], Vector3.right, capSize, capFunc, snap); rightHandle.x = Mathf.Max(rightHandle.x, handlePoints[0].x + 0.1f); Vector3 bottomHandle = Handles.Slider(handlePoints[2], Vector3.up, capSize, capFunc, snap); bottomHandle.y = Mathf.Min(bottomHandle.y, handlePoints[3].y - 0.1f); Vector3 topHandle = Handles.Slider(handlePoints[3], Vector3.up, capSize, capFunc, snap); topHandle.y = Mathf.Max(topHandle.y, handlePoints[2].y + 0.1f); return(Rect.MinMaxRect(leftHandle.x, bottomHandle.y, rightHandle.x, topHandle.y)); }
private void SetButtonPositionHandle(int index, Quaternion handleRotation, Handles.CapFunction cap, Color color) { var point = _spline.GetPointTransformed(index, _self.transform); if (EditorApplication.isPlaying) { point = _spline.GetPoint(index); } var size = HandleUtility.GetHandleSize(point) * 4; Handles.color = color; if (Handles.Button(point, handleRotation, size * _handleSize, size * _pickSize, cap)) { _selectedIndex = index; Repaint(); } if (_selectedIndex != index) { return; } EditorGUI.BeginChangeCheck(); point = Handles.PositionHandle(point, handleRotation); if (!EditorGUI.EndChangeCheck()) { return; } Undo.RecordObject(_self, "Move Point"); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); EditorUtility.SetDirty(_self); _spline.SetTransformedPoint(_selectedIndex, point, _self.transform); }
private void OnSceneGUI() { Tree target = base.target as Tree; TreeData treeData = GetTreeData(target); if (treeData != null) { this.VerifySelection(treeData); if (s_SelectedGroup != null) { this.OnCheckHotkeys(treeData, true); Transform transform = target.transform; Matrix4x4 localToWorldMatrix = target.transform.localToWorldMatrix; Event current = Event.current; if (s_SelectedGroup.GetType() == typeof(TreeGroupRoot)) { Tools.s_Hidden = false; Handles.color = s_NormalColor; Handles.DrawWireDisc(transform.position, transform.up, treeData.root.rootSpread); } else { Tools.s_Hidden = true; Handles.color = Handles.secondaryColor; Handles.DrawWireDisc(transform.position, transform.up, treeData.root.rootSpread); } if ((s_SelectedGroup != null) && (s_SelectedGroup.GetType() == typeof(TreeGroupBranch))) { EventType rawType = current.type; if ((current.type == EventType.Ignore) && (current.rawType == EventType.MouseUp)) { rawType = current.rawType; } Handles.DrawLine(Vector3.zero, Vector3.zero); HandleUtility.ApplyWireMaterial(); GL.Begin(1); for (int i = 0; i < s_SelectedGroup.nodeIDs.Length; i++) { TreeNode node = treeData.GetNode(s_SelectedGroup.nodeIDs[i]); TreeSpline spline = node.spline; if (spline != null) { Handles.color = (node != s_SelectedNode) ? s_GroupColor : s_NormalColor; Matrix4x4 matrixx2 = localToWorldMatrix * node.matrix; Vector3 v = matrixx2.MultiplyPoint(spline.GetPositionAtTime(0f)); GL.Color(Handles.color); for (float k = 0.01f; k <= 1f; k += 0.01f) { Vector3 vector2 = matrixx2.MultiplyPoint(spline.GetPositionAtTime(k)); GL.Vertex(v); GL.Vertex(vector2); v = vector2; } } } GL.End(); for (int j = 0; j < s_SelectedGroup.nodeIDs.Length; j++) { TreeNode node2 = treeData.GetNode(s_SelectedGroup.nodeIDs[j]); TreeSpline spline2 = node2.spline; if (spline2 != null) { Handles.color = (node2 != s_SelectedNode) ? s_GroupColor : s_NormalColor; Matrix4x4 m = localToWorldMatrix * node2.matrix; for (int n = 0; n < spline2.nodes.Length; n++) { SplineNode node3 = spline2.nodes[n]; Vector3 position = m.MultiplyPoint(node3.point); float size = HandleUtility.GetHandleSize(position) * 0.08f; Handles.color = Handles.centerColor; int keyboardControl = GUIUtility.keyboardControl; switch (editMode) { case EditMode.MoveNode: if (n != 0) { break; } if (<>f__mg$cache0 == null) { <>f__mg$cache0 = new Handles.CapFunction(Handles.CircleHandleCap); } position = Handles.FreeMoveHandle(position, Quaternion.identity, size, Vector3.zero, <>f__mg$cache0); goto Label_0361; case EditMode.RotateNode: if (<>f__mg$cache2 == null) {
private static Vector3 DoSlider(int id, Vector3 position, Vector3 slide1, Vector3 slide2, float s, Handles.CapFunction cap) { return(Slider2D.Do(id, position, Vector3.zero, Vector3.Cross(slide1, slide2), slide1, slide2, s, cap, Vector2.zero, false)); }
// Returns the distance the new position has moved along slideDir1 and slideDir2 private static Vector2 CalcDeltaAlongDirections( int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.CapFunction capFunction, Vector2 snap, bool drawHelper) { Vector3 position = handlePos + offset; Quaternion rotation = Quaternion.LookRotation(handleDir, slideDir1); Vector2 deltaDistanceAlongDirections = new Vector2(0, 0); Event evt = Event.current; switch (evt.GetTypeForControl(id)) { case EventType.Layout: case EventType.MouseMove: if (capFunction != null) { capFunction(id, position, rotation, handleSize, EventType.Layout); } else { HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(handlePos + offset, handleSize * .5f)); } break; case EventType.MouseDown: // am I closest to the thingy? if (HandleUtility.nearestControl == id && evt.button == 0 && GUIUtility.hotControl == 0 && !evt.alt) { s_CurrentMousePosition = evt.mousePosition; bool success = true; Vector3 localMousePoint = Handles.inverseMatrix.MultiplyPoint(GetMousePosition(handleDir, handlePos, ref success)); if (success) { GUIUtility.hotControl = id; // Grab mouse focus s_StartPosition = handlePos; Vector3 clickOffset = localMousePoint - handlePos; s_StartPlaneOffset.x = Vector3.Dot(clickOffset, slideDir1); s_StartPlaneOffset.y = Vector3.Dot(clickOffset, slideDir2); evt.Use(); EditorGUIUtility.SetWantsMouseJumping(1); } } break; case EventType.MouseDrag: capFunction?.Invoke(id, position, rotation, handleSize, EventType.Layout); if (GUIUtility.hotControl == id) { Vector2 mouseDelta = evt.mousePosition - s_CurrentMousePosition; s_CurrentMousePosition += mouseDelta; bool success = true; Vector3 localMousePoint = Handles.inverseMatrix.MultiplyPoint(GetMousePosition(handleDir, handlePos, ref success)); if (success) { // Determine hitpos projection onto slideDirs deltaDistanceAlongDirections.x = HandleUtility.PointOnLineParameter(localMousePoint, s_StartPosition, slideDir1); deltaDistanceAlongDirections.y = HandleUtility.PointOnLineParameter(localMousePoint, s_StartPosition, slideDir2); deltaDistanceAlongDirections -= s_StartPlaneOffset; deltaDistanceAlongDirections.x = Handles.SnapValue(deltaDistanceAlongDirections.x, snap.x); deltaDistanceAlongDirections.y = Handles.SnapValue(deltaDistanceAlongDirections.y, snap.y); GUI.changed = true; } evt.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2)) { GUIUtility.hotControl = 0; evt.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.Repaint: { if (capFunction == null) { break; } Handles.SetupHandleColor(id, evt, out var prevColor, out var thickness); capFunction(id, position, rotation, handleSize, EventType.Repaint); Handles.color = prevColor; // Draw a helper rectangle to show what plane we are dragging in if (drawHelper && GUIUtility.hotControl == id) { Vector3[] verts = new Vector3[4]; float helperSize = handleSize * 10.0f; verts[0] = position + (slideDir1 * helperSize + slideDir2 * helperSize); verts[1] = verts[0] - slideDir1 * helperSize * 2.0f; verts[2] = verts[1] - slideDir2 * helperSize * 2.0f; verts[3] = verts[2] + slideDir1 * helperSize * 2.0f; Handles.color = Color.white; float outline = 0.6f; Handles.DrawSolidRectangleWithOutline(verts, new Color(1, 1, 1, 0.05f), new Color(outline, outline, outline, 0.4f)); Handles.color = prevColor; } } break; } return(deltaDistanceAlongDirections); }
void OnSceneGUI() { RenderAttenuationSpheres(); if (m_AkAmbient.multiPositionTypeLabel == MultiPositionTypeLabel.Simple_Mode) { return; } int someHashCode = GetHashCode(); Handles.matrix = m_AkAmbient.transform.localToWorldMatrix; for (int i = 0; i < m_AkAmbient.multiPositionArray.Count; i++) { Vector3 pos = m_AkAmbient.multiPositionArray[i]; Handles.Label(pos, "Point_" + i); float handleSize = HandleUtility.GetHandleSize(pos); // Get the needed data before the handle int controlIDBeforeHandle = GUIUtility.GetControlID(someHashCode, FocusType.Passive); #if UNITY_2017_3_OR_NEWER bool isEventUsedBeforeHandle = (Event.current.type == EventType.Used); #else bool isEventUsedBeforeHandle = (Event.current.type == EventType.used); #endif Handles.color = Color.green; #if UNITY_5_6_OR_NEWER Handles.CapFunction capFunc = Handles.SphereHandleCap; #else Handles.DrawCapFunction capFunc = Handles.SphereCap; #endif Handles.ScaleValueHandle(0, pos, Quaternion.identity, handleSize, capFunc, 0); if (curPointIndex == i) { pos = Handles.PositionHandle(pos, Quaternion.identity); } // Get the needed data after the handle int controlIDAfterHandle = GUIUtility.GetControlID(someHashCode, FocusType.Passive); #if UNITY_2017_3_OR_NEWER bool isEventUsedByHandle = !isEventUsedBeforeHandle && (Event.current.type == EventType.Used); #else bool isEventUsedByHandle = !isEventUsedBeforeHandle && (Event.current.type == EventType.used); #endif if ((controlIDBeforeHandle < GUIUtility.hotControl && GUIUtility.hotControl < controlIDAfterHandle) || isEventUsedByHandle) { curPointIndex = i; } m_AkAmbient.multiPositionArray[i] = pos; } if (m_AkAmbient.multiPositionTypeLabel == MultiPositionTypeLabel.Large_Mode) { Handles.BeginGUI(); Rect size = new Rect(0, 0, 200, 70); GUI.Window(0, new Rect(Screen.width - size.width - 10, Screen.height - size.height - 50, size.width, size.height), DoMyWindow, "AkAmbient Tool Bar"); Handles.EndGUI(); } }
public static Vector3 DrawHandle(Vector3 position, PathSpace space, bool isInterpickedUp, float handleDiameter, Handles.CapFunction capFunc, HandleColours colours, out HandleInputType inputType, int handleIndex) { int id = GetID(handleIndex); Vector3 screenPosition = Handles.matrix.MultiplyPoint(position); Matrix4x4 cachedMatrix = Handles.matrix; inputType = HandleInputType.None; EventType eventType = Event.current.GetTypeForControl(id); float handleRadius = handleDiameter / 2f; float dstToHandle = HandleUtility.DistanceToCircle(position, handleRadius + extraInputRadius); float dstToMouse = HandleUtility.DistanceToCircle(position, 0); // Handle input events if (isInterpickedUp) { // Repaint if mouse is entering/exiting handle (for highlight colour) if (dstToHandle == 0) { if (!mouseIsOverAHandle) { HandleUtility.Repaint(); mouseIsOverAHandle = true; } } else { if (mouseIsOverAHandle) { HandleUtility.Repaint(); mouseIsOverAHandle = false; } } switch (eventType) { case EventType.MouseDown: if (Event.current.button == 0 && Event.current.modifiers != EventModifiers.Alt) { if (dstToHandle == 0 && dstToMouse < dstMouseToDragPointStart) { dstMouseToDragPointStart = dstToMouse; GUIUtility.hotControl = id; handleDragMouseEnd = handleDragMouseStart = Event.current.mousePosition; handleDragWorldStart = position; selectedHandleID = id; inputType = HandleInputType.LMBPress; } } break; case EventType.MouseUp: dstMouseToDragPointStart = float.MaxValue; if (GUIUtility.hotControl == id && Event.current.button == 0) { GUIUtility.hotControl = 0; selectedHandleID = -1; Event.current.Use(); inputType = HandleInputType.LMBRelease; if (Event.current.mousePosition == handleDragMouseStart) { inputType = HandleInputType.LMBClick; } } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id && Event.current.button == 0) { handleDragMouseEnd += new Vector2(Event.current.delta.x, -Event.current.delta.y); Vector3 position2 = Camera.current.WorldToScreenPoint(Handles.matrix.MultiplyPoint(handleDragWorldStart)) + (Vector3)(handleDragMouseEnd - handleDragMouseStart); inputType = HandleInputType.LMBDrag; // Handle can move freely in 3d space if (space == PathSpace.xyz) { position = Handles.matrix.inverse.MultiplyPoint(Camera.current.ScreenToWorldPoint(position2)); } // Handle is clamped to xy or xz plane else { position = MouseUtility.GetMouseWorldPosition(space); } GUI.changed = true; Event.current.Use(); } break; } } switch (eventType) { case EventType.Repaint: Color originalColour = Handles.color; Handles.color = (isInterpickedUp) ? colours.defaultColour : colours.disabledColour; if (id == GUIUtility.hotControl) { Handles.color = colours.selectedColour; } else if (dstToHandle == 0 && selectedHandleID == -1 && isInterpickedUp) { Handles.color = colours.highlightedColour; } Handles.matrix = Matrix4x4.identity; Vector3 lookForward = Vector3.up; Camera cam = Camera.current; if (cam != null) { if (cam.orthographic) { lookForward = -cam.transform.forward; } else { lookForward = (cam.transform.position - position); } } capFunc(id, screenPosition, Quaternion.LookRotation(lookForward), handleDiameter, EventType.Repaint); Handles.matrix = cachedMatrix; Handles.color = originalColour; break; case EventType.Layout: Handles.matrix = Matrix4x4.identity; HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(screenPosition, handleDiameter / 2f)); Handles.matrix = cachedMatrix; break; } return(position); }
public override void OnSceneGUI(NavGraph target) { var graph = target as RecastGraph; Handles.matrix = Matrix4x4.identity; Handles.color = AstarColor.BoundsHandles; Handles.CapFunction cap = Handles.CylinderHandleCap; var center = graph.forcedBoundsCenter; Matrix4x4 matrix = Matrix4x4.TRS(center, Quaternion.Euler(graph.rotation), graph.forcedBoundsSize * 0.5f); if (Tools.current == Tool.Scale) { const float HandleScale = 0.1f; Vector3 mn = Vector3.zero; Vector3 mx = Vector3.zero; EditorGUI.BeginChangeCheck(); for (int i = 0; i < handlePoints.Length; i++) { var ps = matrix.MultiplyPoint3x4(handlePoints[i]); Vector3 p = matrix.inverse.MultiplyPoint3x4(Handles.Slider(ps, ps - center, HandleScale * HandleUtility.GetHandleSize(ps), cap, 0)); if (i == 0) { mn = mx = p; } else { mn = Vector3.Min(mn, p); mx = Vector3.Max(mx, p); } } if (EditorGUI.EndChangeCheck()) { graph.forcedBoundsCenter = matrix.MultiplyPoint3x4((mn + mx) * 0.5f); graph.forcedBoundsSize = Vector3.Scale(graph.forcedBoundsSize, (mx - mn) * 0.5f); } } else if (Tools.current == Tool.Move) { EditorGUI.BeginChangeCheck(); center = Handles.PositionHandle(center, Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : Quaternion.Euler(graph.rotation)); if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit) { graph.forcedBoundsCenter = center; } } else if (Tools.current == Tool.Rotate) { EditorGUI.BeginChangeCheck(); var rot = Handles.RotationHandle(Quaternion.Euler(graph.rotation), graph.forcedBoundsCenter); if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit) { graph.rotation = rot.eulerAngles; } } }
private void OnEnable() { prismaticHandleDrawFunction = PrismaticHandleDrawFunction; }
public static Vector3 TinyHandle2D(int id, Transform transform, float size, Handles.CapFunction func = null)
public static bool Button(int id, Vector3 position, Quaternion direction, float size, float pickSize, bool useHandleSize, Handles.CapFunction capFunc, Color hoverCol, out bool isHovering)
public static Vector3 TinyHandle2D(int id, Vector3 position, Quaternion rotation, float size, Handles.CapFunction func = null)
public static float DoCenter(int id, float value, Vector3 position, Quaternion rotation, float size, Handles.CapFunction capFunction, float snap) { Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (HandleUtility.nearestControl == id && current.button == 0) { GUIUtility.hotControl = id; SliderScale.s_StartScale = value; SliderScale.s_ValueDrag = 0f; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; SliderScale.s_ScaleDrawLength = 1f; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseMove: if (id == HandleUtility.nearestControl) { HandleUtility.Repaint(); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { SliderScale.s_ValueDrag += HandleUtility.niceMouseDelta * 0.01f; value = (Handles.SnapValue(SliderScale.s_ValueDrag, snap) + 1f) * SliderScale.s_StartScale; SliderScale.s_ScaleDrawLength = value / SliderScale.s_StartScale; GUI.changed = true; current.Use(); } break; case EventType.KeyDown: if (GUIUtility.hotControl == id) { if (current.keyCode == KeyCode.Escape) { value = SliderScale.s_StartScale; SliderScale.s_ScaleDrawLength = 1f; GUIUtility.hotControl = 0; GUI.changed = true; current.Use(); } } break; case EventType.Repaint: { Color color = Color.white; if (id == GUIUtility.hotControl) { color = Handles.color; Handles.color = Handles.selectedColor; } else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0) { color = Handles.color; Handles.color = Handles.preselectionColor; } capFunction(id, position, rotation, size * 0.15f, EventType.Repaint); if (id == GUIUtility.hotControl || (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)) { Handles.color = color; } break; } case EventType.Layout: capFunction(id, position, rotation, size * 0.15f, EventType.Layout); break; } return(value); }
public static Vector3 TinyHandle2D(int id, Vector3 pos, Vector3 forward, Vector3 up, Vector3 right, float size, Handles.CapFunction func = null)
private void DrawBezierPointAt(int index, int controlPointIndex, Handles.CapFunction capFunc) { Vector3 worldPos; Quaternion rotation; float sizeModifier; if (controlPointIndex == EndPointIndex.CONTROL_POINT_NONE) { worldPos = spline[index].position; rotation = Quaternion.identity; sizeModifier = END_POINT_SIZE; } else if (controlPointIndex == EndPointIndex.CONTROL_POINT_PRECEDING) { worldPos = spline[index].precedingControlPointPosition; rotation = SceneView.lastActiveSceneView.rotation; sizeModifier = END_POINT_CONTROL_POINTS_SIZE; } else { worldPos = spline[index].followingControlPointPosition; rotation = SceneView.lastActiveSceneView.rotation; sizeModifier = END_POINT_CONTROL_POINTS_SIZE; } if (index != selectedEndPointIndex || selectedEndPointIndex.controlPointIndex != controlPointIndex) { if (index != selectedEndPointIndex) { Handles.color = Color.white; } else { Handles.color = SELECTED_END_POINT_CONNECTED_POINTS_COLOR; } if (Event.current.alt || Event.current.button > 0) { //capFunc( 0, worldPos, rotation, HandleUtility.GetHandleSize( worldPos ) * sizeModifier ); capFunc(0, worldPos, rotation, HandleUtility.GetHandleSize(worldPos) * sizeModifier, EventType.Repaint); } else { if (Handles.Button(worldPos, rotation, HandleUtility.GetHandleSize(worldPos) * sizeModifier, sizeModifier, capFunc)) { Undo.RecordObject(spline, "Change Selected Point"); selectedEndPointIndex = new EndPointIndex(index, controlPointIndex); worldSpaceRotationInitialized = false; endPointControlPointRotationInitialized = false; Repaint(); } } } else { Handles.color = SELECTED_END_POINT_COLOR; capFunc(0, worldPos, rotation, HandleUtility.GetHandleSize(worldPos) * sizeModifier * 1.5f, EventType.Repaint); } }
static internal Vector2 Slider2DCircular(int id, Vector2 position, float size, Handles.CapFunction drawCapFunction) { var type = Event.current.GetTypeForControl(id); switch (type) { case EventType.MouseDown: if (Event.current.button == 0 && HandleUtility.nearestControl == id && !Event.current.alt) { GUIUtility.keyboardControl = id; GUIUtility.hotControl = id; s_CurrentMousePosition = Event.current.mousePosition; s_DragStartScreenPosition = Event.current.mousePosition; Vector2 b = HandleUtility.WorldToGUIPoint(position); s_DragScreenOffset = s_CurrentMousePosition - b; EditorGUIUtility.SetWantsMouseJumping(1); Event.current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (Event.current.button == 0 || Event.current.button == 2)) { GUIUtility.hotControl = 0; Event.current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { s_CurrentMousePosition = Event.current.mousePosition; Vector2 center = position; position = Handles.inverseMatrix.MultiplyPoint(s_CurrentMousePosition - s_DragScreenOffset); if (!Mathf.Approximately((center - position).magnitude, 0f)) { GUI.changed = true; } Event.current.Use(); } break; case EventType.KeyDown: if (GUIUtility.hotControl == id && Event.current.keyCode == KeyCode.Escape) { position = Handles.inverseMatrix.MultiplyPoint(s_DragStartScreenPosition - s_DragScreenOffset); GUIUtility.hotControl = 0; GUI.changed = true; Event.current.Use(); } break; } if (drawCapFunction != null) { drawCapFunction(id, position, Quaternion.identity, size, type); } return(position); }
public override void OnSceneGUI(NavGraph target) { Event e = Event.current; var graph = target as GridGraph; graph.UpdateTransform(); var currentTransform = graph.transform * Matrix4x4.Scale(new Vector3(graph.width, 1, graph.depth)); if (e.type == EventType.MouseDown) { isMouseDown = true; } else if (e.type == EventType.MouseUp) { isMouseDown = false; } if (!isMouseDown) { savedTransform = currentTransform; savedDimensions = new Vector2(graph.width, graph.depth); savedNodeSize = graph.nodeSize; } Handles.matrix = Matrix4x4.identity; Handles.color = AstarColor.BoundsHandles; #if UNITY_5_5_OR_NEWER Handles.CapFunction cap = Handles.CylinderHandleCap; #else Handles.DrawCapFunction cap = Handles.CylinderCap; #endif var center = currentTransform.Transform(new Vector3(0.5f, 0, 0.5f)); if (Tools.current == Tool.Scale) { const float HandleScale = 0.1f; Vector3 mn = Vector3.zero; Vector3 mx = Vector3.zero; EditorGUI.BeginChangeCheck(); for (int i = 0; i < handlePoints.Length; i++) { var ps = currentTransform.Transform(handlePoints[i]); Vector3 p = savedTransform.InverseTransform(Handles.Slider(ps, ps - center, HandleScale * HandleUtility.GetHandleSize(ps), cap, 0)); // Snap to increments of whole nodes p.x = Mathf.Round(p.x * savedDimensions.x) / savedDimensions.x; p.z = Mathf.Round(p.z * savedDimensions.y) / savedDimensions.y; if (i == 0) { mn = mx = p; } else { mn = Vector3.Min(mn, p); mx = Vector3.Max(mx, p); } } if (EditorGUI.EndChangeCheck()) { graph.center = savedTransform.Transform((mn + mx) * 0.5f); graph.unclampedSize = Vector2.Scale(new Vector2(mx.x - mn.x, mx.z - mn.z), savedDimensions) * savedNodeSize; } } else if (Tools.current == Tool.Move) { EditorGUI.BeginChangeCheck(); center = Handles.PositionHandle(graph.center, Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : Quaternion.Euler(graph.rotation)); if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit) { graph.center = center; } } else if (Tools.current == Tool.Rotate) { 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; }