Esempio n. 1
0
        public static GameObject CreateLoopVerticalScrollRect(DefaultControls.Resources resources)
        {
            GameObject root = CreateUIElementRoot("Loop Vertical Scroll Rect", new Vector2(200, 200));

            GameObject content = CreateUIObject("Content", root);

            RectTransform contentRT = content.GetComponent <RectTransform>();

            contentRT.anchorMin = new Vector2(0.5f, 1);
            contentRT.anchorMax = new Vector2(0.5f, 1);
            contentRT.sizeDelta = new Vector2(200, 0);
            contentRT.pivot     = new Vector2(0.5f, 1);

            // Setup UI components.

            LoopVerticalScrollRect scrollRect = root.AddComponent <LoopVerticalScrollRect>();

            scrollRect.content                       = contentRT;
            scrollRect.viewport                      = null;
            scrollRect.horizontalScrollbar           = null;
            scrollRect.verticalScrollbar             = null;
            scrollRect.horizontal                    = false;
            scrollRect.vertical                      = true;
            scrollRect.horizontalScrollbarVisibility = LoopScrollRect.EScrollbarVisibility.Permanent;
            scrollRect.verticalScrollbarVisibility   = LoopScrollRect.EScrollbarVisibility.Permanent;
            scrollRect.horizontalScrollbarSpacing    = 0;
            scrollRect.verticalScrollbarSpacing      = 0;

            root.AddComponent <RectMask2D>();

            VerticalLayoutGroup layoutGroup = content.AddComponent <VerticalLayoutGroup>();

            layoutGroup.childAlignment         = TextAnchor.UpperCenter;
            layoutGroup.childForceExpandWidth  = true;
            layoutGroup.childForceExpandHeight = false;

            ContentSizeFitter sizeFitter = content.AddComponent <ContentSizeFitter>();

            sizeFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
            sizeFitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

            return(root);
        }