internal static void Handle(PivotType aSides, Transform aTransform, bool aLockX, bool aLockY, bool aLockZ, Vector3 aSnap, ref Vector3 lbf, ref Vector3 rtb, Handles.DrawCapFunction aCap) { Vector3 pt = new Vector3(0,0,0); Vector3 mask = new Vector3(aLockX?1:0, aLockY?1:0, aLockZ?1:0); if ((aSides & PivotType.Left ) > 0) pt.x = lbf.x; if ((aSides & PivotType.Right ) > 0) pt.x = rtb.x; if ((aSides & PivotType.Top ) > 0) pt.y = rtb.y; if ((aSides & PivotType.Bottom) > 0) pt.y = lbf.y; if ((aSides & PivotType.Front ) > 0) pt.z = lbf.z; if ((aSides & PivotType.Back ) > 0) pt.z = rtb.z; pt = aTransform.TransformPoint(pt); Vector3 result = Handles.FreeMoveHandle(pt, Quaternion.identity, HandleUtility.GetHandleSize(pt) * mHandleSize, Vector3.zero, aCap); if (result != pt) { Vector3 dir = SuperCubeEditorUtil.CreateBillboardNormal(pt, aLockX, aLockY, aLockZ); result = SuperCubeEditorUtil.SnapVector(Vector3.Scale(SuperCubeEditorUtil.GetPlanePoint(result, new Plane(dir, pt)), mask), aSnap); result = aTransform.InverseTransformPoint(result); if ((aSides & PivotType.Left ) > 0) lbf.x = result.x; if ((aSides & PivotType.Right ) > 0) rtb.x = result.x; if ((aSides & PivotType.Top ) > 0) rtb.y = result.y; if ((aSides & PivotType.Bottom) > 0) lbf.y = result.y; if ((aSides & PivotType.Front ) > 0) lbf.z = result.z; if ((aSides & PivotType.Back ) > 0) rtb.z = result.z; } }
internal static Vector3 SideSlider(int id, Vector3 position, Vector3 sideVector, Vector3 direction, float size, Handles.DrawCapFunction drawFunc, float snap, float bias) { Event current = Event.current; Vector3 normalized1 = Vector3.Cross(sideVector, direction).normalized; Vector3 vector3_1 = Handles.Slider2D(id, position, normalized1, direction, sideVector, 0.0f, drawFunc, Vector2.one * snap); Vector3 vector3_2 = position + Vector3.Project(vector3_1 - position, direction); switch (current.type) { case EventType.Repaint: if (HandleUtility.nearestControl == id && GUIUtility.hotControl == 0 || GUIUtility.hotControl == id) { RectHandles.HandleDirectionalCursor(position, normalized1, direction); break; } break; case EventType.Layout: Vector3 normalized2 = sideVector.normalized; HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position + sideVector * 0.5f - normalized2 * size * 2f, position - sideVector * 0.5f + normalized2 * size * 2f) - bias); break; case EventType.MouseMove: RectHandles.DetectCursorChange(id); break; } return vector3_2; }
internal static Vector3 SideSlider(int id, Vector3 position, Vector3 sideVector, Vector3 direction, float size, Handles.DrawCapFunction drawFunc, float snap, float bias) { Event current = Event.current; Vector3 normalized = Vector3.Cross(sideVector, direction).normalized; Vector3 vector = Handles.Slider2D(id, position, normalized, direction, sideVector, 0f, drawFunc, Vector2.one * snap); vector = position + Vector3.Project(vector - position, direction); EventType type = current.type; if (type != EventType.Repaint) { if (type != EventType.Layout) { if (type == EventType.MouseMove) { RectHandles.DetectCursorChange(id); } } else { Vector3 normalized2 = sideVector.normalized; HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position + sideVector * 0.5f - normalized2 * size * 2f, position - sideVector * 0.5f + normalized2 * size * 2f) - bias); } } else { if ((HandleUtility.nearestControl == id && GUIUtility.hotControl == 0) || GUIUtility.hotControl == id) { RectHandles.HandleDirectionalCursor(position, normalized, direction); } } return vector; }
// Create an angular slider for the given transform 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) { 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); }
internal static void OnSceneGUI(SceneView sceneView) { if (e.type == EventType.KeyDown && e.modifiers == EventModifiers.None && e.keyCode == KeyCode.B) { PeekPlugin.Configuration.displaySceneToolbars = !PeekPlugin.Configuration.displaySceneToolbars; PeekPlugin.Configuration.Save(); e.Use(); } if (!PeekPlugin.Configuration.enableSceneToolbars.Display(sceneView.maximized) || !PeekPlugin.Configuration.displaySceneToolbars) { return; } Profiler.BeginSample("Peek." + nameof(SceneToolbars)); try { Handles.BeginGUI(); DrawToolbar(sceneView, selectionToolbarControl, selectionToolbarTargets); if (PeekPlugin.Configuration.enableStickyDragAndDrop) { if (dragToolbarControl != null) { EditorGUI.BeginDisabledGroup(!dragToolbarLocked); DrawToolbar(sceneView, dragToolbarControl, new[] { dragToolbarTarget }); EditorGUI.EndDisabledGroup(); } RefreshDragToolbar(sceneView); } if (PeekPlugin.Configuration.enableHierarchySpaceShortcut && e.type == EventType.KeyDown && e.modifiers == EventModifiers.None && e.keyCode == KeyCode.Space) { if (OpenHierarchyTool()) { e.Use(); } } Handles.EndGUI(); } catch (Exception ex) { Debug.LogException(ex); } Profiler.EndSample(); }
internal static void OnSceneGUI(SceneView sceneView) { if (PeekPlugin.Configuration.toggleToolbarShortcut.Check()) { PeekPlugin.Configuration.displaySceneToolbars = !PeekPlugin.Configuration.displaySceneToolbars; PeekPlugin.Configuration.Save(); e.TryUse(); } if (!PeekPlugin.Configuration.enableSceneToolbars.Display(sceneView.maximized) || !PeekPlugin.Configuration.displaySceneToolbars) { return; } Profiler.BeginSample("Peek." + nameof(SceneToolbars)); try { Handles.BeginGUI(); selectionToolbarControls.TryGetValue(sceneView, out var selectionToolbarControl); DrawToolbar(sceneView, selectionToolbarControl, selectionToolbarTargets); if (PeekPlugin.Configuration.enableStickyDragAndDrop) { if (dragToolbarControl != null) { EditorGUI.BeginDisabledGroup(!dragToolbarLocked); DrawToolbar(sceneView, dragToolbarControl, new[] { dragToolbarTarget }); EditorGUI.EndDisabledGroup(); } RefreshDragToolbar(sceneView); } if (PeekPlugin.Configuration.selectionHierarchyShortcut.Check(e)) { if (OpenHierarchyTool(selectionToolbarControl)) { e.Use(); } } Handles.EndGUI(); } catch (Exception ex) { Debug.LogException(ex); } finally { Profiler.EndSample(); } }
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) { bool changed = GUI.changed; GUI.changed = false; Vector2 vector2 = Slider2D.CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, drawFunc, snap, drawHelper); if (GUI.changed) handlePos = Slider2D.s_StartPosition + slideDir1 * vector2.x + slideDir2 * vector2.y; GUI.changed |= changed; return handlePos; }
public static bool Do(int id, Vector3 position, Quaternion direction, float size, float pickSize, Handles.DrawCapFunction capFunc) { Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (HandleUtility.nearestControl == id) { GUIUtility.hotControl = id; current.Use(); } break; case EventType.MouseUp: if ((GUIUtility.hotControl != id) || ((current.button != 0) && (current.button != 2))) { break; } GUIUtility.hotControl = 0; current.Use(); if (HandleUtility.nearestControl != id) { break; } return true; 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) { Handles.color = Handles.selectedColor; } capFunc(id, position, direction, size); Handles.color = color; break; } case EventType.Layout: if (GUI.enabled) { HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, pickSize)); } break; } return false; }
internal static void RenderGizmo(Camera camera) { Vector3[] array = new Vector3[4]; Vector3[] array2 = new Vector3[4]; float num; if (CameraEditor.GetFrustum(camera, array, array2, out num)) { Color color = Handles.color; Handles.color = CameraEditor.kGizmoCamera; for (int i = 0; i < 4; i++) { Handles.DrawLine(array[i], array[(i + 1) % 4]); Handles.DrawLine(array2[i], array2[(i + 1) % 4]); Handles.DrawLine(array[i], array2[i]); } Handles.color = color; } }
internal static Vector3 CornerSlider(int id, Vector3 cornerPos, Vector3 handleDir, Vector3 outwardsDir1, Vector3 outwardsDir2, float handleSize, Handles.DrawCapFunction drawFunc, Vector2 snap) { Event current = Event.current; Vector3 vector3 = Handles.Slider2D(id, cornerPos, handleDir, outwardsDir1, outwardsDir2, handleSize, drawFunc, snap); switch (current.type) { case EventType.MouseMove: RectHandles.DetectCursorChange(id); break; case EventType.Repaint: if (HandleUtility.nearestControl == id && GUIUtility.hotControl == 0 || GUIUtility.hotControl == id) { RectHandles.HandleDirectionalCursor(cornerPos, handleDir, outwardsDir1 + outwardsDir2); break; } break; } return vector3; }
public void OnSceneGUI() { this.anchorJoint2D = (AnchoredJoint2D)this.target; if (!this.anchorJoint2D.enabled) { return; } Vector3 position1 = Joint2DEditor.TransformPoint(this.anchorJoint2D.transform, (Vector3)this.anchorJoint2D.anchor); Vector3 position2 = (Vector3)this.anchorJoint2D.connectedAnchor; if ((bool)((Object)this.anchorJoint2D.connectedBody)) { position2 = Joint2DEditor.TransformPoint(this.anchorJoint2D.connectedBody.transform, position2); } Vector3 vector3 = position1 + (position2 - position1).normalized * HandleUtility.GetHandleSize(position1) * 0.1f; Handles.color = Color.green; Handles.DrawAAPolyLine(new Vector3[2] { vector3, position2 }); if (this.HandleAnchor(ref position2, true)) { position2 = this.SnapToSprites(position2); position2 = Joint2DEditor.SnapToPoint(position2, position1, 0.13f); if ((bool)((Object)this.anchorJoint2D.connectedBody)) { position2 = Joint2DEditor.InverseTransformPoint(this.anchorJoint2D.connectedBody.transform, position2); } Undo.RecordObject((Object)this.anchorJoint2D, "Move Connected Anchor"); this.anchorJoint2D.connectedAnchor = (Vector2)position2; } if (!this.HandleAnchor(ref position1, false)) { return; } Vector3 point = Joint2DEditor.SnapToPoint(this.SnapToSprites(position1), position2, 0.13f); Undo.RecordObject((Object)this.anchorJoint2D, "Move Anchor"); this.anchorJoint2D.anchor = (Vector2)Joint2DEditor.InverseTransformPoint(this.anchorJoint2D.transform, point); }
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; } }
internal static Vector3 CornerSlider(int id, Vector3 cornerPos, Vector3 handleDir, Vector3 outwardsDir1, Vector3 outwardsDir2, float handleSize, Handles.DrawCapFunction drawFunc, Vector2 snap) { Event current = Event.current; Vector3 result = Handles.Slider2D(id, cornerPos, handleDir, outwardsDir1, outwardsDir2, handleSize, drawFunc, snap); EventType type = current.type; if (type != EventType.MouseMove) { if (type == EventType.Repaint) { if ((HandleUtility.nearestControl == id && GUIUtility.hotControl == 0) || GUIUtility.hotControl == id) { RectHandles.HandleDirectionalCursor(cornerPos, handleDir, outwardsDir1 + outwardsDir2); } } } else { RectHandles.DetectCursorChange(id); } return result; }
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 point = Handles.Slider(vector2, vector, handleSize * 0.03f, new Handles.DrawCapFunction(Handles.DotCap), 0f); float result = 0f; if (GUI.changed) { result = HandleUtility.PointOnLineParameter(point, vector2, vector); } GUI.changed |= changed; Handles.color = color; return(result); }
private static void DrawPoseError(Transform node, Bounds bounds) { Camera camera = Camera.current; if (camera) { GUIStyle style = new GUIStyle(GUI.skin.label); style.normal.textColor = Color.red; style.wordWrap = false; style.alignment = TextAnchor.MiddleLeft; Vector3 start = node.position; Vector3 end = node.position + Vector3.up * 0.20f; if (node.position.x <= node.root.position.x) { end.x = bounds.min.x; } else { end.x = bounds.max.x; } GUIContent content = new GUIContent(node.name); Rect rect = HandleUtility.WorldPointToSizedRect(end, content, style); rect.x += 2; if (node.position.x > node.root.position.x) { rect.x -= rect.width; } Handles.BeginGUI(); rect.y -= style.CalcSize(content).y / 4; GUI.Label(rect, content, style); Handles.EndGUI(); Handles.color = kErrorMessageColor; Handles.DrawLine(start, end); } }
internal virtual void RuleMatrixOnGUI(RuleTile tile, Rect rect, RuleTile.TilingRule tilingRule) { Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f); int index = 0; float w = rect.width / 3f; float h = rect.height / 3f; for (int y = 0; y <= 2; y++) { float top = rect.yMin + y * h; Handles.DrawLine(new Vector3(rect.xMin, top), new Vector3(rect.xMax, top)); } for (int x = 0; x <= 2; x++) { float left = rect.xMin + x * w; Handles.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax)); } Handles.color = Color.white; for (int y = 0; y <= 2; y++) { for (int x = 0; x <= 2; x++) { Rect r = new Rect(rect.xMin + x * w, rect.yMin + y * h, w - 1, h - 1); if (x != 1 || y != 1) { RuleOnGUI(r, y * 3 + x, tilingRule.m_Neighbors[index]); RuleNeighborUpdate(r, tilingRule, index); index++; } else { RuleTransformOnGUI(r, tilingRule.m_RuleTransform); RuleTransformUpdate(r, tilingRule); } } } }
static Vector3 PivotHandleGUI(Rect rect, Vector3 pivot, Quaternion rotation) { int id = GUIUtility.GetControlID(s_PivotHandleHash, FocusType.Passive); EventType eventType = Event.current.GetTypeForControl(id); if (GUI.color.a > 0 || GUIUtility.hotControl == id) { EventType typeBefore = eventType; EditorGUI.BeginChangeCheck(); Vector3 newPivot = Handles.Slider2D(id, pivot, rotation * Vector3.forward, rotation * Vector3.right, rotation * Vector3.up, HandleUtility.GetHandleSize(pivot) * 0.1f, RectHandles.PivotHandleCap, Vector2.zero); if (typeBefore == EventType.MouseDown && GUIUtility.hotControl == id) { RectTransformSnapping.CalculatePivotSnapValues(rect, pivot, rotation); } if (EditorGUI.EndChangeCheck()) { Vector2 offset = Quaternion.Inverse(rotation) * (newPivot - pivot); offset.x /= rect.width; offset.y /= rect.height; Vector2 pivotCoordBefore = new Vector2(-rect.x / rect.width, -rect.y / rect.height); Vector2 pivotCoordAfter = pivotCoordBefore + offset; Vector2 snapSize = HandleUtility.GetHandleSize(pivot) * RectTransformSnapping.kSnapThreshold * new Vector2(1 / rect.width, 1 / rect.height); pivotCoordAfter = RectTransformSnapping.SnapToGuides(pivotCoordAfter, snapSize); offset = (pivotCoordAfter - pivotCoordBefore); offset.x *= rect.width; offset.y *= rect.height; pivot += rotation * offset; } } ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingPivot, eventType); return(pivot); }
public void DrawMajorTicks(Rect position, float frameRate) { Color color = Handles.color; GUI.BeginGroup(position); if (Event.current.type != EventType.Repaint) { GUI.EndGroup(); return; } TimeArea.InitStyles(); this.SetTickMarkerRanges(); this.hTicks.SetTickStrengths(3f, 80f, true); Color textColor = TimeArea.styles.TimelineTick.normal.textColor; textColor.a = 0.1f; Handles.color = textColor; for (int i = 0; i < this.hTicks.tickLevels; i++) { float num = this.hTicks.GetStrengthOfLevel(i) * 0.9f; if (num > 0.5f) { float[] ticksAtLevel = this.hTicks.GetTicksAtLevel(i, true); for (int j = 0; j < ticksAtLevel.Length; j++) { if (ticksAtLevel[j] >= 0f) { int num2 = Mathf.RoundToInt(ticksAtLevel[j] * frameRate); float x = this.FrameToPixel((float)num2, frameRate, position); Handles.DrawLine(new Vector3(x, 0f, 0f), new Vector3(x, position.height, 0f)); } } } } GUI.EndGroup(); Handles.color = color; }
public void OnSceneGUI() { if (Tools.viewToolActive) { return; } bool flag = GUIUtility.hotControl == this.m_HandleControlID; CircleCollider2D target = (CircleCollider2D)this.target; Color color = Handles.color; Handles.color = Handles.s_ColliderHandleColor; bool enabled = GUI.enabled; if (!this.editingCollider && !flag) { GUI.enabled = false; Handles.color = new Color(0.0f, 0.0f, 0.0f, 1f / 1000f); } Vector3 lossyScale = target.transform.lossyScale; float num1 = Mathf.Max(Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.y)), Mathf.Abs(lossyScale.z)); float radius = Mathf.Max(Mathf.Abs(num1 * target.radius), 1E-05f); Vector3 position = target.transform.TransformPoint((Vector3)target.offset); int hotControl = GUIUtility.hotControl; float num2 = Handles.RadiusHandle(Quaternion.identity, position, radius, true); if (GUI.changed) { Undo.RecordObject((Object)target, "Adjust Radius"); target.radius = num2 * 1f / num1; } if (hotControl != GUIUtility.hotControl && GUIUtility.hotControl != 0) { this.m_HandleControlID = GUIUtility.hotControl; } Handles.color = color; GUI.enabled = enabled; }
private void DrawIsoStatusSymbol(Vector3 center, SceneView view, float alpha) { float num = 1f - Mathf.Clamp01(view.m_Ortho.faded * 1.2f - 0.1f); Vector3 a = Vector3.up * 3f; Vector3 vector = Vector3.right * 10f; Vector3 vector2 = center - vector * 0.5f; Handles.color = new Color(1f, 1f, 1f, 0.6f * alpha); Handles.DrawAAPolyLine(new Vector3[] { vector2 + a * (1f - num), vector2 + vector + a * (1f + num * 0.5f) }); Handles.DrawAAPolyLine(new Vector3[] { vector2, vector2 + vector }); Handles.DrawAAPolyLine(new Vector3[] { vector2 - a * (1f - num), vector2 + vector - a * (1f + num * 0.5f) }); }
protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { // Allow global space scaling for multi-selection but not for a single object Quaternion handleRotation = Selection.transforms.Length > 1 ? Tools.handleRotation : Tools.handleLocalRotation; TransformManipulator.DebugAlignment(handleRotation); if (Event.current.type == EventType.MouseDown) { s_CurrentScale = Vector3.one; } EditorGUI.BeginChangeCheck(); TransformManipulator.BeginManipulationHandling(true); s_CurrentScale = Handles.ScaleHandle(s_CurrentScale, handlePosition, handleRotation, HandleUtility.GetHandleSize(handlePosition)); TransformManipulator.EndManipulationHandling(); if (EditorGUI.EndChangeCheck() && !isStatic) { TransformManipulator.SetScaleDelta(s_CurrentScale, handleRotation); } }
internal static Vector3 SideSlider(int id, Vector3 position, Vector3 sideVector, Vector3 direction, float size, Handles.CapFunction capFunction, float snap) { return SideSlider(id, position, sideVector, direction, size, capFunction, snap, 0f); }
static Vector3 DoPlanarHandle( int id, int planePrimaryAxis, Vector3 position, Vector3 offset, Quaternion rotation, float handleSize, float cameraLerp, Vector3 viewVectorDrawSpace, PositionHandleParam.Orientation orientation) { var positionOffset = offset; var axis1index = planePrimaryAxis; var axis2index = (axis1index + 1) % 3; var axisNormalIndex = (axis1index + 2) % 3; Color prevColor = Handles.color; bool isDisabled = !GUI.enabled; color = isDisabled ? staticColor : GetColorByAxis(axisNormalIndex); color = GetFadedAxisColor(color, cameraLerp, id); float faceOpacity = 0.8f; if (GUIUtility.hotControl == id) { color = selectedColor; } else if (IsHovering(id, Event.current)) { faceOpacity = 0.4f; } else { faceOpacity = 0.1f; } color = ToActiveColorSpace(color); // NOTE: The planar transform handles always face toward the camera so they won't // obscure each other (unlike the X, Y, and Z axis handles which always face in the // positive axis directions). Whenever the octant that the camera is in (relative to // to the transform tool) changes, we need to move the planar transform handle // positions to the correct octant. // Comments below assume axis1 is X and axis2 is Z to make it easier to visualize things. // Shift the planar transform handle in the positive direction by half its // handleSize so that it doesn't overlap in the center of the transform gizmo, // and also move the handle origin into the octant that the camera is in. // Don't update the actant while dragging to avoid too much distraction. if (!currentlyDragging) { switch (orientation) { case PositionHandleParam.Orientation.Camera: // Offset the X position of the handle in negative direction if camera is in the -X octants; otherwise positive. // Test against -0.01 instead of 0 to give a little bias to the positive quadrants. This looks better in axis views. s_PlanarHandlesOctant[axis1index] = (viewVectorDrawSpace[axis1index] > 0.01f ? -1 : 1); // Likewise with the other axis. s_PlanarHandlesOctant[axis2index] = (viewVectorDrawSpace[axis2index] > 0.01f ? -1 : 1); break; case PositionHandleParam.Orientation.Signed: s_PlanarHandlesOctant[axis1index] = 1; s_PlanarHandlesOctant[axis2index] = 1; break; } } Vector3 handleOffset = s_PlanarHandlesOctant; // Zero out the offset along the normal axis. handleOffset[axisNormalIndex] = 0; positionOffset = rotation * Vector3.Scale(positionOffset, handleOffset); // Rotate and scale the offset handleOffset = rotation * (handleOffset * handleSize * 0.5f); // Calculate 3 axes Vector3 axis1 = Vector3.zero; Vector3 axis2 = Vector3.zero; Vector3 axisNormal = Vector3.zero; axis1[axis1index] = 1; axis2[axis2index] = 1; axisNormal[axisNormalIndex] = 1; axis1 = rotation * axis1; axis2 = rotation * axis2; axisNormal = rotation * axisNormal; // Draw the "filler" color for the handle verts[0] = position + positionOffset + handleOffset + (axis1 + axis2) * handleSize * 0.5f; verts[1] = position + positionOffset + handleOffset + (-axis1 + axis2) * handleSize * 0.5f; verts[2] = position + positionOffset + handleOffset + (-axis1 - axis2) * handleSize * 0.5f; verts[3] = position + positionOffset + handleOffset + (axis1 - axis2) * handleSize * 0.5f; Color faceColor = new Color(color.r, color.g, color.b, color.a * faceOpacity); Handles.DrawSolidRectangleWithOutline(verts, faceColor, Color.clear); // And then render the handle itself (this is the colored outline) position = Slider2D(id, position, handleOffset + positionOffset, axisNormal, axis1, axis2, handleSize * 0.5f, RectangleHandleCap, GridSnapping.active ? Vector2.zero : new Vector2(EditorSnapSettings.move[axis1index], EditorSnapSettings.move[axis2index]), false); Handles.color = prevColor; return(position); }
public static bool MovePoints(IEditablePoint points, Transform cloudTransform, List <int> selection) { if (selection.Count == 0) { return(false); } if (Event.current.type == EventType.MouseUp) { PointEditor.s_EditingScale = Vector3.one; PointEditor.s_EditingRotation = Quaternion.identity; } if (Camera.current) { Vector3 vector = Vector3.zero; vector = ((Tools.pivotMode != PivotMode.Pivot) ? (selection.Aggregate(vector, (Vector3 current, int index) => current + points.GetPosition(index)) / (float)selection.Count) : points.GetPosition(selection[0])); vector = cloudTransform.TransformPoint(vector); switch (Tools.current) { case Tool.Move: { Vector3 position = Handles.PositionHandle(vector, (Tools.pivotRotation != PivotRotation.Local) ? Quaternion.identity : cloudTransform.rotation); if (GUI.changed) { Vector3 b = cloudTransform.InverseTransformPoint(position) - cloudTransform.InverseTransformPoint(vector); foreach (int current4 in selection) { points.SetPosition(current4, points.GetPosition(current4) + b); } return(true); } break; } case Tool.Rotate: { Quaternion rotation = Handles.RotationHandle(PointEditor.s_EditingRotation, vector); if (GUI.changed) { Vector3 b2 = cloudTransform.InverseTransformPoint(vector); foreach (int current2 in selection) { Vector3 vector2 = points.GetPosition(current2) - b2; vector2 = Quaternion.Inverse(PointEditor.s_EditingRotation) * vector2; vector2 = rotation * vector2; vector2 += b2; points.SetPosition(current2, vector2); } PointEditor.s_EditingRotation = rotation; return(true); } break; } case Tool.Scale: { Vector3 vector3 = Handles.ScaleHandle(PointEditor.s_EditingScale, vector, Quaternion.identity, HandleUtility.GetHandleSize(vector)); if (GUI.changed) { Vector3 b3 = cloudTransform.InverseTransformPoint(vector); foreach (int current3 in selection) { Vector3 vector4 = points.GetPosition(current3) - b3; vector4.x /= PointEditor.s_EditingScale.x; vector4.y /= PointEditor.s_EditingScale.y; vector4.z /= PointEditor.s_EditingScale.z; vector4.x *= vector3.x; vector4.y *= vector3.y; vector4.z *= vector3.z; vector4 += b3; points.SetPosition(current3, vector4); } PointEditor.s_EditingScale = vector3; return(true); } break; } } } return(false); }
public static Vector3 FreeMoveHandle(Vector3 position, Quaternion rotation, float size, Vector3 snap, Handles.DrawCapFunction capFunc) { int controlID = GUIUtility.GetControlID(Handles.s_FreeMoveHandleHash, FocusType.Keyboard); return FreeMove.Do(controlID, position, rotation, size, snap, capFunc); }
public static Vector3 Slider2D(Vector3 handlePos, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.DrawCapFunction drawFunc, float snap) { bool drawHelper = false; return Handles.Slider2D(handlePos, handleDir, slideDir1, slideDir2, handleSize, drawFunc, snap, drawHelper); }
public static Vector3 Slider(Vector3 position, Vector3 direction, float size, Handles.DrawCapFunction drawFunc, float snap) { int controlID = GUIUtility.GetControlID(Handles.s_SliderHash, FocusType.Keyboard); return Slider1D.Do(controlID, position, direction, size, drawFunc, snap); }
private static void RuleMatrixOnGUI(HexagonalRuleTile hexTile, Rect rect, RuleTile.TilingRule tilingRule, bool flatTop) { Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f); float w = rect.width / 3f; float h = rect.height / 3f; // Grid if (flatTop) { for (int x = 0; x <= 3; x++) { float left = rect.xMin + x * w; float offset = x % 3 > 0 ? 0 : h / 2; Handles.DrawLine(new Vector3(left, rect.yMin + offset), new Vector3(left, rect.yMax - offset)); if (x < 3) { bool noOffset = x % 2 > 0; for (int y = 0; y < (noOffset ? 4 : 3); y++) { float top = rect.yMin + y * h + (noOffset ? 0 : h / 2); Handles.DrawLine(new Vector3(left, top), new Vector3(left + w, top)); } } } } else { for (int y = 0; y <= 3; y++) { float top = rect.yMin + y * h; float offset = y % 3 > 0 ? 0 : w / 2; Handles.DrawLine(new Vector3(rect.xMin + offset, top), new Vector3(rect.xMax - offset, top)); if (y < 3) { bool noOffset = y % 2 > 0; for (int x = 0; x < (noOffset ? 4 : 3); x++) { float left = rect.xMin + x * w + (noOffset ? 0 : w / 2); Handles.DrawLine(new Vector3(left, top), new Vector3(left, top + h)); } } } } // Icons Handles.color = Color.white; for (int index = 0; index < hexTile.neighborCount; ++index) { Vector2 position = flatTop ? s_FlatTopPositions[index] : s_PointedTopPositions[index]; int arrowIndex = flatTop ? s_FlatTopArrows[index] : s_PointedTopArrows[index]; Rect r = new Rect(rect.xMin + position.x * w, rect.yMin + position.y * h, w - 1, h - 1); hexTile.RuleOnGUI(r, arrowIndex, tilingRule.m_Neighbors[index]); if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition)) { var allConsts = hexTile.m_NeighborType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); var neighbors = allConsts.Select(c => (int)c.GetValue(null)).ToList(); neighbors.Sort(); int oldIndex = neighbors.IndexOf(tilingRule.m_Neighbors[index]); int newIndex = (int)Mathf.Repeat(oldIndex + GetMouseChange(), neighbors.Count); tilingRule.m_Neighbors[index] = neighbors[newIndex]; GUI.changed = true; Event.current.Use(); } } // Center { Rect r = new Rect(rect.xMin + w, rect.yMin + h, w - 1, h - 1); switch (tilingRule.m_RuleTransform) { case RuleTile.TilingRule.Transform.Rotated: GUI.DrawTexture(r, autoTransforms[0]); break; case RuleTile.TilingRule.Transform.MirrorX: GUI.DrawTexture(r, autoTransforms[1]); break; case RuleTile.TilingRule.Transform.MirrorY: GUI.DrawTexture(r, autoTransforms[2]); break; } if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition)) { tilingRule.m_RuleTransform = (RuleTile.TilingRule.Transform)(((int)tilingRule.m_RuleTransform + GetMouseChange()) % 4); GUI.changed = true; Event.current.Use(); } } }
private void OnGUI() { HandleContextMenu(); EditorGUILayout.BeginVertical(); GUILayout.Space(10f); EditorGUILayout.BeginHorizontal(); float leftMargin = (Screen.width / EditorGUIUtility.pixelsPerPoint - Styles.toolbarWidth) * 0.5f; GUILayout.Space(leftMargin); EditMode.DoInspectorToolbar(k_SceneViewEditModes, Styles.toolContents, GridPaintingState.instance); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(leftMargin); DoActiveTargetsGUI(); EditorGUILayout.EndHorizontal(); GUILayout.Space(6f); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); Rect clipboardToolbarRect = EditorGUILayout.BeginHorizontal(GUIContent.none, "Toolbar"); DoClipboardHeader(); EditorGUILayout.EndHorizontal(); Rect dragRect = new Rect(k_DropdownWidth + k_ResizerDragRectPadding, 0, position.width - k_DropdownWidth - k_ResizerDragRectPadding, k_ToolbarHeight); float brushInspectorSize = m_PreviewResizer.ResizeHandle(position, k_MinBrushInspectorHeight, k_MinClipboardHeight, k_ToolbarHeight, dragRect); float clipboardHeight = position.height - brushInspectorSize - k_TopAreaHeight; Rect clipboardRect = new Rect(0f, clipboardToolbarRect.yMax, position.width, clipboardHeight); OnClipboardGUI(clipboardRect); EditorGUILayout.EndVertical(); GUILayout.Space(clipboardRect.height); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(GUIContent.none, "Toolbar"); DoBrushesDropdown(); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); m_BrushScroll = GUILayout.BeginScrollView(m_BrushScroll, false, false); GUILayout.Space(5f); OnBrushInspectorGUI(); GUILayout.EndScrollView(); EditorGUILayout.EndVertical(); Color oldColor = Handles.color; Handles.color = Color.black; Handles.DrawLine(new Vector3(0, clipboardRect.yMax + 0.5f, 0), new Vector3(Screen.width, clipboardRect.yMax + 0.5f, 0)); Handles.color = Color.black.AlphaMultiplied(0.33f); Handles.DrawLine(new Vector3(0, GUILayoutUtility.GetLastRect().yMax + 0.5f, 0), new Vector3(Screen.width, GUILayoutUtility.GetLastRect().yMax + 0.5f, 0)); Handles.color = oldColor; EditorGUILayout.BeginVertical(); GUILayout.Space(2f); EditorGUILayout.EndVertical(); // Keep repainting until all previews are loaded if (AssetPreview.IsLoadingAssetPreviews(GetInstanceID())) { Repaint(); } // Release keyboard focus on click to empty space if (Event.current.type == EventType.MouseDown) { GUIUtility.keyboardControl = 0; } }
private void CollisionPlanesSceneGUI() { if (m_ScenePlanes.Count == 0) { return; } Event evt = Event.current; Color origCol = Handles.color; Color col = new Color(1, 1, 1, 0.5F); for (int i = 0; i < m_ScenePlanes.Count; ++i) { if (m_ScenePlanes[i] == null) { continue; } Transform transform = m_ScenePlanes[i]; Vector3 position = transform.position; Quaternion rotation = transform.rotation; Vector3 right = rotation * Vector3.right; Vector3 up = rotation * Vector3.up; Vector3 forward = rotation * Vector3.forward; bool isPlayingAndStatic = EditorApplication.isPlaying && transform.gameObject.isStatic; if (editingPlanes) { if (Object.ReferenceEquals(s_SelectedTransform, transform)) { EditorGUI.BeginChangeCheck(); var newPosition = transform.position; var newRotation = transform.rotation; using (new EditorGUI.DisabledScope(isPlayingAndStatic)) { if (isPlayingAndStatic) { Handles.ShowStaticLabel(position); } if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesMove) { newPosition = Handles.PositionHandle(position, rotation); } else if (EditMode.editMode == EditMode.SceneViewEditMode.ParticleSystemCollisionModulePlanesRotate) { newRotation = Handles.RotationHandle(rotation, position); } } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(transform, "Modified Collision Plane Transform"); transform.position = newPosition; transform.rotation = newRotation; ParticleSystemEditorUtils.PerformCompleteResimulation(); } } else { float handleSize = HandleUtility.GetHandleSize(position) * 0.6f; EventType oldEventType = evt.type; // we want ignored mouse up events to check for dragging off of scene view if (evt.type == EventType.Ignore && evt.rawType == EventType.MouseUp) { oldEventType = evt.rawType; } Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.zero, Handles.RectangleHandleCap); // Detect selected plane (similar to TreeEditor) if (oldEventType == EventType.MouseDown && evt.type == EventType.Used) { s_SelectedTransform = transform; oldEventType = EventType.Used; GUIUtility.hotControl = 0; // Reset hot control or the FreeMoveHandle will prevent input to the new Handles. (case 873514) } } } Handles.color = col; Color color = Handles.s_ColliderHandleColor * 0.9f; if (isPlayingAndStatic) { color.a *= 0.2f; } if (m_PlaneVisualizationType == PlaneVizType.Grid) { DrawGrid(position, right, forward, up, color); } else { DrawSolidPlane(position, rotation, color, Color.yellow); } } Handles.color = origCol; }
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); }
static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation) { int id = GUIUtility.GetControlID(s_MoveHandleHash, FocusType.Passive); Vector3 newPos = pivot; float discSize = HandleUtility.GetHandleSize(pivot) * 0.2f; float discOpacity = (1 - GUI.color.a); Vector3[] corners = new Vector3[4]; corners[0] = rotation * new Vector2(rect.x, rect.y) + pivot; corners[1] = rotation * new Vector2(rect.xMax, rect.y) + pivot; corners[2] = rotation * new Vector2(rect.xMax, rect.yMax) + pivot; corners[3] = rotation * new Vector2(rect.x, rect.yMax) + pivot; VertexSnapping.HandleMouseMove(id); bool supportsRectSnapping = Selection.transforms.Length == 1 && UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation; Event evt = Event.current; EventType eventType = evt.GetTypeForControl(id); Plane guiPlane = new Plane(corners[0], corners[1], corners[2]); switch (eventType) { case EventType.MouseDown: { bool acceptClick = false; if (Tools.vertexDragging) { acceptClick = true; } else { acceptClick = evt.button == 0 && evt.modifiers == 0 && RectHandles.RaycastGUIPointToWorldHit(evt.mousePosition, guiPlane, out s_StartMouseWorldPos) && ( SceneViewDistanceToRectangle(corners, evt.mousePosition) == 0f || (discOpacity > 0 && SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, discSize, evt.mousePosition) == 0f) ); } if (acceptClick) { s_StartPosition = pivot; s_StartMousePos = s_CurrentMousePos = evt.mousePosition; s_Moving = false; s_LockAxis = -1; GUIUtility.hotControl = GUIUtility.keyboardControl = id; EditorGUIUtility.SetWantsMouseJumping(1); HandleUtility.ignoreRaySnapObjects = null; evt.Use(); // Calculate snapping values if applicable if (supportsRectSnapping) { Transform transform = Selection.activeTransform; RectTransform rectTransform = transform.GetComponent <RectTransform>(); Transform transformParent = transform.parent; RectTransform rectTransformParent = transformParent.GetComponent <RectTransform>(); s_StartRectPosition = rectTransform.anchoredPosition; RectTransformSnapping.CalculatePositionSnapValues(transformParent, transform, rectTransformParent, rectTransform); } } break; } case EventType.MouseDrag: { if (GUIUtility.hotControl == id) { s_CurrentMousePos += evt.delta; if (!s_Moving && (s_CurrentMousePos - s_StartMousePos).magnitude > 3f) { s_Moving = true; // Re-raycast to get start mouse pos when effective dragging starts. // This prevents a sudden unsnap when the dragging is enabled. RectHandles.RaycastGUIPointToWorldHit(s_CurrentMousePos, guiPlane, out s_StartMouseWorldPos); } if (s_Moving) { if (Tools.vertexDragging) { if (HandleUtility.ignoreRaySnapObjects == null) { Handles.SetupIgnoreRaySnapObjects(); } Vector3 near; if (HandleUtility.FindNearestVertex(s_CurrentMousePos, null, out near)) { // Snap position based on found near vertex newPos = near; GUI.changed = true; } ManipulationToolUtility.minDragDifference = Vector2.zero; } else { ManipulationToolUtility.SetMinDragDifferenceForPos(pivot); Vector3 pos; if (RectHandles.RaycastGUIPointToWorldHit(s_CurrentMousePos, guiPlane, out pos)) { Vector3 offset = pos - s_StartMouseWorldPos; // Snap to axis if (evt.shift) { // Get offset in rect handles space offset = Quaternion.Inverse(rotation) * offset; // Determine lock axis if not already set if (s_LockAxis == -1) { s_LockAxis = Mathf.Abs(offset.x) > Mathf.Abs(offset.y) ? 0 : 1; } // Cancel mocement on other axis offset[1 - s_LockAxis] = 0; // Put offset back in world space offset = rotation * offset; } else { s_LockAxis = -1; } if (supportsRectSnapping) { Transform transformParent = Selection.activeTransform.parent; Vector3 rectPosition = s_StartRectPosition + transformParent.InverseTransformVector(offset); rectPosition.z = 0; Quaternion inverseRotation = Quaternion.Inverse(rotation); Vector2 snapSize = Vector2.one * HandleUtility.GetHandleSize(newPos) * RectTransformSnapping.kSnapThreshold; snapSize.x /= (inverseRotation * transformParent.TransformVector(Vector3.right)).x; snapSize.y /= (inverseRotation * transformParent.TransformVector(Vector3.up)).y; Vector3 newRectPosition = RectTransformSnapping.SnapToGuides(rectPosition, snapSize); ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(rectPosition, newRectPosition); offset = transformParent.TransformVector(newRectPosition - s_StartRectPosition); } newPos = s_StartPosition + offset; GUI.changed = true; } } } evt.Use(); } break; } case EventType.MouseUp: { if (GUIUtility.hotControl == id) { if (!s_Moving) { Selection.activeGameObject = SceneViewPicking.PickGameObject(evt.mousePosition); } GUIUtility.hotControl = 0; EditorGUIUtility.SetWantsMouseJumping(0); HandleUtility.ignoreRaySnapObjects = null; evt.Use(); } break; } case EventType.Repaint: { if (Tools.vertexDragging) { RectHandles.RectScalingHandleCap(id, pivot, rotation, 1, EventType.Repaint); } else { Handles.color = Handles.secondaryColor * new Color(1, 1, 1, 1.5f * discOpacity); Handles.CircleHandleCap(id, pivot, rotation, discSize, EventType.Repaint); Handles.color = Handles.secondaryColor * new Color(1, 1, 1, 0.3f * discOpacity); Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, discSize); } break; } } ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingPosX, eventType); ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingLeft, eventType); ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingRight, eventType); ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingPosY, eventType); ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingTop, eventType); ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingBottom, eventType); return(newPos); }
protected override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic) { var ids = Handles.TransformHandleIds.Default; TransformManipulator.BeginManipulationHandling(false); // Lock position when scaling or rotating if (ids.scale.Has(GUIUtility.hotControl) || ids.rotation.Has(GUIUtility.hotControl)) { Tools.LockHandlePosition(); } else { Tools.UnlockHandlePosition(); } EditorGUI.BeginChangeCheck(); if (Event.current.type == EventType.MouseDown) { s_Scale = Vector3.one; } var startPosition = handlePosition; var endPosition = startPosition; var startRotation = Tools.handleRotation; var endRotation = startRotation; var startScale = s_Scale; var endScale = startScale; Handles.TransformHandle(ids, ref endPosition, ref endRotation, ref endScale, Handles.TransformHandleParam.Default); s_Scale = endScale; if (EditorGUI.EndChangeCheck() && !isStatic) { Undo.RecordObjects(Selection.transforms, "Transform Manipulation"); if (TransformManipulator.HandleHasMoved(endPosition)) { ManipulationToolUtility.SetMinDragDifferenceForPos(handlePosition); TransformManipulator.SetPositionDelta(endPosition, TransformManipulator.mouseDownHandlePosition); } Quaternion deltaRotation = Quaternion.Inverse(startRotation) * endRotation; float angle; Vector3 axis; deltaRotation.ToAngleAxis(out angle, out axis); if (!Mathf.Approximately(angle, 0)) { foreach (Transform t in Selection.transforms) { // Rotate around handlePosition (Global or Local axis). if (Tools.pivotMode == PivotMode.Center) { t.RotateAround(handlePosition, startRotation * axis, angle); } // Local rotation (Pivot mode with Local axis). else if (TransformManipulator.individualSpace) { t.Rotate(t.rotation * axis, angle, Space.World); } // Pivot mode with Global axis. else { t.Rotate(startRotation * axis, angle, Space.World); } // sync euler hints after a rotate tool update tyo fake continuous rotation t.SetLocalEulerHint(t.GetLocalEulerAngles(t.rotationOrder)); if (t.parent != null) { t.SendTransformChangedScale(); // force scale update, needed if tr has non-uniformly scaled parent. } } Tools.handleRotation = endRotation; } if (endScale != startScale) { TransformManipulator.SetScaleDelta(endScale, endRotation); } } TransformManipulator.EndManipulationHandling(); }
private static bool DrawSkeletonSubTree(Dictionary <Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones, Quaternion orientation, Transform tr, Bounds bounds, Handles.BoneRenderer boneRenderer) { // if this transform is not a valid bone if (!actualBones.ContainsKey(tr)) { return(false); } int drawnChildren = 0; foreach (Transform child in tr) { if (DrawSkeletonSubTree(actualBones, bones, orientation, child, bounds, boneRenderer)) { drawnChildren++; } } if (!actualBones[tr] && drawnChildren <= 1) { return(false); } int index = -1; if (bones != null) { for (int i = 0; i < bones.Length; i++) { if (bones[i].bone == tr) { index = i; break; } } } // There is no need to check for a pose error if the avatar is not yet valid or tools is not the active one bool poseError = AvatarSetupTool.GetBoneAlignmentError(bones, orientation, index) > 0; sPoseError |= poseError; if (poseError) { DrawPoseError(tr, bounds); Handles.color = kErrorColor; } else if (index != -1) { Handles.color = kHumanColor; } else if (!actualBones[tr]) { Handles.color = kDummyColor; } else { Handles.color = kSkeletonColor; } // Override color if bone is selected if (Selection.activeObject == tr) { Handles.color = kSelectedColor; } Handles.DoBoneHandle(tr, actualBones, boneRenderer); return(true); }
internal static Vector3 SideSlider(int id, Vector3 position, Vector3 sideVector, Vector3 direction, float size, Handles.CapFunction capFunction, float snap, float bias) { Event current = Event.current; Vector3 normalized = Vector3.Cross(sideVector, direction).normalized; Vector3 vector3 = Handles.Slider2D(id, position, normalized, direction, sideVector, 0f, capFunction, (Vector2) (Vector2.one * snap)); vector3 = position + Vector3.Project(vector3 - position, direction); EventType type = current.type; if (type != EventType.Layout) { if (type != EventType.MouseMove) { if ((type == EventType.Repaint) && (((HandleUtility.nearestControl == id) && (GUIUtility.hotControl == 0)) || (GUIUtility.hotControl == id))) { HandleDirectionalCursor(position, normalized, direction); } return vector3; } } else { Vector3 vector4 = sideVector.normalized; HandleUtility.AddControl(id, HandleUtility.DistanceToLine((Vector3) ((position + (sideVector * 0.5f)) - ((vector4 * size) * 2f)), (Vector3) ((position - (sideVector * 0.5f)) + ((vector4 * size) * 2f))) - bias); return vector3; } DetectCursorChange(id); return vector3; }
public static Vector3 ClosestPointToArc(Vector3 center, Vector3 normal, Vector3 from, float angle, float radius) { Vector3[] array = new Vector3[60]; Handles.SetDiscSectionPoints(array, center, normal, from, angle, radius); return HandleUtility.ClosestPointToPolyLine(array); }
public virtual void OnOverlayGUI(Object target, SceneView sceneView) { if (target == null) { return; } // cache some deep values var c = (Camera)target; Vector2 previewSize = c.targetTexture ? new Vector2(c.targetTexture.width, c.targetTexture.height) : GameView.GetMainGameViewTargetSize(); if (previewSize.x < 0f) { // Fallback to Scene View of not a valid game view size previewSize.x = sceneView.position.width; previewSize.y = sceneView.position.height; } // Apply normalizedviewport rect of camera Rect normalizedViewPortRect = c.rect; previewSize.x *= Mathf.Max(normalizedViewPortRect.width, 0f); previewSize.y *= Mathf.Max(normalizedViewPortRect.height, 0f); // Prevent using invalid previewSize if (previewSize.x < 1f || previewSize.y < 1f) { return; } float aspect = previewSize.x / previewSize.y; // Scale down (fit to scene view) previewSize.y = kPreviewNormalizedSize * sceneView.position.height; previewSize.x = previewSize.y * aspect; if (previewSize.y > sceneView.position.height * 0.5f) { previewSize.y = sceneView.position.height * 0.5f; previewSize.x = previewSize.y * aspect; } if (previewSize.x > sceneView.position.width * 0.5f) { previewSize.x = sceneView.position.width * 0.5f; previewSize.y = previewSize.x / aspect; } // Get and reserve rect Rect cameraRect = GUILayoutUtility.GetRect(previewSize.x, previewSize.y); if (Event.current.type == EventType.Repaint) { // setup camera and render previewCamera.CopyFrom(c); // also make sure to sync any Skybox component on the preview camera var dstSkybox = previewCamera.GetComponent <Skybox>(); if (dstSkybox) { var srcSkybox = c.GetComponent <Skybox>(); if (srcSkybox && srcSkybox.enabled) { dstSkybox.enabled = true; dstSkybox.material = srcSkybox.material; } else { dstSkybox.enabled = false; } } var previewTexture = GetPreviewTextureWithSize((int)cameraRect.width, (int)cameraRect.height); previewTexture.antiAliasing = Mathf.Max(1, QualitySettings.antiAliasing); previewCamera.targetTexture = previewTexture; previewCamera.pixelRect = new Rect(0, 0, cameraRect.width, cameraRect.height); Handles.EmitGUIGeometryForCamera(c, previewCamera); GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; if (c.usePhysicalProperties) { // when sensor size is reduced, the previous frame is still visible behing so we need to clear the texture before rendering. RenderTexture rt = RenderTexture.active; RenderTexture.active = previewTexture; GL.Clear(false, true, Color.clear); RenderTexture.active = rt; } previewCamera.Render(); GL.sRGBWrite = false; Graphics.DrawTexture(cameraRect, previewTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, GUI.color, EditorGUIUtility.GUITextureBlit2SRGBMaterial); } }
public static bool Button(Vector3 position, Quaternion direction, float size, float pickSize, Handles.DrawCapFunction capFunc) { int controlID = GUIUtility.GetControlID(Handles.s_ButtonHash, FocusType.Passive); return UnityEditorInternal.Button.Do(controlID, position, direction, size, pickSize, capFunc); }
private static Vector3 DoPlanarHandle(Handles.PlaneHandle planeID, Vector3 position, Quaternion rotation, float handleSize) { int num = 0; int num2 = 0; int hint = 0; bool flag = !Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects); switch (planeID) { case Handles.PlaneHandle.xzPlane: num = 0; num2 = 2; Handles.color = ((!flag) ? Handles.yAxisColor : Handles.staticColor); hint = Handles.s_xzAxisMoveHandleHash; break; case Handles.PlaneHandle.xyPlane: num = 0; num2 = 1; Handles.color = ((!flag) ? Handles.zAxisColor : Handles.staticColor); hint = Handles.s_xyAxisMoveHandleHash; break; case Handles.PlaneHandle.yzPlane: num = 1; num2 = 2; Handles.color = ((!flag) ? Handles.xAxisColor : Handles.staticColor); hint = Handles.s_yzAxisMoveHandleHash; break; } int index = 3 - num2 - num; Color color = Handles.color; Matrix4x4 matrix4x = Matrix4x4.TRS(position, rotation, Vector3.one); Vector3 normalized; if (Camera.current.orthographic) { normalized = matrix4x.inverse.MultiplyVector(SceneView.currentDrawingSceneView.cameraTargetRotation * -Vector3.forward).normalized; } else { normalized = matrix4x.inverse.MultiplyPoint(SceneView.currentDrawingSceneView.camera.transform.position).normalized; } int controlID = GUIUtility.GetControlID(hint, FocusType.Keyboard); if (Mathf.Abs(normalized[index]) < 0.05f && GUIUtility.hotControl != controlID) { Handles.color = color; return position; } if (!Handles.currentlyDragging) { Handles.s_PlanarHandlesOctant[num] = (float)((normalized[num] >= -0.01f) ? 1 : -1); Handles.s_PlanarHandlesOctant[num2] = (float)((normalized[num2] >= -0.01f) ? 1 : -1); } Vector3 vector = Handles.s_PlanarHandlesOctant; vector[index] = 0f; vector = rotation * (vector * handleSize * 0.5f); Vector3 vector2 = Vector3.zero; Vector3 vector3 = Vector3.zero; Vector3 vector4 = Vector3.zero; vector2[num] = 1f; vector3[num2] = 1f; vector4[index] = 1f; vector2 = rotation * vector2; vector3 = rotation * vector3; vector4 = rotation * vector4; Handles.verts[0] = position + vector + (vector2 + vector3) * handleSize * 0.5f; Handles.verts[1] = position + vector + (-vector2 + vector3) * handleSize * 0.5f; Handles.verts[2] = position + vector + (-vector2 - vector3) * handleSize * 0.5f; Handles.verts[3] = position + vector + (vector2 - vector3) * handleSize * 0.5f; Handles.DrawSolidRectangleWithOutline(Handles.verts, new Color(Handles.color.r, Handles.color.g, Handles.color.b, 0.1f), new Color(0f, 0f, 0f, 0f)); position = Handles.Slider2D(controlID, position, vector, vector4, vector2, vector3, handleSize * 0.5f, new Handles.DrawCapFunction(Handles.RectangleCap), new Vector2(SnapSettings.move[num], SnapSettings.move[num2])); Handles.color = color; return position; }
public bool DoGUI(bool hasFocus) { bool enabled = GUI.enabled; if (ms_Style == null) { ms_Style = new Constants(); ms_Style.entryEven = new GUIStyle(ms_Style.entryEven); ms_Style.entryEven.padding.left = 3; ms_Style.entryOdd = new GUIStyle(ms_Style.entryOdd); ms_Style.entryOdd.padding.left = 3; ms_Style.label = new GUIStyle(ms_Style.label); ms_Style.boldLabel = new GUIStyle(ms_Style.boldLabel); ms_Style.label.padding.left = 3; ms_Style.boldLabel.padding.left = 3; ms_Style.boldLabel.padding.top = 0; ms_Style.boldLabel.padding.bottom = 0; this.DoLocalSelectionChange(); } EditorGUIUtility.SetIconSize(ms_IconSize); if ((Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape)) { this.CancelShowCustomDiff(); Event.current.Use(); } SplitterGUILayout.BeginHorizontalSplit(this.m_HorSplit, new GUILayoutOption[0]); GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true) }; Rect theRect = GUILayoutUtility.GetRect((float)0f, (float)0f, options); this.m_FileViewWin.DoGUI(this, theRect, hasFocus); GUILayout.EndVertical(); GUILayout.BeginVertical(new GUILayoutOption[0]); this.WebLikeHistory(hasFocus); GUILayout.EndVertical(); SplitterGUILayout.EndHorizontalSplit(); if (Event.current.type == EventType.Repaint) { Handles.color = Color.black; Handles.DrawLine(new Vector3((float)(this.m_HorSplit.realSizes[0] - 1), theRect.y, 0f), new Vector3((float)(this.m_HorSplit.realSizes[0] - 1), theRect.yMax, 0f)); Handles.DrawLine(new Vector3(0f, theRect.yMax, 0f), new Vector3((float)Screen.width, theRect.yMax, 0f)); } GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.enabled = (this.m_FileViewWin.SelType == ASHistoryFileView.SelectionType.DeletedItems) && enabled; if (GUILayout.Button(EditorGUIUtility.TextContent("Recover"), ms_Style.button, new GUILayoutOption[0])) { this.m_FileViewWin.DoRecover(); } GUILayout.FlexibleSpace(); if (this.m_InRevisionSelectMode) { GUI.enabled = enabled; GUILayout.Label(EditorGUIUtility.TextContent("Select revision to compare to"), ms_Style.boldLabel, new GUILayoutOption[0]); } GUILayout.Space(10f); GUI.enabled = this.IsComparableAssetSelected() && enabled; if (GUILayout.Button(EditorGUIUtility.TextContent("Compare to Local Version"), ms_Style.button, new GUILayoutOption[0])) { this.DoShowDiff(false, this.ChangeLogSelectionRev, -1); GUIUtility.ExitGUI(); } GUI.enabled = ((this.ChangeLogSelectionRev > 0) && (this.m_ChangeLogSelectionGUID != string.Empty)) && enabled; if (GUILayout.Button(EditorGUIUtility.TextContent("Download Selected File"), ms_Style.button, new GUILayoutOption[0])) { this.DownloadFile(); } GUILayout.Space(10f); GUI.enabled = (this.ChangeLogSelectionRev > 0) && enabled; if (GUILayout.Button((this.ChangeLogSelectionRev <= 0) ? "Revert Entire Project" : ("Revert Entire Project to " + this.ChangeLogSelectionRev), ms_Style.button, new GUILayoutOption[0])) { this.DoRevertProject(); } GUI.enabled = enabled; GUILayout.EndHorizontal(); GUILayout.Space(10f); if (!this.m_SplittersOk && (Event.current.type == EventType.Repaint)) { this.m_SplittersOk = true; HandleUtility.Repaint(); } EditorGUIUtility.SetIconSize(Vector2.zero); return(true); }
public static Vector3 Slider2D(int id, Vector3 handlePos, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.DrawCapFunction drawFunc, Vector2 snap, [DefaultValue("false")] bool drawHelper) { return UnityEditorInternal.Slider2D.Do(id, handlePos, new Vector3(0f, 0f, 0f), handleDir, slideDir1, slideDir2, handleSize, drawFunc, snap, drawHelper); }
internal void OnGUI(SceneView view) { float num = Mathf.Min(view.position.width, view.position.height); if (num >= 100f) { if (Event.current.type == EventType.Repaint) { Profiler.BeginSample("SceneView.AxisSelector"); } this.HandleContextClick(view); Camera camera = view.camera; HandleUtility.PushCamera(camera); if (camera.orthographic) { camera.orthographicSize = 0.5f; } camera.cullingMask = 0; camera.transform.position = camera.transform.rotation * new Vector3(0f, 0f, -5f); camera.clearFlags = CameraClearFlags.Nothing; camera.nearClipPlane = 0.1f; camera.farClipPlane = 10f; camera.fieldOfView = view.m_Ortho.Fade(70f, 0f); SceneView.AddCursorRect(new Rect(view.position.width - 100f + 22f, 22f, 56f, 102f), MouseCursor.Arrow); Handles.SetCamera(new Rect(view.position.width - 100f, 0f, 100f, 100f), camera); Handles.BeginGUI(); this.DrawRotationLock(view); this.DrawLabels(view); Handles.EndGUI(); for (int i = 0; i < 3; i++) { Vector3 rhs = SceneViewRotation.kDirectionRotations[i] * Vector3.forward; this.dirVisible[i].target = (Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f); } float num2 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f; this.AxisSelectors(view, camera, num2, -1f, SceneViewRotation.styles.viewAxisLabelStyle); Color color = Handles.centerColor; color = Color.Lerp(color, Color.gray, this.faded2Dgray); color.a *= this.fadedVisibility; if (color.a <= 0.1f || view.isRotationLocked) { GUI.enabled = false; } Handles.color = color; int arg_27C_0 = this.m_CenterButtonControlID; Vector3 arg_27C_1 = Vector3.zero; Quaternion arg_27C_2 = Quaternion.identity; float arg_27C_3 = num2 * 0.8f; float arg_27C_4 = num2; if (SceneViewRotation.< > f__mg$cache2 == null) { SceneViewRotation.< > f__mg$cache2 = new Handles.CapFunction(Handles.CubeHandleCap); } if (Handles.Button(arg_27C_0, arg_27C_1, arg_27C_2, arg_27C_3, arg_27C_4, SceneViewRotation.< > f__mg$cache2) && !view.in2DMode && !view.isRotationLocked) { if (Event.current.clickCount == 2) { view.FrameSelected(); } else if (Event.current.shift || Event.current.button == 2) { this.ViewFromNiceAngle(view, true); } else { this.ViewSetOrtho(view, !view.orthographic); } } this.AxisSelectors(view, camera, num2, 1f, SceneViewRotation.styles.viewAxisLabelStyle); GUI.enabled = true; if (!view.in2DMode && !view.isRotationLocked) { if (Event.current.type == EditorGUIUtility.swipeGestureEventType) { Event current = Event.current; Vector3 a; if (current.delta.y > 0f) { a = Vector3.up; } else if (current.delta.y < 0f) { a = -Vector3.up; } else if (current.delta.x < 0f) { a = Vector3.right; } else { a = -Vector3.right; } Vector3 vector = -a - Vector3.forward * 0.9f; vector = view.camera.transform.TransformDirection(vector); float num3 = 0f; int dir = 0; for (int j = 0; j < 6; j++) { float num4 = Vector3.Dot(SceneViewRotation.kDirectionRotations[j] * -Vector3.forward, vector); if (num4 > num3) { num3 = num4; dir = j; } } this.ViewAxisDirection(view, dir); Event.current.Use(); } } HandleUtility.PopCamera(camera); Handles.SetCamera(camera); if (Event.current.type == EventType.Repaint) { Profiler.EndSample(); } } }
public static Vector3 Slider2D(Vector3 handlePos, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.DrawCapFunction drawFunc, float snap, [DefaultValue("false")] bool drawHelper) { int controlID = GUIUtility.GetControlID(Handles.s_Slider2DHash, FocusType.Keyboard); return Handles.Slider2D(controlID, handlePos, new Vector3(0f, 0f, 0f), handleDir, slideDir1, slideDir2, handleSize, drawFunc, new Vector2(snap, snap), drawHelper); }
internal static Vector3 SideSlider(int id, Vector3 position, Vector3 sideVector, Vector3 direction, float size, Handles.DrawCapFunction drawFunc, float snap) { return RectHandles.SideSlider(id, position, sideVector, direction, size, drawFunc, snap, 0f); }
public static float ScaleValueHandle(float value, Vector3 position, Quaternion rotation, float size, Handles.DrawCapFunction capFunc, float snap) { int controlID = GUIUtility.GetControlID(Handles.s_ScaleValueHandleHash, FocusType.Keyboard); return SliderScale.DoCenter(controlID, value, position, rotation, size, capFunc, snap); }
public static bool SelectPoints(IEditablePoint points, Transform cloudTransform, ref List <int> selection, bool firstSelect) { int controlID = GUIUtility.GetControlID(FocusType.Passive); if (Event.current.alt && Event.current.type != EventType.Repaint) { return(false); } bool result = false; Event current = Event.current; switch (current.GetTypeForControl(controlID)) { case EventType.MouseDown: if ((HandleUtility.nearestControl == controlID || firstSelect) && current.button == 0) { if (!current.shift && !EditorGUI.actionKey) { selection.Clear(); result = true; } GUIUtility.hotControl = controlID; PointEditor.s_StartMouseDragPosition = current.mousePosition; PointEditor.s_StartDragSelection = new List <int>(selection); current.Use(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID && current.button == 0) { if (!PointEditor.s_DidDrag) { int num = PointEditor.FindNearest(PointEditor.s_StartMouseDragPosition, cloudTransform, points); if (num != -1) { if (!current.shift && !EditorGUI.actionKey) { selection.Add(num); } else { int num2 = selection.IndexOf(num); if (num2 != -1) { selection.RemoveAt(num2); } else { selection.Add(num); } } } GUI.changed = true; result = true; } PointEditor.s_StartDragSelection = null; PointEditor.s_StartMouseDragPosition = Vector2.zero; PointEditor.s_DidDrag = false; GUIUtility.hotControl = 0; current.Use(); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlID && current.button == 0) { PointEditor.s_DidDrag = true; selection.Clear(); selection.AddRange(PointEditor.s_StartDragSelection); Rect rect = PointEditor.FromToRect(PointEditor.s_StartMouseDragPosition, current.mousePosition); Matrix4x4 matrix = Handles.matrix; Handles.matrix = cloudTransform.localToWorldMatrix; for (int i = 0; i < points.Count; i++) { Vector2 point = HandleUtility.WorldToGUIPoint(points.GetPosition(i)); if (rect.Contains(point)) { selection.Add(i); } } Handles.matrix = matrix; GUI.changed = true; current.Use(); } break; case EventType.Repaint: if (GUIUtility.hotControl == controlID && current.mousePosition != PointEditor.s_StartMouseDragPosition) { GUIStyle gUIStyle = "SelectionRect"; Handles.BeginGUI(); gUIStyle.Draw(PointEditor.FromToRect(PointEditor.s_StartMouseDragPosition, current.mousePosition), false, false, false, false); Handles.EndGUI(); } break; case EventType.Layout: HandleUtility.AddDefaultControl(controlID); break; } selection = selection.Distinct <int>().ToList <int>(); return(result); }
internal static extern void SetCameraFilterMode(Camera camera, Handles.FilterMode mode);
internal static void RuleMatrixOnGUI(RuleTile tile, Rect rect, RuleTile.TilingRule tilingRule) { Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f); int index = 0; float w = rect.width / 3f; float h = rect.height / 3f; for (int y = 0; y <= 3; y++) { float top = rect.yMin + y * h; Handles.DrawLine(new Vector3(rect.xMin, top), new Vector3(rect.xMax, top)); } for (int x = 0; x <= 3; x++) { float left = rect.xMin + x * w; Handles.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax)); } Handles.color = Color.white; for (int y = 0; y <= 2; y++) { for (int x = 0; x <= 2; x++) { Rect r = new Rect(rect.xMin + x * w, rect.yMin + y * h, w - 1, h - 1); if (x != 1 || y != 1) { tile.RuleOnGUI(r, new Vector2Int(x, y), tilingRule.m_Neighbors[index]); if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition)) { int change = 1; if (Event.current.button == 1) { change = -1; } var allConsts = tile.m_NeighborType.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); var neighbors = allConsts.Select(c => (int)c.GetValue(null)).ToList(); neighbors.Sort(); int oldIndex = neighbors.IndexOf(tilingRule.m_Neighbors[index]); int newIndex = (int)Mathf.Repeat(oldIndex + change, neighbors.Count); tilingRule.m_Neighbors[index] = neighbors[newIndex]; GUI.changed = true; Event.current.Use(); } index++; } else { switch (tilingRule.m_RuleTransform) { case RuleTile.TilingRule.Transform.Rotated: GUI.DrawTexture(r, autoTransforms[0]); break; case RuleTile.TilingRule.Transform.MirrorX: GUI.DrawTexture(r, autoTransforms[1]); break; case RuleTile.TilingRule.Transform.MirrorY: GUI.DrawTexture(r, autoTransforms[2]); break; } if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition)) { tilingRule.m_RuleTransform = (RuleTile.TilingRule.Transform)(((int)tilingRule.m_RuleTransform + 1) % 4); GUI.changed = true; Event.current.Use(); } } } } }
private static void RuleMatrixOnGUI(Rect rect, RuleTile.TilingRule tilingRule) { Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f); var index = 0; var w = rect.width / 3f; var h = rect.height / 3f; for (var y = 0; y <= 3; y++) { var top = rect.yMin + y * h; Handles.DrawLine(new Vector3(rect.xMin, top), new Vector3(rect.xMax, top)); } for (var x = 0; x <= 3; x++) { var left = rect.xMin + x * w; Handles.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax)); } Handles.color = Color.white; for (var y = 0; y <= 2; y++) { for (var x = 0; x <= 2; x++) { var r = new Rect(rect.xMin + x * w, rect.yMin + y * h, w - 1, h - 1); if (x != 1 || y != 1) { switch (tilingRule.m_Neighbors[index]) { case RuleTile.TilingRule.Neighbor.This: GUI.DrawTexture(r, arrows[y * 3 + x]); break; case RuleTile.TilingRule.Neighbor.NotThis: GUI.DrawTexture(r, arrows[9]); break; } if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition)) { tilingRule.m_Neighbors[index] = (RuleTile.TilingRule.Neighbor)(((int)tilingRule.m_Neighbors[index] + 1) % 3); GUI.changed = true; Event.current.Use(); } index++; } else { switch (tilingRule.m_AutoTransform) { case RuleTile.TilingRule.AutoTransform.Rotated: GUI.DrawTexture(r, autoTransforms[0]); break; case RuleTile.TilingRule.AutoTransform.MirrorX: GUI.DrawTexture(r, autoTransforms[1]); break; case RuleTile.TilingRule.AutoTransform.MirrorY: GUI.DrawTexture(r, autoTransforms[2]); break; } if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition)) { tilingRule.m_AutoTransform = (RuleTile.TilingRule.AutoTransform)(((int)tilingRule.m_AutoTransform + 1) % 4); GUI.changed = true; Event.current.Use(); } } } } }
internal static Vector3 Do(int id, Vector3 position, Vector3 direction, float size, Handles.DrawCapFunction drawFunc, float snap) { return Slider1D.Do(id, position, direction, direction, size, drawFunc, snap); }
public static float RotationSlider(int id, Vector3 cornerPos, float rotation, Vector3 pivot, Vector3 handleDir, Vector3 outwardsDir1, Vector3 outwardsDir2, float handleSize, Handles.DrawCapFunction drawFunc, Vector2 snap) { Vector3 b = outwardsDir1 + outwardsDir2; Vector2 vector = HandleUtility.WorldToGUIPoint(cornerPos); Vector2 b2 = (HandleUtility.WorldToGUIPoint(cornerPos + b) - vector).normalized * 15f; RectHandles.RaycastGUIPointToWorldHit(vector + b2, new Plane(handleDir, cornerPos), out cornerPos); Event current = Event.current; Vector3 a = Handles.Slider2D(id, cornerPos, handleDir, outwardsDir1, outwardsDir2, handleSize, drawFunc, Vector2.zero); if (current.type == EventType.MouseMove) { RectHandles.DetectCursorChange(id); } if (current.type == EventType.Repaint && ((HandleUtility.nearestControl == id && GUIUtility.hotControl == 0) || GUIUtility.hotControl == id)) { Rect position = new Rect(current.mousePosition.x - 100f, current.mousePosition.y - 100f, 200f, 200f); EditorGUIUtility.AddCursorRect(position, MouseCursor.RotateArrow); } return rotation - RectHandles.AngleAroundAxis(a - pivot, cornerPos - pivot, handleDir); }
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; Slider1D.s_CurrentMousePosition = Slider1D.s_StartMousePosition = current.mousePosition; Slider1D.s_StartPosition = position; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); break; } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); break; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { Slider1D.s_CurrentMousePosition += current.delta; float num = Handles.SnapValue(HandleUtility.CalcLineTranslation(Slider1D.s_StartMousePosition, Slider1D.s_CurrentMousePosition, Slider1D.s_StartPosition, slideDirection), snap); Vector3 vector3 = Handles.matrix.MultiplyVector(slideDirection); Vector3 v = Handles.s_Matrix.MultiplyPoint(Slider1D.s_StartPosition) + vector3 * num; position = Handles.s_InverseMatrix.MultiplyPoint(v); GUI.changed = true; current.Use(); break; } break; case EventType.Repaint: Color color = Color.white; if (id == GUIUtility.keyboardControl && GUI.enabled) { color = Handles.color; Handles.color = Handles.selectedColor; } drawFunc(id, position, Quaternion.LookRotation(handleDirection), size); if (id == GUIUtility.keyboardControl) { Handles.color = color; break; } break; case EventType.Layout: if ((MulticastDelegate) drawFunc == (MulticastDelegate) new Handles.DrawCapFunction(Handles.ArrowCap)) { HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + slideDirection * size)); HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + slideDirection * size, size * 0.2f)); break; } HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.2f)); break; } return position; }
public static float RotationSlider(int id, Vector3 cornerPos, float rotation, Vector3 pivot, Vector3 handleDir, Vector3 outwardsDir1, Vector3 outwardsDir2, float handleSize, Handles.CapFunction drawFunc, Vector2 snap) { Vector3 vector = outwardsDir1 + outwardsDir2; Vector2 vector2 = HandleUtility.WorldToGUIPoint(cornerPos); Vector2 vector3 = HandleUtility.WorldToGUIPoint(cornerPos + vector) - vector2; vector3 = (Vector2) (vector3.normalized * 15f); RaycastGUIPointToWorldHit(vector2 + vector3, new Plane(handleDir, cornerPos), out cornerPos); Event current = Event.current; Vector3 vector4 = Handles.Slider2D(id, cornerPos, handleDir, outwardsDir1, outwardsDir2, handleSize, drawFunc, Vector2.zero); if (current.type == EventType.MouseMove) { DetectCursorChange(id); } if ((current.type == EventType.Repaint) && (((HandleUtility.nearestControl == id) && (GUIUtility.hotControl == 0)) || (GUIUtility.hotControl == id))) { Rect position = new Rect(current.mousePosition.x - 100f, current.mousePosition.y - 100f, 200f, 200f); EditorGUIUtility.AddCursorRect(position, MouseCursor.RotateArrow); } return (rotation - AngleAroundAxis(vector4 - pivot, cornerPos - pivot, handleDir)); }
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 vector2 = 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))) { if (GUIUtility.hotControl != 0) { return vector2; } bool success = true; Vector3 vector3 = Handles.s_InverseMatrix.MultiplyPoint(GetMousePosition(handleDir, handlePos, ref success)); if (success) { int num = id; GUIUtility.keyboardControl = num; GUIUtility.hotControl = num; s_CurrentMousePosition = current.mousePosition; s_StartPosition = handlePos; Vector3 lhs = vector3 - handlePos; s_StartPlaneOffset.x = Vector3.Dot(lhs, slideDir1); s_StartPlaneOffset.y = Vector3.Dot(lhs, slideDir2); current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); } } return vector2; case EventType.MouseUp: if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2))) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } return vector2; case EventType.MouseMove: case EventType.KeyDown: case EventType.KeyUp: case EventType.ScrollWheel: return vector2; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { s_CurrentMousePosition += current.delta; bool flag2 = true; Vector3 point = Handles.s_InverseMatrix.MultiplyPoint(GetMousePosition(handleDir, handlePos, ref flag2)); if (flag2) { vector2.x = HandleUtility.PointOnLineParameter(point, s_StartPosition, slideDir1); vector2.y = HandleUtility.PointOnLineParameter(point, s_StartPosition, slideDir2); vector2 -= s_StartPlaneOffset; if ((snap.x > 0f) || (snap.y > 0f)) { vector2.x = Handles.SnapValue(vector2.x, snap.x); vector2.y = Handles.SnapValue(vector2.y, snap.y); } GUI.changed = true; } current.Use(); } return vector2; case EventType.Repaint: if (capFunction != null) { Color white = Color.white; if (id == GUIUtility.keyboardControl) { white = Handles.color; Handles.color = Handles.selectedColor; } capFunction(id, position, rotation, handleSize, EventType.Repaint); if (id == GUIUtility.keyboardControl) { Handles.color = white; } if (drawHelper && (GUIUtility.hotControl == id)) { Vector3[] verts = new Vector3[4]; float num2 = handleSize * 10f; verts[0] = position + ((Vector3) ((slideDir1 * num2) + (slideDir2 * num2))); verts[1] = verts[0] - ((Vector3) ((slideDir1 * num2) * 2f)); verts[2] = verts[1] - ((Vector3) ((slideDir2 * num2) * 2f)); verts[3] = verts[2] + ((Vector3) ((slideDir1 * num2) * 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 vector2; } return vector2; case EventType.Layout: if (capFunction == null) { HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(handlePos + offset, handleSize * 0.5f)); return vector2; } capFunction(id, position, rotation, handleSize, EventType.Layout); return vector2; } return vector2; }
/// <summary> /// Отрисовывает перемещаемую "точку" в редиме редактировния /// </summary> /// <param name="position">Предыдущее положение точки</param> /// <param name="handleSize">Размер видимой перемещаемой точки</param> /// <param name="capFunc">Функция отрисовки перемещаемой точки</param> /// <param name="colorSelected">Цвето точки при выделении</param> /// <param name="result">Текущее событие</param> /// <returns>Возвращает новую позицию точки</returns> 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.LeftMouseButtonPress; else if (Event.current.button == 1) result = DragHandleResult.RightMouseButtonPress; } 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.LeftMouseButtonRelease; else if (Event.current.button == 1) result = DragHandleResult.RightMouseButtonRelease; 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.LeftMouseButtonDoubleClick : DragHandleResult.LeftMouseButtonClick; else if (Event.current.button == 1) result = doubleClick ? DragHandleResult.RightMouseButtonDoubleClick : DragHandleResult.RightMouseButtonClick; } } 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.LeftMouseButtonDrag; else if (Event.current.button == 1) result = DragHandleResult.RightMouseButtonDrag; 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 Vector3 Do(int id, Vector3 position, Quaternion rotation, float size, Vector3 snap, Handles.DrawCapFunction capFunc) { bool flag; Vector3 vector = Handles.matrix.MultiplyPoint(position); Matrix4x4 matrix = Handles.matrix; VertexSnapping.HandleKeyAndMouseMove(id); Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (((HandleUtility.nearestControl == id) && (current.button == 0)) || ((GUIUtility.keyboardControl == id) && (current.button == 2))) { int num3 = id; GUIUtility.keyboardControl = num3; GUIUtility.hotControl = num3; s_CurrentMousePosition = s_StartMousePosition = current.mousePosition; s_StartPosition = position; HandleUtility.ignoreRaySnapObjects = null; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); } return position; case EventType.MouseUp: if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2))) { GUIUtility.hotControl = 0; HandleUtility.ignoreRaySnapObjects = null; 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) { return position; } flag = EditorGUI.actionKey && current.shift; if (flag) { if (HandleUtility.ignoreRaySnapObjects == null) { Handles.SetupIgnoreRaySnapObjects(); } object obj2 = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition)); if (obj2 == null) { flag = false; break; } RaycastHit hit = (RaycastHit) obj2; float num = 0f; if (Tools.pivotMode == PivotMode.Center) { float num2 = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, hit.normal); if (num2 != float.PositiveInfinity) { num = Vector3.Dot(position, hit.normal) - num2; } } position = Handles.s_InverseMatrix.MultiplyPoint(hit.point + ((Vector3) (hit.normal * num))); } break; case EventType.Repaint: { Color white = Color.white; if (id == GUIUtility.keyboardControl) { white = Handles.color; Handles.color = Handles.selectedColor; } Handles.matrix = Matrix4x4.identity; capFunc(id, vector, Camera.current.transform.rotation, size); Handles.matrix = matrix; if (id == GUIUtility.keyboardControl) { Handles.color = white; } return position; } case EventType.Layout: Handles.matrix = Matrix4x4.identity; HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(vector, size * 1.2f)); Handles.matrix = matrix; return position; default: return position; } if (!flag) { s_CurrentMousePosition += new Vector2(current.delta.x, -current.delta.y); Vector3 vector2 = Camera.current.WorldToScreenPoint(Handles.s_Matrix.MultiplyPoint(s_StartPosition)) + (s_CurrentMousePosition - s_StartMousePosition); position = Handles.s_InverseMatrix.MultiplyPoint(Camera.current.ScreenToWorldPoint(vector2)); if ((Camera.current.transform.forward == Vector3.forward) || (Camera.current.transform.forward == -Vector3.forward)) { position.z = s_StartPosition.z; } if ((Camera.current.transform.forward == Vector3.up) || (Camera.current.transform.forward == -Vector3.up)) { position.y = s_StartPosition.y; } if ((Camera.current.transform.forward == Vector3.right) || (Camera.current.transform.forward == -Vector3.right)) { position.x = s_StartPosition.x; } if (Tools.vertexDragging) { Vector3 vector3; if (HandleUtility.ignoreRaySnapObjects == null) { Handles.SetupIgnoreRaySnapObjects(); } if (HandleUtility.FindNearestVertex(current.mousePosition, null, out vector3)) { position = Handles.s_InverseMatrix.MultiplyPoint(vector3); } } if (EditorGUI.actionKey && !current.shift) { Vector3 vector4 = position - s_StartPosition; vector4.x = Handles.SnapValue(vector4.x, snap.x); vector4.y = Handles.SnapValue(vector4.y, snap.y); vector4.z = Handles.SnapValue(vector4.z, snap.z); position = s_StartPosition + vector4; } } GUI.changed = true; current.Use(); return position; }
public static float DistanceToArc(Vector3 center, Vector3 normal, Vector3 from, float angle, float radius) { Vector3[] dest = new Vector3[60]; Handles.SetDiscSectionPoints(dest, center, normal, from, angle, radius); return HandleUtility.DistanceToPolyLine(dest); }
public static float DoCenter(int id, float value, Vector3 position, Quaternion rotation, float size, Handles.DrawCapFunction capFunc, 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) { int num = id; GUIUtility.keyboardControl = num; GUIUtility.hotControl = num; SliderScale.s_StartScale = value; SliderScale.s_ValueDrag = 0.0f; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); break; } 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; } 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; } break; case EventType.KeyDown: if (GUIUtility.hotControl == id && current.keyCode == KeyCode.Escape) { value = SliderScale.s_StartScale; SliderScale.s_ScaleDrawLength = 1f; GUIUtility.hotControl = 0; GUI.changed = true; current.Use(); break; } break; case EventType.Repaint: Color color = Color.white; if (id == GUIUtility.keyboardControl) { color = Handles.color; Handles.color = Handles.selectedColor; } capFunc(id, position, rotation, size * 0.15f); if (id == GUIUtility.keyboardControl) { Handles.color = color; break; } break; case EventType.Layout: HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.15f)); break; } return value; }
public override void OnSceneGUI(ParticleSystem s, InitialModuleUI initial) { Color color = Handles.color; Handles.color = ShapeModuleUI.s_ShapeGizmoColor; Matrix4x4 matrix = Handles.matrix; Matrix4x4 matrix4x = default(Matrix4x4); matrix4x.SetTRS(s.transform.position, s.transform.rotation, s.transform.lossyScale); Handles.matrix = matrix4x; EditorGUI.BeginChangeCheck(); int intValue = this.m_Type.intValue; if (intValue == 0 || intValue == 1) { this.m_Radius.floatValue = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue, false); } if (intValue == 10 || intValue == 11) { float floatValue = this.m_Radius.floatValue; float floatValue2 = this.m_Arc.floatValue; Handles.DoSimpleRadiusArcHandleXY(Quaternion.identity, Vector3.zero, ref floatValue, ref floatValue2); this.m_Radius.floatValue = floatValue; this.m_Arc.floatValue = floatValue2; } else if (intValue == 2 || intValue == 3) { this.m_Radius.floatValue = Handles.DoSimpleRadiusHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue, true); } else if (intValue == 4 || intValue == 7) { Vector3 radiusAngleRange = new Vector3(this.m_Radius.floatValue, this.m_Angle.floatValue, initial.m_Speed.scalar.floatValue); radiusAngleRange = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange); this.m_Radius.floatValue = radiusAngleRange.x; this.m_Angle.floatValue = radiusAngleRange.y; initial.m_Speed.scalar.floatValue = radiusAngleRange.z; } else if (intValue == 8 || intValue == 9) { Vector3 radiusAngleRange2 = new Vector3(this.m_Radius.floatValue, this.m_Angle.floatValue, this.m_Length.floatValue); radiusAngleRange2 = Handles.ConeFrustrumHandle(Quaternion.identity, Vector3.zero, radiusAngleRange2); this.m_Radius.floatValue = radiusAngleRange2.x; this.m_Angle.floatValue = radiusAngleRange2.y; this.m_Length.floatValue = radiusAngleRange2.z; } else if (intValue == 5) { Vector3 zero = Vector3.zero; Vector3 vector = new Vector3(this.m_BoxX.floatValue, this.m_BoxY.floatValue, this.m_BoxZ.floatValue); if (this.m_BoxEditor.OnSceneGUI(matrix4x, ShapeModuleUI.s_ShapeGizmoColor, false, ref zero, ref vector)) { this.m_BoxX.floatValue = vector.x; this.m_BoxY.floatValue = vector.y; this.m_BoxZ.floatValue = vector.z; } } else if (intValue == 12) { this.m_Radius.floatValue = Handles.DoSimpleEdgeHandle(Quaternion.identity, Vector3.zero, this.m_Radius.floatValue); } else if (intValue == 6) { Mesh mesh = (Mesh)this.m_Mesh.objectReferenceValue; if (mesh) { bool wireframe = GL.wireframe; GL.wireframe = true; this.m_Material.SetPass(0); Graphics.DrawMeshNow(mesh, s.transform.localToWorldMatrix); GL.wireframe = wireframe; } } if (EditorGUI.EndChangeCheck()) { this.m_ParticleSystemUI.m_ParticleEffectUI.m_Owner.Repaint(); } Handles.color = color; Handles.matrix = matrix; }
/// <summary> /// Draw the control point onto Scene view /// </summary> public void DrawHandles() { #if UNITY_EDITOR bool isCtrlKeyHold = Event.current != null && Event.current.control; bool isShiftKeyHold = Event.current != null && Event.current.shift; //drag to move control point's position EditorHandles.color = Color.blue; Vector3 oldPosition = Position; Vector3 newPosition = EditorHandles.FreeMoveHandle( Position, Quaternion.identity, HandleUtility.GetHandleSize(Position) * 0.2f, Vector3.zero, EditorHandles.CircleHandleCap); newPosition.y = oldPosition.y; //restrict Y-axis movement if (newPosition != oldPosition) { if (isShiftKeyHold) { newPosition = SnapPosition(newPosition); } if (isCtrlKeyHold) { Translate(newPosition - oldPosition); } else { Position = newPosition; } } //drag to move handle's position EditorHandles.color = Color.red; for (int i = 0; i < Handles.Length; ++i) { Vector3 handleOldPosition = Handles[i]; Vector3 handleNewPosition = EditorHandles.FreeMoveHandle( Handles[i], Quaternion.identity, HandleUtility.GetHandleSize(Handles[i]) * 0.1f, Vector3.zero, EditorHandles.RectangleHandleCap); handleNewPosition.y = handleOldPosition.y; //restrict Y-axis movement if (Handles[i] != handleNewPosition) { if (isShiftKeyHold) { handleNewPosition = SnapHandle(handleNewPosition); } SetHandle(i, handleNewPosition); if (isCtrlKeyHold) { Vector3 reflectedPosition = handleNewPosition + 2 * (Position - handleNewPosition); SetHandle(Handles.Length - 1 - i, reflectedPosition); } } EditorHandles.DrawLine(Handles[i], Position); } #endif }