Unity中button 和toggle监听事件函数有无参数

1如果调用监听调用的函数没有参数则用

cs 复制代码
            allselect.onClick.RemoveAllListeners();
            allselect.onClick.AddListener(OnAllProInButtonClick);

2 如果需要传参数进去则要用lamude表达式

cs 复制代码
            allselect.onClick.RemoveAllListeners();
            allselect.onClick.AddListener(() =>OnAllProInButtonClick(Select_Info));

            unallselect.onClick.RemoveAllListeners();
            unallselect.onClick.AddListener(() => OnUnAllProInButtonClick(Select_Info));

            RefreshButton.onClick.RemoveAllListeners();
            RefreshButton.onClick.AddListener(() => OnClickRefreshButtonForTaskprocess(task.TaskId));

3 调用函数时两者不现

Toggle

cs 复制代码
 Toggle Select_Info = processmanagerPrefab.transform.Find("Information/Select").GetComponent<Toggle>();

Select_Info.onValueChanged.RemoveAllListeners();
Select_Info.onValueChanged.AddListener(TurnSelectALLNot);

TurnSelectALLNot函数可以无参数的或默认参数为Toggle.isOn的状态的

cs 复制代码
    private void TurnSelectALLNot(bool isOn )
    {

        foreach (var toggle in proToggles.Values)
        {
            if (toggle != null)
            {
                if (isOn)
                {
                    toggle.isOn = true;
                }
                else
                {
                    toggle.isOn = false;
                }
            }
        }

}

Button

cs 复制代码
            Button allselect = processmanagerPrefab.transform.Find("TaskDetailButtons/Button_Select").GetComponent<Button>();

            allselect.onClick.RemoveAllListeners();
            allselect.onClick.AddListener(() =>OnAllProInButtonClick(Select_Info));

思考是不是可以类似toggle有默认参数bool isOn但不用在函数中写的情况呢?

相关推荐
a1117765 分钟前
水体渲染系统(html开源)
前端·开源·threejs·水体渲染
程序员小李白30 分钟前
CSS 盒子模型
前端·css·html
Zzz不能停38 分钟前
单行 / 多行文本显示省略号(CSS 实现)
前端·css
xiaoxue..39 分钟前
TailwindCSS:从“样式民工”到“UI乐高大师”的逆袭
前端·css·ui
Anastasiozzzz2 小时前
阿亮随手记:动态条件生成Bean
java·前端·数据库
mclwh3 小时前
关于React-Konva 报:Text components are not supported....错误的问题
前端·react.js
SuperEugene3 小时前
错误处理与 try/catch:真实项目里应该捕什么错?
前端·javascript·面试
Amumu121384 小时前
CSS引入方式
前端·css
我是Superman丶4 小时前
【Demo】✋ 数字手势识别 Html
前端·html
HelloReader4 小时前
Leptos + Tauri 2 前端配置Trunk + SSG + 移动端热重载一次打通(Leptos 0.6 口径)
前端