示例#1
0
 private void Start()
 {
     var itemMakeBig = new ComboBoxItem("Make me big!");
     var itemMakeNormal = new ComboBoxItem("Normal", image, true);
     var itemMakeSmall = new ComboBoxItem("Make me small!");
     itemMakeBig.OnSelect += () =>
     {
         comboBox.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 180);
         comboBox.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 40);
         comboBox.UpdateGraphics();
         itemMakeBig.Caption = "Big";
         itemMakeBig.IsDisabled = true;
         itemMakeNormal.Caption = "Make me normal!";
         itemMakeNormal.IsDisabled = false;
         itemMakeSmall.Caption = "Make me small!";
         itemMakeSmall.IsDisabled = false;
     };
     itemMakeNormal.OnSelect += () =>
     {
         comboBox.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 160);
         comboBox.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 30);
         comboBox.UpdateGraphics();
         itemMakeBig.Caption = "Make me big!";
         itemMakeBig.IsDisabled = false;
         itemMakeNormal.Caption = "Normal";
         itemMakeNormal.IsDisabled = true;
         itemMakeSmall.Caption = "Make me small!";
         itemMakeSmall.IsDisabled = false;
     };
     itemMakeSmall.OnSelect += () =>
     {
         comboBox.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 160);
         comboBox.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 20);
         comboBox.UpdateGraphics();
         itemMakeBig.Caption = "Make me big!";
         itemMakeBig.IsDisabled = false;
         itemMakeNormal.Caption = "Make me normal!";
         itemMakeNormal.IsDisabled = false;
         itemMakeSmall.Caption = "Small";
         itemMakeSmall.IsDisabled = true;
     };
     comboBox.AddItems(itemMakeBig, itemMakeNormal, itemMakeSmall);
     comboBox.SelectedIndex = 1;
     comboBox.OnSelectionChanged += (int index) =>
     {
         Camera.main.backgroundColor = new Color32((byte)Random.Range(0, 256), (byte)Random.Range(0, 256), (byte)Random.Range(0, 256), 255);
     };
 }
示例#2
0
 public void ClearItems()
 {
     Items = new ComboBoxItem[0];
 }
示例#3
0
 public void AddItems(params object[] list)
 {
     var cbItems = new List<ComboBoxItem>();
     foreach (var obj in list)
     {
         if (obj is ComboBoxItem)
         {
             var item = (ComboBoxItem)obj;
             cbItems.Add(item);
             continue;
         }
         if (obj is string)
         {
             var item = new ComboBoxItem((string)obj, null, false, null);
             cbItems.Add(item);
             continue;
         }
         if (obj is Sprite)
         {
             var item = new ComboBoxItem(null, (Sprite)obj, false, null);
             cbItems.Add(item);
             continue;
         }
         throw new Exception("Only ComboBoxItem, string and Sprite types are allowed");
     }
     var newItems = new ComboBoxItem[Items.Length + cbItems.Count];
     Items.CopyTo(newItems, 0);
     cbItems.ToArray().CopyTo(newItems, Items.Length);
     Refresh();
     Items = newItems;
 }