Esempio n. 1
0
        /// <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;
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        /// <summary>
        /// 当前选择的对象发生更改
        /// </summary>
        private void SelectionChanged()
        {
            var obj = Selection.activeObject;

            if (!(obj != null &&
                  CanvasUtil.TryGetRectTransform(obj as GameObject, out SelectedUIElement) &&
                  CanvasUtil.TryGetRootCanvas(SelectedUIElement.gameObject, out SelectedRootCanvas) &&
                  SelectedUIElement.gameObject != SelectedRootCanvas.gameObject))
            {
                OnDeselect();
            }
        }
Esempio n. 5
0
        private void ShowPackageMenu()
        {
            var objs = new List <GameObject>();

            Transform parentTrans = null;

            foreach (var obj in Selection.gameObjects)
            {
                if (CanvasUtil.TryGetRectTransform(obj, out var rect))
                {
                    if (parentTrans != null && parentTrans != obj.transform.parent)
                    {
                        EditorUtility.DisplayDialog("出错了", "不能跨节点打包", "好的");
                        return;
                    }

                    parentTrans = obj.transform.parent;
                    objs.Add(obj);
                }
            }

            if (objs.Count <= 0)
            {
                return;
            }

            UIHelperContextMenu.AddItem("打包成原子", false, PackageAtom, objs);
            UIHelperContextMenu.AddItem("打包成模组", false, PackageModule, objs);
            if (objs.Count == 1 && objs[0].transform.childCount > 0)
            {
                UIHelperContextMenu.AddSeparator("");
                UIHelperContextMenu.AddItem("打散", false, Unpack, objs[0]);
            }

            UIHelperContextMenu.Show();
        }