您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍“Unity组件Toogle和DropDown怎么使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Unity组件Toogle和DropDown怎么使用”文章能帮助大家解决问题。
变形 group
public class RToogleGroup01 : MonoBehaviour {
public Toggle tg1;
public Toggle tg2;
// Use this for initialization
void Start () {
tg1.onValueChanged.AddListener(isOn => {
if (isOn)
{
Debug.Log("tg1打开");
}
else
{
Debug.Log("tg1关闭");
}
});
tg2.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
Debug.Log("tg2打开");
}
else
{
Debug.Log("tg2关闭");
}
});
}
// Update is called once per frame
void Update () {
}public class RToogleGroup02 : MonoBehaviour {
public Toggle tg1;
public Toggle tg2;
public Toggle tg3;
public Transform []bgs;
// Use this for initialization
void Start()
{
tg1.onValueChanged.AddListener(isOn => { ShowBG(0); });
tg2.onValueChanged.AddListener(isOn => { ShowBG(1); });
tg3.onValueChanged.AddListener(isOn => { ShowBG(2); });
}
private void ShowBG(int index)
{
for (int i = 0; i < bgs.Length; i++)
{
if (i == index)
{
bgs[i].gameObject.SetActive(true);
}
else
{
bgs[i].gameObject.SetActive(false);
}
}
}public class RDropdown : MonoBehaviour {
Dropdown dropdown;
List<string> tempNames;
void Awake()
{
dropdown = GetComponent<Dropdown>();
tempNames = new List<string>();
dropdown.onValueChanged.AddListener(ExecuteItem);
}
private void ExecuteItem(int arg0)
{
Debug.Log("执行逻辑:"+ arg0);
}
void Start()
{
AddNames();
UpdateDropdownView(tempNames);
}
/// <summary>
/// 刷数据
/// </summary>
/// <param name="showNames"></param>
private void UpdateDropdownView(List<string> showNames)
{
dropdown.options.Clear();
Dropdown.OptionData tempData;
for (int i = 0; i < showNames.Count; i++)
{
tempData = new Dropdown.OptionData();
tempData.text = showNames[i];
dropdown.options.Add(tempData);
}
dropdown.captionText.text = showNames[0];
}
private void AddNames()
{
string s1 = "0";
string s2 = "1";
string s3 = "2";
string s4 = "3";
string s5 = "4";
tempNames.Add(s1);
tempNames.Add(s2);
tempNames.Add(s3);
tempNames.Add(s4);
tempNames.Add(s5);
}
}关于“Unity组件Toogle和DropDown怎么使用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。