Example #1
0
        static public PickerScrollRect AddColumn(GameObject columnList, bool zoom, bool horizontal)
        {
            GameObject column = new GameObject("Column");

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

            GameObject content = new GameObject("Content");

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

            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);
        }
Example #2
0
        protected virtual void RebuildLayout()
        {
            PickerLayoutGroup layout = GetComponentInParent <PickerLayoutGroup>();

            if (layout != null)
            {
                layout.RebuildLayout();
            }
        }
Example #3
0
        protected static void CopyField(PickerLayoutGroup src, PickerLayoutGroup dst)
        {
            if (src == null || dst == null)
            {
                return;
            }

            dst.scrollRect     = src.scrollRect;
            dst.spacing        = src.spacing;
            dst.childPivot     = src.childPivot;
            dst.padding        = src.padding;
            dst.childAlignment = src.childAlignment;
        }
Example #4
0
        protected override void OnBeforeTransformParentChanged()
        {
            base.OnBeforeTransformParentChanged();

            if (transform.parent != null)
            {
                PickerLayoutGroup parentLayoutGroup = transform.parent.GetComponent <PickerLayoutGroup>();

                if (parentLayoutGroup != null)
                {
                    parentLayoutGroup.UnregisterItem(this);
                }
            }
        }
Example #5
0
        protected void ScrollToSelf()
        {
            PickerLayoutGroup layout = GetComponentInParent <PickerLayoutGroup>();

            if (layout == null)
            {
                return;
            }

            PickerScrollRect psr = layout.scrollRect;

            if (psr == null)
            {
                return;
            }

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

            if (columns == null || itemList == null || num < 1 || 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 <ZoomPickerLayoutGroup>() != null;

                PickerScrollRect  exampleScrollRect      = columnList.GetComponentInChildren <PickerScrollRect>();
                PickerLayoutGroup exampleLayoutGroup     = null;
                PickerLayoutGroup exampleZoomLayoutGroup = null;

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

                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

                    PickerScrollRect scrollRect = column.AddComponent <PickerScrollRect>();
                    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)
                    {
                        PickerLayoutGroup layoutGroup = content.AddComponent <PickerLayoutGroup>();
                        CopyField(exampleLayoutGroup, layoutGroup);
                        layoutGroup.scrollRect = scrollRect;
                    }
                    else
                    {
                        ZoomPickerLayoutGroup layoutGroup = content.AddComponent <ZoomPickerLayoutGroup>();
                        CopyField(exampleZoomLayoutGroup, layoutGroup);
                        layoutGroup.scrollRect = scrollRect;
                    }

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

                    Util.CopyField(exampleImage, image);

                    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;

                    GameObject.DestroyImmediate(column);
                }
            }
        }