예제 #1
0
        protected void Setup()
        {
            if (transform.parent == null)
            {
                return;
            }

            ZoomPickerLayoutGroup group = transform.parent.GetComponent <ZoomPickerLayoutGroup>();

            if (group == null)
            {
                return;
            }

            Transform zoomItemParent = group.zoomItemParent;

            if (zoomItemParent == null)
            {
                return;
            }

            if (zoomItem != null)
            {
                foreach (Graphic graphic in zoomItem.GetComponentsInChildren <Graphic>(true))
                {
                    SetupZoomGraphic(graphic, zoomItemParent);
                }
            }
        }
예제 #2
0
        protected static void CopyField(ZoomPickerLayoutGroup src, ZoomPickerLayoutGroup dst)
        {
            if (src == null || dst == null)
            {
                return;
            }

            dst.zoomItemParent = src.zoomItemParent;
            dst.scrollRect     = src.scrollRect;
            dst.spacing        = src.spacing;
            dst.childPivot     = src.childPivot;
            dst.padding        = src.padding;
            dst.childAlignment = src.childAlignment;
        }
예제 #3
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);
                }
            }
        }