Пример #1
0
        /* currently just using items in the list instead of being able to add to it.
         * public void AddItems(params object[] list)
         * {
         *      List<DropDownListItem> ddItems = new List<DropDownListItem>();
         *      foreach (var obj in list)
         *      {
         *              if (obj is DropDownListItem)
         *              {
         *                      ddItems.Add((DropDownListItem)obj);
         *              }
         *              else if (obj is string)
         *              {
         *                      ddItems.Add(new DropDownListItem(caption: (string)obj));
         *              }
         *              else if (obj is Sprite)
         *              {
         *                      ddItems.Add(new DropDownListItem(image: (Sprite)obj));
         *              }
         *              else
         *              {
         *                      throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed");
         *              }
         *      }
         *      Items.AddRange(ddItems);
         *      Items = Items.Distinct().ToList();//remove any duplicates
         *      RebuildPanel();
         * }
         */

        /// <summary>
        /// Rebuilds the contents of the panel in response to items being added.
        /// </summary>
        private void RebuildPanel()
        {
            if (Items.Count == 0)
            {
                return;
            }

            int indx = _panelItems.Count;

            while (_panelItems.Count < Items.Count)
            {
                GameObject newItem = Instantiate(_itemTemplate) as GameObject;
                newItem.name = "Item " + indx;
                newItem.transform.SetParent(_itemsPanelRT, false);

                _panelItems.Add(new DropDownListButton(newItem));
                indx++;
            }
            for (int i = 0; i < _panelItems.Count; i++)
            {
                if (i < Items.Count)
                {
                    DropDownListItem item = Items[i];



                    _panelItems[i].txt.text = item.Caption;
                    if (item.IsDisabled)
                    {
                        _panelItems[i].txt.color = disabledTextColor;
                    }

                    if (_panelItems[i].btnImg != null)
                    {
                        _panelItems[i].btnImg.sprite = null;                                                   //hide the button image
                    }
                    _panelItems[i].img.sprite = item.Image;
                    _panelItems[i].img.color  = (item.Image == null) ? new Color(1, 1, 1, 0)
                                                                                                                                        : item.IsDisabled ? new Color(1, 1, 1, .5f)
                                                                                                                                                                          : Color.white;
                    int ii = i;                     //have to copy the variable for use in anonymous function
                    _panelItems[i].btn.onClick.RemoveAllListeners();
                    _panelItems[i].btn.onClick.AddListener(() =>
                    {
                        OnItemClicked(ii);
                        if (item.OnSelect != null)
                        {
                            item.OnSelect();
                        }
                    });


                    if (_panelItems[i].gameobject.GetComponent <DropDownItem>())
                    {
                        _panelItems[i].gameobject.GetComponent <DropDownItem>().SetValue(item.Value);
                    }
                }
                _panelItems[i].gameobject.SetActive(i < Items.Count);                // if we have more thanks in the panel than Items in the list hide them
            }
        }
 // Use this for initialization
 void Start()
 {
     dropList = GetComponent<DropDownList> ();
     for (int i = 0; i < QualitySettings.names.Length; i++) {
     DropDownListItem newButton = new DropDownListItem (QualitySettings.names[i]);
     dropList.AddItems (newButton);
     }
     txt.text = QualitySettings.names[QualitySettings.GetQualityLevel()];
 }
 // Use this for initialization
 void Start()
 {
     dropList = GetComponent<DropDownList> ();
     resolutions = Screen.resolutions;
     for (int i = 0; i < resolutions.Length; i++) {
     DropDownListItem newButton = new DropDownListItem (ResToString(resolutions[i]));
     dropList.AddItems (newButton);
     }
     txt.text = ResToString(Screen.currentResolution);
 }
Пример #4
0
 // Use this for initialization
 void Start()
 {
     dropList = GetComponent <DropDownList> ();
     for (int i = 0; i < QualitySettings.names.Length; i++)
     {
         DropDownListItem newButton = new DropDownListItem(QualitySettings.names[i]);
         dropList.AddItems(newButton);
     }
     txt.text = QualitySettings.names[QualitySettings.GetQualityLevel()];
 }
Пример #5
0
 // Use this for initialization
 void Start()
 {
     dropList    = GetComponent <DropDownList> ();
     resolutions = Screen.resolutions;
     for (int i = 0; i < resolutions.Length; i++)
     {
         DropDownListItem newButton = new DropDownListItem(ResToString(resolutions[i]));
         dropList.AddItems(newButton);
     }
     txt.text = ResToString(Screen.currentResolution);
 }
 static public int get_Image(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.DropDownListItem self = (UnityEngine.UI.Extensions.DropDownListItem)checkSelf(l);
         pushValue(l, self.Image);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_Image(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.DropDownListItem self = (UnityEngine.UI.Extensions.DropDownListItem)checkSelf(l);
         UnityEngine.Sprite v;
         checkType(l, 2, out v);
         self.Image = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #8
0
 // Use this for initialization
 void Start()
 {
     dropList = GetComponent<DropDownList> ();
     savedCoords = GameObject.Find ("World Data Storage").GetComponent<WorldSavedCoordinates>();
     movement = GameObject.Find ("World Loading Object").GetComponent<WorldMovement> ();
     coords = savedCoords.GetSavedLocations ();
     int numLocations = coords.GetLength (0) - 1;
     //Debug.Log (numLocations);
     for (int i = 0; i <= numLocations; i++) {
         string locationName = savedCoords.GetLocationName(i);
         DropDownListItem newButton = new DropDownListItem (locationName);
         dropList.AddItems (newButton);
     }
 }
Пример #9
0
        private void RebuildPanel()
        {
            if (Items.Count == 0)
            {
                return;
            }
            int num = _panelItems.Count;

            while (_panelItems.Count < Items.Count)
            {
                GameObject gameObject = Object.Instantiate(_itemTemplate);
                gameObject.name = "Item " + num;
                gameObject.transform.SetParent(_itemsPanelRT, worldPositionStays: false);
                _panelItems.Add(new DropDownListButton(gameObject));
                num++;
            }
            for (int i = 0; i < _panelItems.Count; i++)
            {
                if (i < Items.Count)
                {
                    DropDownListItem item = Items[i];
                    _panelItems[i].txt.text = item.Caption;
                    if (item.IsDisabled)
                    {
                        _panelItems[i].txt.color = disabledTextColor;
                    }
                    if (_panelItems[i].btnImg != null)
                    {
                        _panelItems[i].btnImg.sprite = null;
                    }
                    _panelItems[i].img.sprite = item.Image;
                    _panelItems[i].img.color  = ((item.Image == null) ? new Color(1f, 1f, 1f, 0f) : ((!item.IsDisabled) ? Color.white : new Color(1f, 1f, 1f, 0.5f)));
                    int ii = i;
                    _panelItems[i].btn.onClick.RemoveAllListeners();
                    _panelItems[i].btn.onClick.AddListener(delegate
                    {
                        OnItemClicked(ii);
                        if (item.OnSelect != null)
                        {
                            item.OnSelect();
                        }
                    });
                }
                _panelItems[i].gameobject.SetActive(i < Items.Count);
            }
        }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.DropDownListItem o;
         System.String a1;
         checkType(l, 2, out a1);
         System.String a2;
         checkType(l, 3, out a2);
         UnityEngine.Sprite a3;
         checkType(l, 4, out a3);
         System.Boolean a4;
         checkType(l, 5, out a4);
         System.Action a5;
         LuaDelegation.checkDelegate(l, 6, out a5);
         o = new UnityEngine.UI.Extensions.DropDownListItem(a1, a2, a3, a4, a5);
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_OnSelect(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.DropDownListItem self = (UnityEngine.UI.Extensions.DropDownListItem)checkSelf(l);
         System.Action v;
         int           op = LuaDelegation.checkDelegate(l, 2, out v);
         if (op == 0)
         {
             self.OnSelect = v;
         }
         else if (op == 1)
         {
             self.OnSelect += v;
         }
         else if (op == 2)
         {
             self.OnSelect -= v;
         }
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #12
0
 /// <summary>
 /// Removes an item from the drop down list (recommended)
 /// </summary>
 /// <param name="item">Item of type DropDownListItem</param>
 public void RemoveItem(DropDownListItem item)
 {
     Items.Remove(item);
     RebuildPanel();
 }
Пример #13
0
 /// <summary>
 /// Adds an additional item to the drop down list (recommended)
 /// </summary>
 /// <param name="item">Item of type DropDownListItem</param>
 public void AddItem(DropDownListItem item)
 {
     Items.Add(item);
     RebuildPanel();
 }
Пример #14
0
        private void UpdateSelected()
        {
            SelectedItem = (_selectedIndex > -1 && _selectedIndex < Items.Count) ? Items[_selectedIndex] : null;
            if (SelectedItem == null) return;

            bool hasImage = SelectedItem.Image != null;
            if (hasImage)
            {
                _mainButton.img.sprite = SelectedItem.Image;
                _mainButton.img.color = Color.white;

                //if (Interactable) mainButton.img.color = Color.white;
                //else mainButton.img.color = new Color(1, 1, 1, .5f);
            }
            else
            {
                _mainButton.img.sprite = null;
            }

            _mainButton.txt.text = SelectedItem.Caption;

            //update selected index color
            for (int i = 0; i < _itemsPanelRT.childCount; i++)
            {
                _panelItems[i].btnImg.color = (_selectedIndex == i) ? _mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0);
            }
        }