コード例 #1
0
        void HandleThisObject()
        {
            RectTransform rect = gameObject.AddOrGetComponent<RectTransform>();
            float w = rect.rect.width;
            float h = rect.rect.height;
            rect.anchorMin = Vector2.one / 2;
            rect.anchorMax = Vector2.one / 2;
            rect.sizeDelta = new Vector2(h, w);
            var fold = gameObject.AddOrGetComponent<LayoutFoldController>();
            if (fold.foldButton == null)
            {
                foldButton = CreateFoldButton();
                foldButton.name = "FoldButton";
                fold.foldButton = foldButton;

            }
            else
                foldButton = fold.foldButton;
            var foldStatusText = fold.foldButton.GetComponentInChildren<Text>();
            foldStatusText.name = "FoldStatusText";
            fold.foldLabelText = foldStatusText;
            Fold(fold);
            foldStatusText.text=fold.GetFoldString();
            VerticalLayoutGroup group = gameObject.AddOrGetComponent<VerticalLayoutGroup>();
            group.SetChildControl(2);
            Fold(group);
            panel = gameObject.AddOrGetComponent<LayoutPanel>();
            if (panel.resizableElement == null)
                panel.resizableElement = content;
        }
コード例 #2
0
        void Rescan()
        {
            VerticalLayoutGroup verticalLayoutGroup = gameObject.AddOrGetComponent <VerticalLayoutGroup>();

            verticalLayoutGroup.SetChildControl();
            verticalLayoutGroup.spacing = LayoutBorderDragger.borderSize * 3;
            int spacerIndex = -1;

            if (spacer == null)
            {
                FindSpacer();
            }
            for (int i = 0; i < transform.childCount; i++)
            {
                LayoutElement element = transform.GetChild(i).GetComponent <LayoutElement>();
                if (element != null)
                {
                    if (element.flexibleWidth > 0.1f)
                    {
                        element.flexibleWidth = 0.0144f;
                    }
                    if (element.flexibleHeight > 0.1f)
                    {
                        element.flexibleHeight = 0.0044f;
                    }
                }
            }

            if (spacer != null)
            {
                spacerIndex = spacer.transform.GetSiblingIndex();

                for (int i = 0; i < transform.childCount; i++)
                {
                    var thisChild = transform.GetChild(i).gameObject;
                    var thisPanel = thisChild.GetComponent <LayoutPanel>();
                    if (thisPanel != null)
                    {
                        thisPanel.hasSiblingTop    = i > 0 && transform.GetChild(i - 1).GetComponent <LayoutPanel>() != null;
                        thisPanel.hasSiblingBottom = i < transform.childCount - 1 && transform.GetChild(i + 1).GetComponent <LayoutPanel>() != null;
                        thisPanel.isAlignedBottom  = thisPanel.transform.GetSiblingIndex() > spacerIndex;
                    }
                }
            }
            else
            {
                Debug.Log("nospacer");
            }
            gameObject.AddOrGetComponent <VerticalLayoutGroup>().SetChildControl();
            gameObject.AddOrGetComponent <VerticalLayoutGroup>().spacing = LayoutBorderDragger.borderSize * 3;
        }
コード例 #3
0
        public void AddBordersAndSampleContent()
        {
            if (name.Contains(LayoutPanel.spacerName))
            {
                name = "Item " + zExt.RandomString(4);
            }
            AddBordersOnly();
            var fold = gameObject.AddOrGetComponent <LayoutFoldController>();

            if (fold.foldButton == null)
            {
                foldButton      = CreateFoldButton();
                fold.foldButton = foldButton;
            }
            else
            {
                foldButton = fold.foldButton;
            }
            Fold(fold);
            VerticalLayoutGroup group = gameObject.AddOrGetComponent <VerticalLayoutGroup>();

            group.SetChildControl(2);
            Fold(group);
            content               = gameObject.AddImageChild().AddOrGetComponent <LayoutElement>();
            content.minHeight     = LayoutTopControl.topHeight;
            content.minWidth      = 26;
            content.flexibleWidth = 0.001f;
            content.GetComponent <Image>().enabled = false;
            content.name = "CONTENT";
            Fold(content);
            layoutBorderHide = gameObject.AddOrGetComponent <LayoutBorderHide>();
#if UNITY_EDITOR
            Selection.activeObject = content;
#endif

            Fold(GetComponent <RectTransform>());
            TryToGetReferences();

            var panel = gameObject.AddOrGetComponent <LayoutPanel>();
            if (panel.resizableElement == null)
            {
                panel.resizableElement = content;
            }
        }
コード例 #4
0
        static void GroupToLayouVt()
        {
            GameObject g = Selection.activeGameObject;

            Undo.RecordObject(g, "Layout");
            if (g == null)
            {
                return;
            }
            RectTransform rect = CreateGroup();

            if (rect != null)
            {
                VerticalLayoutGroup layout = rect.gameObject.AddComponent <VerticalLayoutGroup>();
                layout.SetMargin(defaultSpacing);
                layout.SetChildControl(defaultSpacing);
                rect.AddContentSizeFitter();
            }
        }