Exemplo n.º 1
0
 public override void SetItemContents(Picker.MassivePickerScrollRect scrollRect, int itemIndex)
 {
     if (m_Text != null)
     {
         m_Text.text = CountryNames[itemIndex];
     }
 }
        int GetMovementTypeIndex()
        {
            int[] counter    = new int[movementTypeToIndex.Count];
            int   totalCount = 0;

            foreach (Object component in targets)
            {
                MassivePickerScrollRect psr = component as MassivePickerScrollRect;
                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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
 public override void SetItemContents(Picker.MassivePickerScrollRect scrollRect, int itemIndex)
 {
     if (m_Text != null)
     {
         m_Text.text = "Item" + itemIndex;
     }
 }
Exemplo n.º 5
0
        public int GetColumnIndex(MassivePickerScrollRect scrollRect)
        {
            if (columns == null)
            {
                return(-1);
            }

            return(System.Array.IndexOf(columns, scrollRect));
        }
Exemplo n.º 6
0
 public override void SetItemContents(Picker.MassivePickerScrollRect scrollRect, int itemIndex)
 {
     if (m_Texts != null && m_Texts.Length > 0)
     {
         string tmp = "Item" + itemIndex;
         foreach (Text text in m_Texts)
         {
             text.text = tmp;
         }
     }
 }
Exemplo n.º 7
0
        public ItemParamType GetItemParam(int columnIndex, int itemIndex)
        {
            MassivePickerScrollRect scrollRect = GetPickerScrollRect(columnIndex);

            if (scrollRect == null)
            {
                return(default(ItemParamType));
            }

            return(itemList[columnIndex].items[itemIndex]);
        }
Exemplo n.º 8
0
        public void RemoveItem(int columnIndex, int itemIndex)
        {
            MassivePickerScrollRect scrollRect = GetPickerScrollRect(columnIndex);

            if (scrollRect == null)
            {
                return;
            }

            itemList[columnIndex].items.RemoveAt(itemIndex);
            scrollRect.UpdateAllItemContent();
        }
        protected void ChangeScrollRect(System.Action <MassivePickerScrollRect> func)
        {
            foreach (Object obj in targets)
            {
                MassivePickerScrollRect psr = obj as MassivePickerScrollRect;

                if (psr != null)
                {
                    func(psr);
                }
            }
        }
Exemplo n.º 10
0
 public override void SetItemContents(Picker.MassivePickerScrollRect scrollRect, int itemIndex)
 {
     if (m_Texts != null && m_Texts.Length > 0)
     {
         int    year = 2015 - itemIndex;
         string tmp  = year.ToString();
         foreach (Text text in m_Texts)
         {
             text.text = tmp;
         }
     }
 }
        protected Object[] GetRecordObjects()
        {
            List <Object> objects = new List <Object>();

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

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

            return(objects.ToArray());
        }
Exemplo n.º 12
0
        public void SetItems(int columnIndex, IList <ItemParamType> itemParams, bool fromInspector = false)
        {
            MassivePickerScrollRect scroll = GetPickerScrollRect(columnIndex);

            if (scroll == null)
            {
                return;
            }

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

            scroll.itemSize  = itemSize;
            scroll.itemCount = itemList[columnIndex].items.Count;
            scroll.UpdateAllItemContent();
        }
Exemplo n.º 13
0
        protected void ScrollToSelf()
        {
            MassivePickerLayoutGroup layout = GetComponentInParent <MassivePickerLayoutGroup>();

            if (layout == null)
            {
                return;
            }

            MassivePickerScrollRect psr = layout.scrollRect;

            if (psr == null)
            {
                return;
            }

            psr.ScrollTo(this);
        }
Exemplo n.º 14
0
        public void AddItem(int columnIndex, ItemParamType param)
        {
            if (itemList == null)
            {
                return;
            }

            if (columnIndex < 0 || itemList.Count <= columnIndex)
            {
                throw new System.ArgumentOutOfRangeException();
            }

            itemList[columnIndex].items.Add(param);

            MassivePickerScrollRect scroll = GetPickerScrollRect(columnIndex);

            ++scroll.itemCount;

            scroll.UpdateAllItemContent();
        }
Exemplo n.º 15
0
        protected static void CopyField(MassivePickerScrollRect src, MassivePickerScrollRect 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.wheelEffect         = src.wheelEffect;
            dst.itemSize            = src.itemSize;
            dst.deactiveItemOnAwake = src.deactiveItemOnAwake;
            dst.itemSource          = src.itemSource;
            dst.itemCount           = src.itemCount;
            dst.layout                        = src.layout;
            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;
        }
Exemplo n.º 16
0
        public override void SetItemContents(MassivePickerScrollRect scrollRect, int itemIndex)
        {
            if (m_Parent == null)
            {
                m_Parent = scrollRect.GetComponentInParent <MassiveStringPicker>();

                if (m_Parent == null)
                {
                    return;
                }
            }

            if (m_ColumnIndex < 0)
            {
                m_ColumnIndex = m_Parent.GetColumnIndex(scrollRect);

                if (m_ColumnIndex < 0)
                {
                    return;
                }
            }

            if (m_Texts == null)
            {
                m_Texts = GetComponentsInChildren <Text>();

                if (m_Texts == null)
                {
                    return;
                }
            }

            string text = m_Parent.GetItemParam(m_ColumnIndex, itemIndex);

            foreach (Text textComponent in m_Texts)
            {
                textComponent.text = text;
            }
        }
Exemplo n.º 17
0
        protected bool IsItemChild(MassivePickerScrollRect rect)
        {
            GameObject item = rect.itemSource;

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

            Transform itemTransform = item.transform;

            while (itemTransform != null)
            {
                itemTransform = itemTransform.parent;

                if (itemTransform == this.transform)
                {
                    return(true);
                }
            }

            return(false);
        }
        RectTransform.Axis GetLayout()
        {
            int horizontal = 0;
            int vertical   = 0;
            int count      = 0;

            foreach (Object component in targets)
            {
                MassivePickerScrollRect psr = component as MassivePickerScrollRect;
                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);
        }
Exemplo n.º 19
0
        public override void SetItemContents(MassivePickerScrollRect scrollRect, int itemIndex)
        {
            if (m_Parent == null)
            {
                m_Parent = scrollRect.GetComponentInParent <MassiveImagePicker>();

                if (m_Parent == null)
                {
                    return;
                }
            }

            if (m_ColumnIndex < 0)
            {
                m_ColumnIndex = m_Parent.GetColumnIndex(scrollRect);

                if (m_ColumnIndex < 0)
                {
                    return;
                }
            }

            if (m_Image == null)
            {
                m_Image = GetComponent <Image>();

                if (m_Image == null)
                {
                    return;
                }
            }

            Sprite sprite = m_Parent.GetItemParam(m_ColumnIndex, itemIndex);

            m_Image.sprite = sprite;
        }
Exemplo n.º 20
0
 protected override void Reset()
 {
     m_ScrollRect = GetComponentInParent <MassivePickerScrollRect>();
 }
Exemplo n.º 21
0
 protected override void OnTransformParentChanged()
 {
     base.OnTransformParentChanged();
     m_ScrollRect = GetComponentInParent <MassivePickerScrollRect>();
 }
Exemplo n.º 22
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);
                }
            }
        }
Exemplo n.º 23
0
        static public GameObject AddMassivePicker(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);

            MassivePickerScrollRect column = AddMassiveColumn(columnList, zoom, horizontal);

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

            if (!noitem)
            {
                GameObject itemSource = new GameObject("ItemSource");
                GameObjectUtility.SetParentAndAlign(itemSource, pickerRoot);

                Vector2 itemSize = horizontal ? new Vector2(15, 50) : new Vector2(50, 20);

                if (!zoom)
                {
                    itemSource.AddComponent <ExampleStringItem>();
                }
                else
                {
                    ExampleZoomStringItem item     = itemSource.AddComponent <ExampleZoomStringItem>();
                    GameObject            zoomItem = new GameObject("zoomItem");
                    GameObjectUtility.SetParentAndAlign(zoomItem, itemSource);
                    SetExampleMassiveItemText(zoomItem, true);
                    RectTransform zoomItemRect = zoomItem.GetComponent <RectTransform>();
                    zoomItemRect.sizeDelta  = itemSize;
                    zoomItemRect.localScale = Vector3.one * 1.2f;
                    item.zoomItem           = zoomItem.transform;
                }

                SetExampleMassiveItemText(itemSource);

                RectTransform itemRectTransform = itemSource.GetComponent <RectTransform>();
                itemRectTransform.sizeDelta = itemSize;
                itemRectTransform.SetSiblingIndex(zoom ? 2 : 1);

                column.deactiveItemOnAwake = true;
                column.itemSource          = itemSource;
                column.itemSize            = itemRectTransform.sizeDelta;
                column.itemCount           = 10;
            }

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

            return(pickerRoot);
        }
Exemplo n.º 24
0
 public virtual void SetItemContents(MassivePickerScrollRect scrollRect, int itemIndex)
 {
     Debug.LogWarning("SetItemContens() is not overrided. It's necessary to attach the script which expanded MassivePickerItem to an item.");
 }