示例#1
0
        /// <summary>
        /// アイテムを作成
        /// </summary>
        /// <param name="itemNum">アイテムの数</param>
        /// <param name="callbackCreateItem">アイテムが作成されるときに呼ばれるコールバック</param>
        public void CreateItems(int itemNum, System.Action <GameObject, int> callbackCreateItem)
        {
            Content.anchoredPosition = Vector2.zero;
            ScrollRect.velocity      = Vector2.zero;
            ClearItems();
            for (int i = 0; i < itemNum; ++i)
            {
                GameObject go = UtageToolKit.AddChildPrefab(Content, ItemPrefab.gameObject);
                items.Add(go);
                if (null != callbackCreateItem)
                {
                    callbackCreateItem(go, i);
                }
            }
            PositionGroup.Reposition();
            bool isStopScrool = IsContentInnerScrollRect() && IsStopScroolWithAllInnner;

            switch (ScrollType)
            {
            case Type.Horizontal:
                ScrollRect.horizontal = !isStopScrool;
                ScrollRect.vertical   = false;
                break;

            case Type.Vertical:
                ScrollRect.horizontal = false;
                ScrollRect.vertical   = !isStopScrool;
                break;
            }
        }
示例#2
0
        public void Reposition()
        {
            Content.anchoredPosition = Vector2.zero;
            ScrollRect.velocity      = Vector2.zero;
            if (PositionGroup != null)
            {
                PositionGroup.Reposition();
            }
            bool isStopScrool = IsContentInnerScrollRect() && IsStopScroolWithAllInnner;

            switch (ScrollType)
            {
            case Type.Horizontal:
                ScrollRect.horizontal = !isStopScrool;
                ScrollRect.vertical   = false;
                if (isAutoCenteringOnRepostion)
                {
                    if (isStopScrool)
                    {
                        float offset = (this.ScrollRectTransform.sizeDelta.x - Content.sizeDelta.x) / 2;
                        Content.anchoredPosition = new Vector3(offset, 0, 0);
                    }
                    else
                    {
                        ScrollRect.horizontalNormalizedPosition = 0.5f;
                    }
                }
                break;

            case Type.Vertical:
                ScrollRect.horizontal = false;
                ScrollRect.vertical   = !isStopScrool;
                if (isAutoCenteringOnRepostion)
                {
                    if (isStopScrool)
                    {
                        float offset = -(this.ScrollRectTransform.sizeDelta.y - Content.sizeDelta.y) / 2;
                        Content.anchoredPosition = new Vector3(0, offset, 0);
                    }
                    else
                    {
                        ScrollRect.verticalNormalizedPosition = 0.5f;
                    }
                }
                break;
            }
            ScrollRect.enabled = !isStopScrool;
        }