private static void DrawUIDummyGizmo(UIDummy component, GizmoType gizmoType) { var gameObject = component?.gameObject; if (gameObject == null) { return; } if (!(CanvasUtil.TryGetRootCanvas(gameObject, out var canvas) && CanvasUtil.TryGetRectTransform(gameObject, out var rect))) { return; } var canvasRect = CanvasUtil.GetCanvasRect(rect); var center = canvasRect.Center; var mat4x4 = canvas.transform.localToWorldMatrix; foreach (var dummy in component.Dummys) { if (dummy == null) { continue; } Vector3 offset = dummy.Offset; DrawDummyCross(mat4x4, center + offset, dummy.AliasName, Color.red); } }
/// <summary> /// 画当前UI单元的辅助线 /// </summary> private static void DrawElementGuideline() { if (!(HelperSettings.GridVisible && HelperSettings.GuideVisible && SnapHelper.SelectedUIElement != null)) { return; } var color = HelperSettings.GuideColor; var canvasRect = CanvasUtil.GetCanvasRect(SnapHelper.SelectedUIElement); const float MAX = 100000f; const float MIN = -100000f; var oldMatrix = Gizmos.matrix; Gizmos.color = color; Gizmos.matrix = SnapHelper.SelectedRootCanvas.transform.localToWorldMatrix; var rect = canvasRect.Rect; Gizmos.DrawLine(new Vector3(rect.xMin, MIN, 0f), new Vector3(rect.xMin, MAX, 0f)); Gizmos.DrawLine(new Vector3(rect.xMax, MIN, 0f), new Vector3(rect.xMax, MAX, 0f)); Gizmos.DrawLine(new Vector3(MIN, rect.yMin, 0f), new Vector3(MAX, rect.yMin, 0f)); Gizmos.DrawLine(new Vector3(MIN, rect.yMax, 0f), new Vector3(MAX, rect.yMax, 0f)); Gizmos.matrix = oldMatrix; }
private bool GetCorrectElementPosition(out CanvasRect canvasRect, out Vector3 position) { canvasRect = new CanvasRect(); position = Vector3.zero; if (!HelperSettings.GridSnap) { return(false); } canvasRect = CanvasUtil.GetCanvasRect(SelectedUIElement); var rect = canvasRect.Rect; var topLeft = new Vector3(rect.xMin, rect.yMax, 0); var gridSizeX = HelperSettings.GridSize.x; var gridSizeY = HelperSettings.GridSize.y; var canvasHalfSize = SelectedRootCanvas.pixelRect.size * 0.5f; var tx = Mathf.Clamp(Convert.ToInt32(Mathf.Round(topLeft.x / gridSizeX) * gridSizeX), -canvasHalfSize.x, canvasHalfSize.x); var ty = Mathf.Clamp(Convert.ToInt32(Mathf.Round(topLeft.y / gridSizeY) * gridSizeY), -canvasHalfSize.y, canvasHalfSize.y); position = new Vector3(tx, ty, 0); return(true); }