「Unity/TMPro/Dropdown」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「<pre> using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class SettingScene : MonoBehaviour { vo...」) |
|||
行9: | 行9: | ||
void Start() | void Start() | ||
{ | { | ||
− | + | AreaDropdownInit(); | |
areaDropdown = this.transform.Find("AreaDropdown").GetComponent<TMP_Dropdown>(); | areaDropdown = this.transform.Find("AreaDropdown").GetComponent<TMP_Dropdown>(); | ||
areaDropdown.onValueChanged.AddListener(delegate { | areaDropdown.onValueChanged.AddListener(delegate { |
2022年9月4日 (日) 23:30時点における版
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class SettingScene : MonoBehaviour { void Start() { AreaDropdownInit(); areaDropdown = this.transform.Find("AreaDropdown").GetComponent<TMP_Dropdown>(); areaDropdown.onValueChanged.AddListener(delegate { AreaDropdownValueChanged(areaDropdown); }); } void AreaDropdownInit() { areas.Add("simple"); areas.Add("sabaku"); areas.Add("sushi"); List<TMP_Dropdown.OptionData> optionMessages = new List<TMP_Dropdown.OptionData>(); TMP_Dropdown areaDropdown = this.transform.Find("AreaDropdown").GetComponent<TMP_Dropdown>(); areaDropdown.ClearOptions(); foreach (string area in areas) { TMP_Dropdown.OptionData optionData; optionData = new TMP_Dropdown.OptionData(); optionData.text = area; optionMessages.Add(optionData); } foreach (TMP_Dropdown.OptionData message in optionMessages) { areaDropdown.options.Add(message); } areaDropdown.value = areas.IndexOf(area); this.transform.Find("AreaDropdown/Label").GetComponent<TextMeshProUGUI>().text = areas[areaDropdown.value].ToString(); } void AreaDropdownValueChanged(TMP_Dropdown change) { area = areas[change.value]; this.transform.Find("AreaDropdown/Label").GetComponent<TextMeshProUGUI>().text = areas[areaDropdown.value].ToString(); } }