unity 内置组件事件调动

寵の児 提交于 2020-01-25 17:55:36

 

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
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!