facebook twitter hatena line email

「Unity/TMPro/Dropdown」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「<pre> using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class SettingScene : MonoBehaviour { vo...」)
 
 
(同じ利用者による、間の1版が非表示)
行7: 行7:
 
public class SettingScene : MonoBehaviour
 
public class SettingScene : MonoBehaviour
 
{
 
{
 +
    TMP_Dropdown areaDropdown;
 +
    List<string> areas;
 +
    string area;
 
     void Start()
 
     void Start()
 
     {
 
     {
         InitAreaDropdown();
+
         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 {
行17: 行20:
 
     void AreaDropdownInit()
 
     void AreaDropdownInit()
 
     {
 
     {
 +
        areas = new List<string>();
 
         areas.Add("simple");
 
         areas.Add("simple");
 
         areas.Add("sabaku");
 
         areas.Add("sabaku");

2024年1月6日 (土) 20:16時点における最新版

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class SettingScene : MonoBehaviour
{
    TMP_Dropdown areaDropdown;
    List<string> areas;
    string area;
    void Start()
    {
        AreaDropdownInit();
        areaDropdown = this.transform.Find("AreaDropdown").GetComponent<TMP_Dropdown>();
        areaDropdown.onValueChanged.AddListener(delegate {
            AreaDropdownValueChanged(areaDropdown);
        });
    }
    void AreaDropdownInit()
    {
        areas = new List<string>();
        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();
    }
}