Example #1
0
        //------------------------------------------------------------------------------------------外部可用接口

        /// <summary>
        /// 初始化item
        /// </summary>
        /// <param name="defaultID">默认选中id</param>
        /// <param name="scrollList">自定义[id,item]</param>
        public void Init <T>(int defaultID = 0, Dictionary <string, T> scrollList = null) where T : FScrollItem
        {
            if (scrollList != null)
            {
                ScollList                = new List <FScollObject>();
                Content.pivot            = Content.anchorMax = Content.anchorMin = new Vector2(0.5f, 0.5f);
                Content.anchoredPosition = new Vector3(0, 0, 0);
                int count = 0;

                foreach (var item2 in scrollList.Keys)
                {
                    RectTransform rt   = scrollList[item2].GetComponent <RectTransform>();
                    IFScrollItem  item = rt.GetComponent <IFScrollItem>();
                    int           id   = int.Parse(item2);

                    if (item != null)
                    {
                        item.OnScrollInit(this, id);
                    }

                    if (rt != null)
                    {
                        rt.pivot     = rt.anchorMax = rt.anchorMin = new Vector2(0.5f, 0.5f);
                        rt.sizeDelta = ScrollSize;
                        if (SlideType == FSlideType.Horizontal)
                        {
                            rt.anchoredPosition = new Vector2(count * (ScrollSize.x + Margin.x), 0);
                        }
                        else
                        {
                            rt.anchoredPosition = new Vector2(0, -count * (ScrollSize.y + Margin.y));
                        }
                        FScollObject fs = new FScollObject(rt, id, rt.anchoredPosition, rt.anchoredPosition);
                        sizeUpdata(fs);
                        ScollList.Add(fs);
                    }
                    count++;
                }

                if (ScollList.Count > 0)
                {
                    NowItemID = -1;
                    MoveToItemID(defaultID);
                }
            }
            else
            {
                Init(defaultID);
            }
        }
Example #2
0
        public void Init(int defultID = 0)
        {
            ScollList                = new List <FScollObject>();
            Content.pivot            = Content.anchorMax = Content.anchorMin = new Vector2(0.5f, 0.5f);
            Content.anchoredPosition = new Vector3(0, 0, 0);
            for (int i = 0; i < Content.childCount; i++)
            {
                RectTransform rt   = Content.GetChild(i).GetComponent <RectTransform>();
                IFScrollItem  item = rt.GetComponent <IFScrollItem>();
                if (item != null)
                {
                    item.OnScrollInit(this, i);
                }

                if (rt != null)
                {
                    rt.pivot     = rt.anchorMax = rt.anchorMin = new Vector2(0.5f, 0.5f);
                    rt.sizeDelta = ScrollSize;
                    if (SlideType == FSlideType.Horizontal)
                    {
                        rt.anchoredPosition = new Vector2(i * (ScrollSize.x + Margin.x), 0);
                    }
                    else
                    {
                        rt.anchoredPosition = new Vector2(0, -i * (ScrollSize.y + Margin.y));
                    }
                    FScollObject fs = new FScollObject(rt, i, rt.anchoredPosition, rt.anchoredPosition);
                    sizeUpdata(fs);
                    ScollList.Add(fs);
                }
            }
            if (ScollList.Count > 0)
            {
                NowItemID = -1;
                MoveToItemID(defultID);
            }
        }