Example #1
0
 public void RefreshShownValue()
 {
     TMP_Dropdown.OptionData optionData = TMP_Dropdown.s_NoOptionData;
     if (this.options.Count > 0)
     {
         optionData = this.options[Mathf.Clamp(this.m_Value, 0, this.options.Count - 1)];
     }
     if (this.m_CaptionText)
     {
         if (optionData != null && optionData.text != null)
         {
             this.m_CaptionText.text = optionData.text;
         }
         else
         {
             this.m_CaptionText.text = string.Empty;
         }
     }
     if (this.m_CaptionImage)
     {
         if (optionData != null)
         {
             this.m_CaptionImage.sprite = optionData.image;
         }
         else
         {
             this.m_CaptionImage.sprite = null;
         }
         this.m_CaptionImage.enabled = (this.m_CaptionImage.sprite != null);
     }
 }
    public void PopulateAllDropdownList()
    {
        _myDropdown.options.Clear();
        foreach (var item in SQL.Instance.GetAllShopts())
        {
            var option = new TMPro.TMP_Dropdown.OptionData()
            {
                text = item.id + " - " + item.shopName + " - " + item.address01
            };

            _myDropdown.options.Add(option);
        }
    }
    void Start()
    {
        //Asigna el desplegable de resoluciones.
        TMPro.TMP_Dropdown dropdown = GetComponent <TMPro.TMP_Dropdown>();

        dropdown.options.RemoveAt(0);

        list = new List <Resolution>();

        //Mira si en el sistema ya hay una configuración de resolución guardada.
        if (PlayerPrefs.HasKey("Width") == false)
        {
            PlayerPrefs.SetInt("Width", Screen.currentResolution.width);
            PlayerPrefs.SetInt("Height", Screen.currentResolution.height);
            PlayerPrefs.SetInt("Hz", Screen.currentResolution.refreshRate);
            PlayerPrefs.Save();
        }

        //Comprueba el ratio de la pantalla.
        float aspect = (float)Display.main.systemWidth / (float)Display.main.systemHeight;

        //rellena el desplegable con resoluciones compatibles.
        for (int i = Screen.resolutions.Length - 1; i > 0; i--)
        {
            string resText = Screen.resolutions[i].width + " x " + Screen.resolutions[i].height + ", " + Screen.resolutions[i].refreshRate + "Hz";
            TMPro.TMP_Dropdown.OptionData data = new TMPro.TMP_Dropdown.OptionData(resText);

            if (Mathf.Approximately((float)Screen.resolutions[i].width / (float)Screen.resolutions[i].height, aspect))
            {
                dropdown.options.Add(data);
                list.Add(Screen.resolutions[i]);
            }
        }

        //Muestra la resolución actual como la seleccionada en el desplegable.
        bool found = false;

        for (int i = 0; i < list.Count && found == false; i++)
        {
            if (list[i].width == Screen.currentResolution.width && list[i].height == Screen.currentResolution.height)
            {
                found = true;
                Mute(dropdown.onValueChanged);
                dropdown.value = i;
                Unmute(dropdown.onValueChanged);
            }
        }
    }
Example #4
0
    // Start is called before the first frame update
    void Start()
    {
        var dropdown = transform.GetComponent <TMPro.TMP_Dropdown>();

        dropdown.ClearOptions();

        List <TMPro.TMP_Dropdown.OptionData> dropdownList = new List <TMPro.TMP_Dropdown.OptionData>();

        foreach (ShapeSettings s in items)
        {
            TMPro.TMP_Dropdown.OptionData item = new TMPro.TMP_Dropdown.OptionData(s.name);
            dropdownList.Add(item);
        }

        dropdown.AddOptions(dropdownList);
    }
Example #5
0
 private TMP_Dropdown.DropdownItem AddItem(TMP_Dropdown.OptionData data, bool selected, TMP_Dropdown.DropdownItem itemTemplate, List <TMP_Dropdown.DropdownItem> items)
 {
     TMP_Dropdown.DropdownItem dropdownItem = this.CreateItem(itemTemplate);
     dropdownItem.rectTransform.SetParent(itemTemplate.rectTransform.parent, false);
     dropdownItem.gameObject.SetActive(true);
     dropdownItem.gameObject.name = "Item " + items.Count + ((data.text == null) ? string.Empty : (": " + data.text));
     if (dropdownItem.toggle != null)
     {
         dropdownItem.toggle.isOn = false;
     }
     if (dropdownItem.text)
     {
         dropdownItem.text.text = data.text;
     }
     if (dropdownItem.image)
     {
         dropdownItem.image.sprite  = data.image;
         dropdownItem.image.enabled = (dropdownItem.image.sprite != null);
     }
     items.Add(dropdownItem);
     return(dropdownItem);
 }
Example #6
0
        public void Show()
        {
            bool flag = !this.IsActive() || !this.IsInteractable() || this.m_Dropdown != null;

            if (!flag)
            {
                bool flag2 = !this.validTemplate;
                if (flag2)
                {
                    this.SetupTemplate();
                    bool flag3 = !this.validTemplate;
                    if (flag3)
                    {
                        return;
                    }
                }
                List <Canvas> list = TMP_ListPool <Canvas> .Get();

                base.gameObject.GetComponentsInParent <Canvas>(false, list);
                bool flag4 = list.Count == 0;
                if (!flag4)
                {
                    Canvas canvas = list[0];
                    TMP_ListPool <Canvas> .Release(list);

                    this.m_Template.gameObject.SetActive(true);
                    this.m_Dropdown      = this.CreateDropdownList(this.m_Template.gameObject);
                    this.m_Dropdown.name = "Dropdown List";
                    this.m_Dropdown.SetActive(true);
                    RectTransform rectTransform = this.m_Dropdown.transform as RectTransform;
                    rectTransform.SetParent(this.m_Template.transform.parent, false);
                    TMP_Dropdown.DropdownItem componentInChildren = this.m_Dropdown.GetComponentInChildren <TMP_Dropdown.DropdownItem>();
                    GameObject    gameObject     = componentInChildren.rectTransform.parent.gameObject;
                    RectTransform rectTransform2 = gameObject.transform as RectTransform;
                    componentInChildren.rectTransform.gameObject.SetActive(true);
                    Rect    rect    = rectTransform2.rect;
                    Rect    rect2   = componentInChildren.rectTransform.rect;
                    Vector2 vector  = rect2.min - rect.min + new Vector2(componentInChildren.rectTransform.localPosition.x, componentInChildren.rectTransform.localPosition.y);
                    Vector2 vector2 = rect2.max - rect.max + new Vector2(componentInChildren.rectTransform.localPosition.x, componentInChildren.rectTransform.localPosition.y);
                    Vector2 size    = rect2.size;
                    this.m_Items.Clear();
                    Toggle toggle = null;
                    for (int i = 0; i < this.options.Count; i++)
                    {
                        TMP_Dropdown.OptionData   data = this.options[i];
                        TMP_Dropdown.DropdownItem item = this.AddItem(data, this.value == i, componentInChildren, this.m_Items);
                        bool flag5 = item == null;
                        if (!flag5)
                        {
                            item.toggle.isOn = (this.value == i);
                            item.toggle.onValueChanged.AddListener(delegate(bool x)
                            {
                                this.OnSelectItem(item.toggle);
                            });
                            bool isOn = item.toggle.isOn;
                            if (isOn)
                            {
                                item.toggle.Select();
                            }
                            bool flag6 = toggle != null;
                            if (flag6)
                            {
                                Navigation navigation  = toggle.navigation;
                                Navigation navigation2 = item.toggle.navigation;
                                navigation.mode          = Navigation.Mode.Explicit;
                                navigation2.mode         = Navigation.Mode.Explicit;
                                navigation.selectOnDown  = item.toggle;
                                navigation.selectOnRight = item.toggle;
                                navigation2.selectOnLeft = toggle;
                                navigation2.selectOnUp   = toggle;
                                toggle.navigation        = navigation;
                                item.toggle.navigation   = navigation2;
                            }
                            toggle = item.toggle;
                        }
                    }
                    Vector2 sizeDelta = rectTransform2.sizeDelta;
                    sizeDelta.y = size.y * (float)this.m_Items.Count + vector.y - vector2.y;
                    rectTransform2.sizeDelta = sizeDelta;
                    float num   = rectTransform.rect.height - rectTransform2.rect.height;
                    bool  flag7 = num > 0f;
                    if (flag7)
                    {
                        rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, rectTransform.sizeDelta.y - num);
                    }
                    Vector3[] array = new Vector3[4];
                    rectTransform.GetWorldCorners(array);
                    RectTransform rectTransform3 = canvas.transform as RectTransform;
                    Rect          rect3          = rectTransform3.rect;
                    for (int j = 0; j < 2; j++)
                    {
                        bool flag8 = false;
                        for (int k = 0; k < 4; k++)
                        {
                            Vector3 vector3 = rectTransform3.InverseTransformPoint(array[k]);
                            bool    flag9   = vector3[j] < rect3.min[j] || vector3[j] > rect3.max[j];
                            if (flag9)
                            {
                                flag8 = true;
                                break;
                            }
                        }
                        bool flag10 = flag8;
                        if (flag10)
                        {
                            RectTransformUtility.FlipLayoutOnAxis(rectTransform, j, false, false);
                        }
                    }
                    for (int l = 0; l < this.m_Items.Count; l++)
                    {
                        RectTransform rectTransform4 = this.m_Items[l].rectTransform;
                        rectTransform4.anchorMin        = new Vector2(rectTransform4.anchorMin.x, 0f);
                        rectTransform4.anchorMax        = new Vector2(rectTransform4.anchorMax.x, 0f);
                        rectTransform4.anchoredPosition = new Vector2(rectTransform4.anchoredPosition.x, vector.y + size.y * (float)(this.m_Items.Count - 1 - l) + size.y * rectTransform4.pivot.y);
                        rectTransform4.sizeDelta        = new Vector2(rectTransform4.sizeDelta.x, size.y);
                    }
                    this.AlphaFadeList(0.15f, 0f, 1f);
                    this.m_Template.gameObject.SetActive(false);
                    componentInChildren.gameObject.SetActive(false);
                    this.m_Blocker = this.CreateBlocker(canvas);
                }
            }
        }
 /// <summary>
 /// Create an object representing a single option for the dropdown list.
 /// </summary>
 /// <param name="key">Optional key for the option.</param>
 /// <param name="text">Optional text for the option.</param>
 /// <param name="image">Optional image for the option.</param>
 public OptionDataKeyValue(string key, string text, Sprite image)
 {
     this.key     = key;
     m_OptionData = new TMP_Dropdown.OptionData(image);
 }
 public OptionDataKeyValue(string key, string text)
 {
     this.key     = key;
     m_OptionData = new TMP_Dropdown.OptionData(text);
 }