Exemplo n.º 1
0
    public void TryMakeNext()
    { // Attempts creating the next dropdown item.  If not one, ends.
        currentDropdownIndex++;
        try
        {
            //print("Nearly equal - \na: " + percentageComplete + "\nb: " + (increment *(double)currentDropdownIndex));
            Image newDropdownImage = Instantiate(dropdownPrefab);
            Text  newText          = newDropdownImage.GetComponentInChildren <Text>();
            newText.text = newList[currentDropdownIndex - 1].mode;
            newDropdownImage.transform.SetParent(transform, false);
            newDropdownImage.gameObject.SetActive(true);
            Color color = newDropdownImage.color;
            color.a = 0;
            newDropdownImage.color = color;
            //RectTransform rect = newDropdownImage.GetComponent<RectTransform>();
            Vector2      initialPos      = new Vector2(0, -(currentDropdownIndex - 1) * (dropdownRect.rect.height - .65f)); // -.65f gets rid of line in between (causes slight overlap)
            DropdownItem newDropdownItem = newDropdownImage.gameObject.GetComponent <DropdownItem>();
            newDropdownItem.listMode = newList[currentDropdownIndex - 1];
            Button newButton = newDropdownItem.GetComponentInChildren <Button>();
            newDropdownImage.sprite = (newList[currentDropdownIndex - 1].selected) ? SpriteManager.selectedDropdownSprite : SpriteManager.defaultDropdownSprite;
            switch (dropdownType)
            {
            case DropdownType.SortBy:
                ListMode sortModeListener = newList[currentDropdownIndex - 1];
                newButton.onClick.RemoveAllListeners();
                newButton.onClick.AddListener(() => window.SetSortMode(sortModeListener));
                break;

            case DropdownType.Filter:
                ListMode filterModeListener = newList[currentDropdownIndex - 1];
                newButton.onClick.AddListener(() => window.FilterModeCallback(filterModeListener));
                break;

            case DropdownType.Location:
                ListMode locationModeListener = newList[currentDropdownIndex - 1];
                // newButton.onClick.AddListener(() => window.SetLocationMode(locationModeListener));
                break;
            }
            newDropdownItem.Open(initialPos);
            dropdownDisplayedItems.Add(newDropdownItem);
        }
        catch (ArgumentOutOfRangeException)
        {
            creatingDropdown     = false;
            currentDropdownIndex = 0;
        }
    }
Exemplo n.º 2
0
 void AddItems(QueryAutocomplete autocomplete)
 {
     foreach (var p in autocomplete.predictions)
     {
         DropdownItem item = Instantiate(itemTemplate, dropdownHolder).AddComponent <DropdownItem>();
         item.button = item.GetComponentInChildren <Button>();
         item.button.onClick.AddListener(() => SelectAutocomplete(item.index));
         item.main_text           = item.transform.Find("Main").GetComponent <Text>();
         item.secondary_text      = item.transform.Find("Secondary").GetComponent <Text>();
         item.main_text.text      = p.structured_formatting.main_text;
         item.secondary_text.text = p.structured_formatting.secondary_text;
         item.index = items.Count;
         item.gameObject.SetActive(true);
         item.name = "Item " + items.Count;
         items.Add(item);
     }
 }