Esempio n. 1
0
        private GameObject CreateScroll(ScrollNode node, GameObject gameObject)
        {
            int            scrollDirect = node.scrollDirect;
            LoopScrollRect rect         = null;

            if (scrollDirect == 0)
            {
                rect          = gameObject.AddComponent <LoopHorizontalScrollRect>();
                rect.vertical = false;
            }
            else
            {
                rect            = gameObject.AddComponent <LoopVerticalScrollRect>();
                rect.horizontal = false;
            }

            gameObject    = CreateStretchObject("Viewport", gameObject);
            rect.viewport = gameObject.GetComponent <RectTransform>();
            gameObject    = CreateStretchObject("Content", gameObject);
            rect.content  = gameObject.GetComponent <RectTransform>();

            rect.content.anchorMax = Vector2.one * 0.5f;
            rect.content.anchorMin = Vector2.one * 0.5f;

            rect.content.sizeDelta = rect.GetComponent <RectTransform>().sizeDelta;
            if (node.type.ToString().Contains(UINodeType.gscroll.ToString()))
            {
                SetLayout(rect.content.gameObject.AddComponent <GridLayoutGroup>(), node as GScrollNode);
            }
            else if (node.type.ToString().StartsWith("h"))
            {
                SetLayout(rect.content.gameObject.AddComponent <HorizontalLayoutGroup>(), node as ScrollNode);
            }
            else
            {
                SetLayout(rect.content.gameObject.AddComponent <VerticalLayoutGroup>(), node as ScrollNode);
            }

            return(gameObject);
        }
Esempio n. 2
0
 private void SetLayout(HorizontalLayoutGroup layout, ScrollNode node)
 {
     layout.spacing = node.space;
     layout.childForceExpandWidth  = false;
     layout.childForceExpandHeight = false;
 }