Exemple #1
0
        int GetMovementTypeIndex()
        {
            int[] counter    = new int[movementTypeToIndex.Count];
            int   totalCount = 0;

            foreach (Object component in targets)
            {
                PickerScrollRect psr = component as PickerScrollRect;
                if (psr == null)
                {
                    continue;
                }

                ++totalCount;

                int index;

                if (movementTypeToIndex.TryGetValue(psr.movementType, out index))
                {
                    ++counter[index];
                }
            }

            for (int i = 0; i < counter.Length; ++i)
            {
                if (counter[i] == totalCount)
                {
                    return(i);
                }
            }

            return(counter.Length);
        }
Exemple #2
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);
        }
Exemple #3
0
        protected bool _AddItem(int columnIndex, GameObject item)
        {
            if (item == null)
            {
                return(false);
            }

            PickerScrollRect scroll = GetPickerScrollRect(columnIndex);

            if (scroll == null)
            {
                return(false);
            }

            item.transform.SetParent(scroll.content.transform);

            EffectBase effect = GetComponentInParent <EffectBase>();

            if (effect != null)
            {
                effect.SetEffectComponentToAllChildGraphics(item.transform);
            }

            return(true);
        }
Exemple #4
0
        protected void ChangeScrollRect(System.Action <PickerScrollRect> func)
        {
            foreach (Object obj in targets)
            {
                PickerScrollRect psr = obj as PickerScrollRect;

                if (psr != null)
                {
                    func(psr);
                }
            }
        }
Exemple #5
0
        public void SetItems(int columnIndex, IList <ItemParamType> itemParams, bool fromInspector = false)
        {
            PickerScrollRect scroll = GetPickerScrollRect(columnIndex);

            if (scroll == null)
            {
                return;
            }

            RectTransform rectTransform = scroll.content;

            if (rectTransform == null)
            {
                return;
            }

            if (!fromInspector)
            {
                itemList[columnIndex].items = itemParams.ToList();
            }

            int childCount = rectTransform.childCount;

            if (itemParams.Count < childCount)
            {
                for (int i = childCount - 1; i >= itemParams.Count; --i)
                {
                    GameObject.DestroyImmediate(rectTransform.GetChild(i).gameObject);
                }

                childCount = itemParams.Count;
            }

            int itemIndex = 0;

            for (int itemCount = Mathf.Min(itemParams.Count, childCount); itemIndex < itemCount; ++itemIndex)
            {
                Transform     childTransform = rectTransform.GetChild(itemIndex);
                ItemComponent item           = childTransform.GetComponent <ItemComponent>();
                UpdateItem(item, itemParams[itemIndex]);
            }

            for (int i = itemIndex; itemIndex < itemParams.Count; ++itemIndex)
            {
                GameObject item = CreateItem(itemParams[i]);

                if (item != null)
                {
                    _AddItem(columnIndex, item);
                }
            }
        }
Exemple #6
0
        static public GameObject AddPicker(MenuCommand command, string name, bool zoom, bool horizontal, bool noitem)
        {
            GameObject pickerRoot = MenuOptions.CreateUIElementRoot(name, command, MenuOptions.s_ImageGUIElementSize);

            GameObject columnList = new GameObject("ColumnList");

            GameObjectUtility.SetParentAndAlign(columnList, pickerRoot);

#if UNITY_5_4_UNDER
            columnList.AddComponent(horizontal ? typeof(VerticalLayoutGroup) : typeof(HorizontalLayoutGroup));
#else
            if (horizontal)
            {
                VerticalLayoutGroup group = columnList.AddComponent <VerticalLayoutGroup>();
                group.childControlWidth  = true;
                group.childControlHeight = true;
            }
            else
            {
                HorizontalLayoutGroup group = columnList.AddComponent <HorizontalLayoutGroup>();
                group.childControlWidth  = true;
                group.childControlHeight = true;
            }
#endif

            RectTransform rect = (RectTransform)columnList.transform;
            rect.anchorMin = Vector2.zero;
            rect.anchorMax = Vector2.one;
            rect.sizeDelta = new Vector2(-20, -20);

            PickerScrollRect column = AddColumn(columnList, zoom, horizontal);

            GameObject glass = AddGlass(pickerRoot, zoom, horizontal);
            AddFrame(pickerRoot);

            if (!noitem)
            {
                for (int itemIndex = 0; itemIndex < 3; ++itemIndex)
                {
                    AddItem(column.content.gameObject, zoom, horizontal, itemIndex);
                }
            }

            if (zoom)
            {
                column.content.GetComponent <ZoomPickerLayoutGroup>().zoomItemParent = glass.transform;
            }

            return(pickerRoot);
        }
Exemple #7
0
        protected Object[] GetRecordObjects()
        {
            List <Object> objects = new List <Object>();

            foreach (Object obj in targets)
            {
                PickerScrollRect psr = obj as PickerScrollRect;

                if (psr != null)
                {
                    objects.AddRange(psr.GetComponentsInChildren <Component>());
                }
            }

            return(objects.ToArray());
        }
Exemple #8
0
        protected void ScrollToSelf()
        {
            PickerLayoutGroup layout = GetComponentInParent <PickerLayoutGroup>();

            if (layout == null)
            {
                return;
            }

            PickerScrollRect psr = layout.scrollRect;

            if (psr == null)
            {
                return;
            }

            psr.ScrollTo(this);
        }
Exemple #9
0
        public void RemoveItem(int columnIndex, int itemIndex)
        {
            PickerScrollRect scrollRect = GetPickerScrollRect(columnIndex);

            if (scrollRect == null)
            {
                return;
            }

            Transform scrollTransform = scrollRect.content.transform;

            if (itemIndex < 0 || scrollTransform.childCount <= itemIndex)
            {
                return;
            }

            Transform itemTransform = scrollTransform.GetChild(itemIndex);

            GameObject.DestroyImmediate(itemTransform.gameObject);

            itemList[columnIndex].items.RemoveAt(itemIndex);
        }
Exemple #10
0
        protected static void CopyField(PickerScrollRect src, PickerScrollRect dst)
        {
            if (src == null || dst == null)
            {
                return;
            }

            dst.autoScrollSeconds        = src.autoScrollSeconds;
            dst.slipVelocityRate         = src.slipVelocityRate;
            dst.onSelectItem             = src.onSelectItem;
            dst.initialPosition          = src.initialPosition;
            dst.initialPositionItemIndex = src.initialPositionItemIndex;
            dst.layout                        = src.layout;
            dst.wheelEffect                   = src.wheelEffect;
            dst.wheelPerspective              = src.wheelPerspective;
            dst.movementType                  = src.movementType;
            dst.content                       = src.content;
            dst.horizontal                    = src.horizontal;
            dst.vertical                      = src.vertical;
            dst.elasticity                    = src.elasticity;
            dst.inertia                       = src.inertia;
            dst.decelerationRate              = src.decelerationRate;
            dst.scrollSensitivity             = src.scrollSensitivity;
            dst.viewport                      = src.viewport;
            dst.horizontalScrollbar           = src.horizontalScrollbar;
            dst.verticalScrollbar             = src.verticalScrollbar;
            dst.horizontalScrollbarVisibility = src.horizontalScrollbarVisibility;
            dst.verticalScrollbarVisibility   = src.verticalScrollbarVisibility;
            dst.horizontalScrollbarSpacing    = src.horizontalScrollbarSpacing;
            dst.verticalScrollbarSpacing      = src.verticalScrollbarSpacing;
            dst.onValueChanged                = src.onValueChanged;
            dst.velocity                      = src.velocity;
            dst.normalizedPosition            = src.normalizedPosition;
            dst.horizontalNormalizedPosition  = src.horizontalNormalizedPosition;
            dst.verticalNormalizedPosition    = src.verticalNormalizedPosition;
        }
Exemple #11
0
        RectTransform.Axis GetLayout()
        {
            int horizontal = 0;
            int vertical   = 0;
            int count      = 0;

            foreach (Object component in targets)
            {
                PickerScrollRect psr = component as PickerScrollRect;
                if (psr == null)
                {
                    continue;
                }

                ++count;

                if (psr.horizontal)
                {
                    ++horizontal;
                }
                else
                {
                    ++vertical;
                }
            }

            if (count == horizontal)
            {
                return(RectTransform.Axis.Horizontal);
            }
            if (count == vertical)
            {
                return(RectTransform.Axis.Vertical);
            }
            return((RectTransform.Axis) int.MaxValue);
        }
Exemple #12
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);
                }
            }
        }