示例#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);
            }
        }
示例#2
0
        /// <summary>
        /// 控制item在不同位置的大小
        /// </summary>
        void sizeUpdata(FScollObject fobject)
        {
            float fz         = Vector2.Distance(fobject.rectTransform.anchoredPosition, Vector2.zero);
            float sizeOffset = 1;

            if (SlideType == FSlideType.Horizontal)
            {
                sizeOffset = fz / ((ScrollSize.x + Margin.x) * 1.0f);
            }
            else
            {
                sizeOffset = fz / ((ScrollSize.y + Margin.y) * 1.0f);
            }

            if (sizeOffset > 1)
            {
                sizeOffset = 1;
            }
            fobject.rectTransform.localScale = Vector2.one * (PicthScale * (1 - sizeOffset) + 1);
        }
示例#3
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);
            }
        }