下拉框也是常用的组件之一。
下拉框创建完后,导出资源
代码控制实现
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
/*
* Author:W
* 下拉框
*/
public class GComboBoxTest : MonoBehaviour {
private GComponent root;
private GComboBox comboBox1;
private GComboBox comboBox2;
void Awake()
{
UIPackage.AddPackage("UI/Basics");
}
// Use this for initialization
void Start () {
root = this.GetComponent<UIPanel>().ui;
comboBox1 = root.GetChild("n5").asComboBox;
comboBox1.items = new string[] {"选项1","选项2","选项3","选项4" };
comboBox1.values = new string[] {"1","2","3","4"};
comboBox1.icons = new string[] {"icon01", "icon02", "icon03", "icon04"};
comboBox1.onChanged.Add((EventContext context) => {
GObject itemObject = (GObject)context.sender;
Debug.Log("下拉框菜单项="+itemObject.text+" 被选中,它对应的值="+comboBox1.values[comboBox1.selectedIndex]);
});
}
// Update is called once per frame
void Update () {
}
}
运行结果如下