public void OnEndDrag(PointerEventData e)
        {
            if (!dragEnabled)
            {
                return;
            }
            panel.AddOrGetComponent <CanvasGroup>().blocksRaycasts   = true;
            panel.gameObject.AddOrGetComponent <CanvasGroup>().alpha = 1;
            if (LayoutDropTarget.currentTarget != null)
            {
                panel.PlaceDropTarget(LayoutDropTarget.currentTarget.dropTarget, LayoutDropTarget.currentTarget.targetDropIndex);
            }
            else
            {
                panel.PlaceDropTarget(savedParent, savedSibilingIndex);
            }
            var ll = panel.GetComponent <LayoutElement>();

            if (ll != null)
            {
                ll.ignoreLayout = wasIgnore;
            }
            draggedItem = null;
            Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
        }
        public void OnBeginDrag(PointerEventData e)
        {
            if (canvas == null)
            {
                canvas = GetComponentInParent <Canvas>();
            }
            if (!dragEnabled)
            {
                return;
            }
            if (panel == null)
            {
                panel = GetComponentInParent <LayoutPanel>();
            }

            savedParent        = panel.transform.parent;
            savedSibilingIndex = panel.transform.GetSiblingIndex();
            var ll = panel.GetComponent <LayoutElement>();

            {
                if (ll != null)
                {
                    wasIgnore       = ll.ignoreLayout;
                    ll.ignoreLayout = true;
                }
            }
            panel.AddOrGetComponent <CanvasGroup>().blocksRaycasts = false;
            panel.AddOrGetComponent <CanvasGroup>().alpha          = dragOpacity;
            draggedItem = this;
            panel.PlaceDropTarget(canvas.transform, -1);
            Cursor.SetCursor(zResourceLoader.panCursor, LayoutBorderDragger.cursorCenter, CursorMode.Auto);
        }
Пример #3
0
 void TryToGetReferences()
 {
     if (topControl == null) topControl = GetComponentInChildren<LayoutTopControl>();
     if (panel == null) panel = gameObject.GetComponent<LayoutPanel>();
     if (foldController == null) foldController = gameObject.GetComponent<LayoutFoldController>();
     if (foldController != null) foldButton = foldController.foldButton;
     if (layoutBorderHide == null) layoutBorderHide = GetComponent<LayoutBorderHide>();
 }
Пример #4
0
        public void AddBordersOnly()
        {
            int count = System.Enum.GetNames(typeof(LayoutBorderDragger.Side)).Length;

            for (int i = 0; i < count; i++)
            {
                var a = gameObject.AddImageChild();
                var d = a.gameObject.AddComponent <LayoutBorderDragger>();
                if (borderOverScan > 0)
                {
                    var text = a.gameObject.AddTextChild();
                    text.text            = null;
                    text.supportRichText = false;
                    text.GetComponent <RectTransform>().sizeDelta        = new Vector2(borderOverScan, borderOverScan);
                    text.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
                    text.name  = "raycast catcher";
                    text.font  = font;
                    text.color = textColor;
                }

                d.side = (LayoutBorderDragger.Side)i;
#if UNITY_EDITOR
                Undo.RegisterCreatedObjectUndo(a.gameObject, "borders");
#endif
            }
            topControl = GetComponentInChildren <LayoutTopControl>();
            if (topControl == null)
            {
                var topImage = gameObject.AddImageChild();
                topControl = topImage.gameObject.AddOrGetComponent <LayoutTopControl>();
                if (layoutCreator != null)
                {
                    topImage.color = layoutCreator.topColor;
                }
            }
            Text labelText = topControl.GetComponentInChildren <Text>();

            if (labelText == null)
            {
                labelText = topControl.gameObject.AddTextChild();

                labelText.name      = "Panel Label";
                labelText.text      = name;
                labelText.font      = font;
                labelText.alignment = TextAnchor.MiddleLeft;
                labelText.color     = textColor;
                var textRect = labelText.GetComponent <RectTransform>();

                textRect.anchorMin        = new Vector2(0f, 0f);
                textRect.anchorMax        = new Vector2(1f, 1f);
                textRect.anchoredPosition = new Vector2(-7.5f, 0f);
                textRect.sizeDelta        = new Vector2(-25f, 4f);
                textRect.pivot            = new Vector2(0.5f, 0.5f);
            }
        }
Пример #5
0
        public void AddTop()
        {
            topControl = GetComponentInChildren<LayoutTopControl>();
            if (topControl == null)
            {
                var topImage = gameObject.AddImageChild();
                if (layoutBorderHide != null) topImage.color = layoutBorderHide.borderColor.Randomize();
                topControl = topImage.gameObject.AddOrGetComponent<LayoutTopControl>();
                if (layoutCreator != null)
                {
                    topImage.color = layoutCreator.topColor;
                }
#if UNITY_EDITOR
                Undo.RegisterCreatedObjectUndo(topControl.gameObject, "top");
#endif
            }
            topControl.transform.SetAsFirstSibling();
        }
Пример #6
0
        public void OnEndDrag(PointerEventData e)
        {
            if (!dragEnabled)
            {
                return;
            }
            panel.AddOrGetComponent <CanvasGroup>().blocksRaycasts   = true;
            panel.gameObject.AddOrGetComponent <CanvasGroup>().alpha = 1;
            panel.freeMode = savedFreeDragState;

            if (!freeDrag)
            {
                Debug.Log("was non freedrag");
                if (LayoutDropTarget.currentTarget != null)
                {
                    Debug.Log("current target was " + LayoutDropTarget.currentTarget.name);
                    panel.PlaceDropTarget(LayoutDropTarget.currentTarget.dropTarget, LayoutDropTarget.currentTarget.targetDropIndex);
                }
                else
                {
                    Debug.Log("was no target");
                    panel.PlaceDropTarget(savedParent, savedSibilingIndex);
                }
                var ll = panel.GetComponent <LayoutElement>();
                if (ll != null)
                {
                    ll.ignoreLayout = wasIgnore;
                }
            }
            else
            {
                Debug.Log("was freedrag");
            }
            Debug.Log("ended drag");
            draggedItem = null;
            Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
        }