button
helloz 4/3/2024 Unity3d
UnityAction, no return parameter
functions
functions | parameter | describe |
---|---|---|
AddBtnEvent(Button, UnityAction) | Button:UnityEngine.UI.Button | button add click event |
RemoveBtnEvent(Button,UnityAction) | Button:UnityEngine.UI.Button | button remove click event |
RemoveBtnAllEvent(Button) | Button:UnityEngine.UI.Button | Removes all button events for the specified object |
transform:AddBtnEvent(string,UnityAction) | string:Name of child to be found. | |
transform:RemoveAllBtnEvent(string) | string: Name of child to be found. | |
transform:RemoveAllBtnEvent(Transform) | Transform:button.transform | |
transform:RemoveAllBtnEvent(GameObject) | GameObject:button.gameObject |
example
🎉 💯
this is lua code
--add button click event--
---example1----
transform:AddBtnEvent("bg/btnYes",onClickYes);
function onClickYes()
clickyes()
hide()
end
local btnYes = transform:Find("bg/btnYes"):GetComponent('Button')
---example2---
AddBtnEvent(btnYes,onClickYes);
---example3----
btnYes.onClick:AddListener(onClickYes)
-----remove button click event
btnYes.onClick:RemoveAllListeners()
RemoveBtnEvent(btnYes,onClickYes)
RemoveAllBtnEvent(btnYes)
transform:RemoveBtnEvent("bg/btnYes",onClickYes)
transform:RemoveAllBtnEvent("bg/btnYes")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20