public static GameObject CreateLoopHorizontalScrollRect(DefaultControls.Resources resources)
{
GameObject root = CreateUIElementRoot("Loop Horizontal Scroll Rect", new Vector2(200, 200));
GameObject content = CreateUIObject("Content", root);
RectTransform contentRT = content.GetComponent<RectTransform>();
contentRT.anchorMin = new Vector2(0, 0.5f);
contentRT.anchorMax = new Vector2(0, 0.5f);
contentRT.sizeDelta = new Vector2(0, 200);
contentRT.pivot = new Vector2(0, 0.5f);
// Setup UI components.
LoopHorizontalScrollRect scrollRect = root.AddComponent<LoopHorizontalScrollRect>();
scrollRect.content = contentRT;
scrollRect.viewport = null;
scrollRect.horizontalScrollbar = null;
scrollRect.verticalScrollbar = null;
scrollRect.horizontal = true;
scrollRect.vertical = false;
scrollRect.horizontalScrollbarVisibility = LoopScrollRect.ScrollbarVisibility.Permanent;
scrollRect.verticalScrollbarVisibility = LoopScrollRect.ScrollbarVisibility.Permanent;
scrollRect.horizontalScrollbarSpacing = 0;
scrollRect.verticalScrollbarSpacing = 0;
root.AddComponent<RectMask2D>();
HorizontalLayoutGroup layoutGroup = content.AddComponent<HorizontalLayoutGroup>();
layoutGroup.childAlignment = TextAnchor.MiddleLeft;
layoutGroup.childForceExpandWidth = false;
layoutGroup.childForceExpandHeight = true;
ContentSizeFitter sizeFitter = content.AddComponent<ContentSizeFitter>();
sizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
sizeFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained;
return root;
}