UnityEngine.UI.SGDefaultControls.CreateLoopVerticalScrollRect C# (CSharp) Method

CreateLoopVerticalScrollRect() public static method

public static CreateLoopVerticalScrollRect ( DefaultControls resources ) : GameObject
resources DefaultControls
return UnityEngine.GameObject
        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.ScrollbarVisibility.Permanent;
            scrollRect.verticalScrollbarVisibility = LoopScrollRect.ScrollbarVisibility.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;
        }