eventData | 传入的数据(通常由事件系统传入)。 |
已注册 ISubmitHandler 回调。
这通过指定的“提交”键(默认是 Return 键)来检测选择按钮的时间。
若要更改提交键,请执行以下任一操作:
1.转到 Edit >Project Settings >Input。
2.接下来,展开 Axes 部分,然后转到 Submit 部分(如果存在)。
3.如果 Submit 不存在,则将数字 1 添加到 Size 字段。这会在底部创建一个新部分。展开该新部分,然后将 Name 字段更改为“Submit”。
4.将 Positive Button 字段更改为所需键(例如空格键)。
或者:
1.转到项目中的 EventSystem
2.转到“Inspector”窗口,然后将 Submit Button 字段更改为 Input Manager 中的一个部分(例如“Submit”),或是通过命名为喜欢的名称来创建自己的按钮,然后按照接下来几个步骤执行。
3.转到 Edit >Project Settings >Input 以进入输入管理器。
4.在“Inspector”窗口中展开 Axes 部分。将 1 添加到“Size”字段。这会在底部创建一个新部分。
5.展开该新部分,然后将它命名为您在 EventSystem 的 Submit Button 字段中插入的相同名称。将 Positive Button 字段设置为所需键(例如空格键)。
//Create a UI element by going to Create >UI and choose one of the visible items(Image, Button, Panel etc.) from the list. This script gives the GameObject a Button-like behaviour. //Attach this script to the UI GameObject
using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems;
public class ButtonOnSubmit : Button { //Press enter on the Button GameObject to trigger this Event public override void OnSubmit(BaseEventData eventData) { //Output that the Button is in the submit stage Debug.Log("Submitted!"); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.