欢迎加入Unity业内qq交流群:956187480
qq扫描二维码加群

变形 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);
}
}
}
二:DropDown
public class RDropdown : MonoBehaviour {
Dropdown dropdown;
List tempNames;
void Awake()
{
dropdown = GetComponent();
tempNames = new List();
dropdown.onValueChanged.AddListener(ExecuteItem);
}
private void ExecuteItem(int arg0)
{
Debug.Log("执行逻辑:"+ arg0);
}
void Start()
{
AddNames();
UpdateDropdownView(tempNames);
}
///
/// 刷数据
///
///
private void UpdateDropdownView(List 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);
}
}
demo地址:https://download.csdn.net/download/qq_37310110/11099998
欢迎加入Unity业内qq交流群:956187480
qq扫描二维码加群