海淀天下城电子沙盘单机版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

62 lines
1.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DropdownListData : MonoBehaviour
{
private Dropdown ThisDropdown;
public string SelectText
{
get
{
return ThisDropdown.captionText.text;
}
set
{
SetDropdownValue(value);
}
}
void Awake()
{
ThisDropdown = this.GetComponent<Dropdown>();
}
public void AddData(string data)
{
Dropdown.OptionData tempData = new Dropdown.OptionData();
tempData.text = data;
ThisDropdown.options.Add(tempData);
}
public void DataBind(List<string> List)
{
ThisDropdown.ClearOptions();
Dropdown.OptionData tempData;
if (List == null || List.Count <= 0)
{
ThisDropdown.captionText.text = string.Empty;
return;
}
for (int i = 0; i < List.Count; i++)
{
tempData = new Dropdown.OptionData();
tempData.text = List[i];
ThisDropdown.options.Add(tempData);
}
ThisDropdown.value = 0;
ThisDropdown.captionText.text = ThisDropdown.options[0].text;
}
public void SetDropdownValue(string text)
{
int index = ThisDropdown.options.FindIndex((x) => { return x.text == text; });
if (index != -1)
{
ThisDropdown.value = index;
ThisDropdown.captionText.text = text;
}
else
ThisDropdown.captionText.text = text;
}
}