之前在FairyGUI编辑器菜单扩展中,我使用了App.Alert("复制失败")来提示操作是否成功。这篇则会说一下我们可以使用的弹窗提示,以及做到类似资源发布成功时的"发布成功"飘窗。
打开APP的API脚本,可以看到有很多公开方法,这里只介绍使用过的弹窗。
消息窗口:Alert

确认窗口:Confirm

输入窗口:Input

等待窗口:ShowWaiting和CloseWaiting。

注意:等待窗口ShowWaiting会阻塞界面操作,所以要和CloseWaiting方法一起使用,在合适的时机添加CloseWaiting方法。
以上这几个窗口是可以直接通过App访问的,还有一个窗口需要花一些工夫,就是发布成功时过几秒自动消失的黄色窗口。
使用方法
消息窗口:CS.FairyEditor.App.Alert(msg, err, callback),其中参数二和参数三可以为空,三个参数的类型分别是:string msg , Exception err , Action callback。
Lua
App.Alert("这是消息框")
确认窗口:CS.FairyEditor.App.Confirm(msg, callback),参数可以为空,两个参数的类型分别是:string msg , Action<string> callback 回调方法中带有参数,这个参数可以用来区分按钮点击。
Lua
App.Confirm("这是确认框")
App.Confirm("这是确认框1",function(val)
---val:yes/no
fprint(val)
end)
输入窗口:CS.FairyEditor.App.Input(msg, text, callback),参数可以为空,参数类型分别是:string msg , string text , Action<string> callback 回调方法中带有参数。回调方法只有在点击确认时生效,参数默认值等于传入的参数二。
Lua
App.Input()
App.Input("这是输入框2","输入框消息")
App.Input("这是输入框3","输入框消息",function(val)
---点击确认后执行回调
---默认情况下,val == text
fprint(val)
end)
接下来需要绕一下圈子,才能拿到"发布成功"的黄色提示窗口,简称飘窗。
首先,通过xlua内置方法取得App中泛型方法GetDialog
其次,声明要获取的窗口类型:typeof(CS.FairyEditor.Dialog.PromptDialog)
最后,调用窗口类型方法:Open()
Lua
---取得App中的泛型方法GetDialog App为命名空间CS.FairyEditor.App,FairyGUI官方内置了App = CS.FairyEditor.App
local getDialog = xlua.get_generic_method(App,"GetDialog")
---声明弹窗类型
local promptDlgType = typeof(CS.FairyEditor.Dialog.PromptDialog)
--为泛型方法指定类型,并获取对应的类型窗口脚本类
local promptDlgClass = getDialog(promptDlgType)
--调用 若泛型方法为静态,则无需传第一个实例参数
promptDlgClass():Open("这是一个会自动关闭的提示窗口")

以上就是本篇内容,如果对你有帮助,那就好!有问题也可以留言指出!感谢!