Files
Studio/Assets/Scripts/UVC/UI/UVCDropDown.cs
2025-05-14 17:00:44 +09:00

67 lines
1.6 KiB
C#

using NUnit.Framework;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
namespace Studio.UVC.UI
{
/// <summary>
/// DropDown
/// </summary>
[RequireComponent(typeof(TMP_Dropdown))]
public class UVCDropDown : MonoBehaviour
{
private TMP_Dropdown dropdown;
public TMP_Dropdown DropDown
{
get
{
if (dropdown == null)
dropdown = GetComponent<TMP_Dropdown>();
return dropdown;
}
}
public Action<int> OnValueChange;
public virtual void Init()
{
dropdown = GetComponent<TMP_Dropdown>();
dropdown.ClearOptions();
dropdown.onValueChanged.AddListener(OnDropdownValueChange);
}
private void OnDropdownValueChange(int index)
{
OnValueChange?.Invoke(index);
}
/// <summary>
/// Setting Option
/// </summary>
/// <param name="data">Option Name</param>
public virtual void SetOption(string data)
{
if (dropdown == null)
{
Debug.Log("dropdown Null");
return;
}
TMP_Dropdown.OptionData option = new TMP_Dropdown.OptionData();
option.text = data;
dropdown.options.Add(option);
}
public virtual void SetOptions(List<string> datas)
{
dropdown.AddOptions(datas);
}
public virtual string GetSelectOptionName()
{
return dropdown.options[dropdown.value].text;
}
}
}