using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Test : MonoBehaviour
{
[Header("InputField")]
public InputField input;
[Header("Slider")]
public Slider slider;
[Header("Button")]
public Button button;
[Header("Toggle")]
public Toggle toogle;
[Header("Dropdown")]
public Dropdown drop_down;
[Header("ScrollRect")]
public ScrollRect scrollrect;
[Header("Scrollbar")]
public Scrollbar scrollbar;
// Start is called before the first frame update
void Start()
{
//InputField 当输入值变化时调用
input.onValueChanged.AddListener(Input_onValueChanged);
//当输入完成,鼠标点击其他处,或者按下Enter时调用
input.onEndEdit.AddListener(Input_onEndEdit);
//--------------------------------------------
//当slider滑动,value发生变化时调用
slider.onValueChanged.AddListener(Slider_onValueChanged);
//----------------------------
//当点击 button 时调用
button.onClick.AddListener(Button_onClick);
button.onClick.AddListener(delegate () { Button_onClick_two("hahah"); });
//---------------------------------
//当 toogle 下的ison 发生变化时调用
toogle.onValueChanged.AddListener(Toogle_onValueChanged);
//--------------------
//当Dropdown value 发生变化时调用
drop_down.onValueChanged.AddListener(DropDown_onValueChanged);
//------------------
//当滑动条 的 value发生变化时 调用
scrollrect.onValueChanged.AddListener(scrollrect_onValueChanged);
//--------------
//当 scrollbar 的value变化时 调用
scrollbar.onValueChanged.AddListener(scrollbar_onValueChanged);
}
#region InputField
public void Input_onValueChanged(string str)
{
print("onValueChanged" + str);
}
public void Input_onEndEdit(string str)
{
print("onEndEdit" + str);
}
#endregion
#region Slider
public void Slider_onValueChanged(float f_number)
{
print("onValueChanged" + f_number);
}
#endregion
#region Button
public void Button_onClick()
{
print("button 点击");
}
public void Button_onClick_two(string str)
{
print(str);
}
#endregion
#region Toogle
public void Toogle_onValueChanged(bool bool_demo)
{
print(bool_demo);
}
#endregion
#region Dropdown
public void DropDown_onValueChanged(int number)
{
print("Dropdown" + number);
}
#endregion
#region scrollrect
public void scrollrect_onValueChanged(Vector2 v2)
{
print(v2);
}
#endregion
#region Scrollbar
public void scrollbar_onValueChanged(float d_number)
{
print("scrollbar_onValueChanged"+d_number);
}
#endregion
}
来源:CSDN
作者:fanfan_hongyun
链接:https://blog.csdn.net/fanfan_hongyun/article/details/103781107