/// <summary>
        /// 初始化此控件.
        /// </summary>
        public CenterView Init()
        {
            if (horizontal)
            {
                content.pivot = new Vector2(0, 0.5f); //内容的原点在最左边.
            }
            else if (vertical)
            {
                content.pivot = new Vector2(0.5f, 1f); //内容的原点在最上边.
            }
            m_totalPage = content.childCount - 1;

            m_end = -((RectTransform)content.GetChild(0).transform).anchoredPosition;
            SetContentAnchoredPosition(m_end);

            foreach (RectTransform child in content)
            {
                CenterViewItem item = child.GetComponent <CenterViewItem>();
                if (item == null)
                {
                    item = child.gameObject.AddComponent <CenterViewItem>();
                }
                item.index         = child.GetSiblingIndex();
                item.clickToCenter = clickItemToCenter;
                m_all.Add(item);
            }
            m_all.Sort();
            for (int i = 0; i < m_totalPage + 1; i++)
            {
                CenterViewItem item = m_all[i] as CenterViewItem;
                ((RectTransform)item.transform).SetSiblingIndex(i);
                Vector3 v = item.transform.localPosition;
                v.z = i;
                item.transform.localPosition = v;
            }
            m_all.Clear();

            if (horizontal)
            {
                _scaleXRenders();
            }
            else if (vertical)
            {
                _scaleYRenders();
            }

            LayoutGroup group = transform.GetComponentInChildren <LayoutGroup>();

            if (group)
            {
                group.enabled = false;
            }

            if (pageIndicator)
            {
                pageIndicator.iPage = this;
                pageIndicator.Build(totalPage + 1);
            }
            return(this);
        }
示例#2
0
        /// <summary>
        /// 用于排序.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(object other)
        {
            CenterViewItem item = other as CenterViewItem;

            if (this.index > item.index)
            {
                return(1);
            }
            else if (this.index < item.index)
            {
                return(-1);
            }
            return(0);
        }
示例#3
0
        /// <summary>
        /// 初始化此控件.
        /// </summary>
        public CenterView Init()
        {
            if (horizontal)
            {
                content.pivot = new Vector2(0, 0.5f);                 //内容的原点在最左边.
            }
            else if (vertical)
            {
                content.pivot = new Vector2(0.5f, 1f);                 //内容的原点在最上边.
            }
            m_totalPage = content.childCount - 1;


//			Vector2 itemPos = Vector2.one;
//			Vector2 itemSize = Vector2.one;
//			Vector2 itemAnchorMin = Vector2.one;
//			Vector2 itemAnchorMax = Vector2.one;
//			Vector2 itemPivot = Vector2.one;
//			Vector2 itemOffsetMin = Vector2.one;
//			Vector2 itemOffsetMax = Vector2.one;
//			List<Vector2> pos = new List<Vector2>();
//
//			if (content.childCount > 0) {
//				RectTransform child = content.GetChild (0).transform as RectTransform;
//				itemSize = child.sizeDelta;
//				itemPos = child.anchoredPosition;
//				itemAnchorMin = child.anchorMin;
//				itemAnchorMax = child.anchorMax;
//				itemPivot = child.pivot;
//				itemOffsetMin = child.offsetMin;
//				itemOffsetMax = child.offsetMax;
//				foreach (RectTransform ch in content)
//				{
//					pos.Add(ch.anchoredPosition);
//				}
//			}

            LayoutGroup group = transform.GetComponentInChildren <LayoutGroup>();

            if (group && Application.isPlaying)
            {
                group.enabled = false;
            }

            int i = 0;

            foreach (RectTransform child in content)
            {
//				itemPivot = child.pivot;
//				child.offsetMin = itemOffsetMin;
//				child.offsetMax = itemOffsetMax;
//				child.anchorMin = itemAnchorMin;
//				child.anchorMax = itemAnchorMax;
//				child.sizeDelta = itemSize;
//				child.anchoredPosition = pos[i];

                if (m_centerItem == null)
                {
                    m_centerItem = child;
                }

                CenterViewItem item = child.GetComponent <CenterViewItem>();
                if (item == null)
                {
                    item = child.gameObject.AddComponent <CenterViewItem>();
                }
//				LayoutGroup childGroup = item.GetComponent<LayoutGroup>();
//				if(childGroup && childGroup.enabled){
//					childGroup.enabled = false;
//					childGroup.enabled = true;
//				}
                item.index         = child.GetSiblingIndex();
                item.clickToCenter = clickItemToCenter;
                m_all.Add(item);
                ++i;
            }

            m_end = -((RectTransform)content.GetChild(0).transform).anchoredPosition;
            SetContentAnchoredPosition(m_end);

            m_all.Sort();
            for (i = 0; i < m_totalPage + 1; i++)
            {
                CenterViewItem item = m_all[i] as CenterViewItem;
                ((RectTransform)item.transform).SetSiblingIndex(i);
                Vector3 v = item.transform.localPosition;
                v.z = i;
                item.transform.localPosition = v;
            }
            m_all.Clear();

            if (horizontal)
            {
                _scaleXRenders();
            }
            else if (vertical)
            {
                _scaleYRenders();
            }

            if (pageIndicator)
            {
                pageIndicator.iPage = this;
                pageIndicator.Build(totalPage + 1);
            }
            return(this);
        }