示例#1
0
        static public MassivePickerScrollRect AddMassiveColumn(GameObject columnList, bool zoom, bool horizontal)
        {
            GameObject column = new GameObject("Column");

            GameObjectUtility.SetParentAndAlign(column, columnList);
            MassivePickerScrollRect scrollRect = column.AddComponent <MassivePickerScrollRect>();

            GameObject content = new GameObject("Content");

            GameObjectUtility.SetParentAndAlign(content, column);
            MassivePickerLayoutGroup layoutGroup = (!zoom ? content.AddComponent <MassivePickerLayoutGroup>() : content.AddComponent <MassiveZoomPickerLayoutGroup>());

            scrollRect.content = (RectTransform)layoutGroup.transform;
            scrollRect.layout  = (horizontal ? RectTransform.Axis.Horizontal : RectTransform.Axis.Vertical);

            layoutGroup.scrollRect = scrollRect;
            layoutGroup.spacing    = 3f;

            Image scrollImage = column.AddComponent <Image>();

            scrollImage.sprite = (Sprite)AssetDatabase.LoadAssetAtPath(!horizontal ? CanvasSpritePath : CanvasRotateSpritePath, typeof(Sprite));
            scrollImage.type   = Image.Type.Sliced;

            Mask scrollMask = column.AddComponent <Mask>();

            scrollMask.showMaskGraphic = true;

            return(scrollRect);
        }
示例#2
0
        protected override void Reset()
        {
            base.Reset();

            MassivePickerLayoutGroup layoutGroup = GetComponentInChildren <MassivePickerLayoutGroup>();

            if (layoutGroup != null)
            {
                content = layoutGroup.GetComponent <RectTransform>();
            }
        }
示例#3
0
        public MassivePickerItem GetSelectedPickerItem()
        {
            MassivePickerLayoutGroup layout = pickerLayoutGroup;

            if (layout != null)
            {
                return(pickerLayoutGroup.GetPickerItem(beforeSelectedItemIndex));
            }

            return(null);
        }
示例#4
0
        protected static void CopyField(MassivePickerLayoutGroup src, MassivePickerLayoutGroup dst)
        {
            if (src == null || dst == null)
            {
                return;
            }

            dst.spacing    = src.spacing;
            dst.childPivot = src.childPivot;
            dst.scrollRect = src.scrollRect;
        }
示例#5
0
        protected void ScrollToSelf()
        {
            MassivePickerLayoutGroup layout = GetComponentInParent <MassivePickerLayoutGroup>();

            if (layout == null)
            {
                return;
            }

            MassivePickerScrollRect psr = layout.scrollRect;

            if (psr == null)
            {
                return;
            }

            psr.ScrollTo(this);
        }
示例#6
0
        public void SetColumns(int num)
        {
            MassivePickerScrollRect[] columns = this.columns;

            if (columns == null || itemList == null || num <= 0 || columns.Length == num && itemList.Count == num || columnList == null)
            {
                return;
            }

            if (itemList.Count < num)
            {
                for (int i = itemList.Count; i < num; ++i)
                {
                    itemList.Add(new ItemListType());
                }
            }
            else if (itemList.Count > num)
            {
                itemList.RemoveRange(num, itemList.Count - num);
            }

            if (columns.Length < num)
            {
                bool zoom = columnList.GetComponentInChildren <MassiveZoomPickerLayoutGroup>() != null;

                MassivePickerScrollRect  exampleScrollRect      = columnList.GetComponentInChildren <MassivePickerScrollRect>();
                MassivePickerLayoutGroup exampleLayoutGroup     = null;
                MassivePickerLayoutGroup exampleZoomLayoutGroup = null;

                if (!zoom)
                {
                    exampleLayoutGroup = columnList.GetComponentInChildren <MassivePickerLayoutGroup>();
                }
                else
                {
                    exampleZoomLayoutGroup = columnList.GetComponentInChildren <MassiveZoomPickerLayoutGroup>();
                }

                Image exampleImage = columnList.GetComponentInChildren <Image>();

                for (int i = columns.Length; i < num; ++i)
                {
                    GameObject column = new GameObject("Column");
#if UNITY_EDITOR
                    Undo.RegisterCreatedObjectUndo(column, "Column");
#endif

                    MassivePickerScrollRect scrollRect = column.AddComponent <MassivePickerScrollRect>();

                    Image image = column.AddComponent <Image>();
                    column.AddComponent <Mask>().showMaskGraphic = true;
                    column.transform.SetParent(columnList.transform);
                    column.transform.localScale = Vector3.one;

                    GameObject content = new GameObject("Content");
                    content.transform.SetParent(column.transform);

#if UNITY_EDITOR
                    Undo.RegisterCreatedObjectUndo(column, "content");
#endif

                    if (!zoom)
                    {
                        MassivePickerLayoutGroup layoutGroup = content.AddComponent <MassivePickerLayoutGroup>();
                        CopyField(exampleLayoutGroup, layoutGroup);
                        layoutGroup.scrollRect = scrollRect;
                    }
                    else
                    {
                        MassiveZoomPickerLayoutGroup layoutGroup = content.AddComponent <MassiveZoomPickerLayoutGroup>();
                        CopyField(exampleZoomLayoutGroup, layoutGroup);
                        layoutGroup.scrollRect = scrollRect;
                    }

                    CopyField(exampleScrollRect, scrollRect);
                    scrollRect.content = (RectTransform)content.transform;

                    Util.CopyField(exampleImage, image);

                    scrollRect.deactiveItemOnAwake = IsItemChild(scrollRect);

                    itemList[i] = new ItemListType();
                }
            }
            else if (columns.Length > num)
            {
                for (int i = columns.Length - 1, j = num; i >= j; --i)
                {
                    GameObject column = columnList.GetChild(i).gameObject;
                    Util.DestroyObject(column);
                }
            }
        }