创建对话框/弹出窗口 [英] Create Dialog Box/pop up windows

查看:172
本文介绍了创建对话框/弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这样的代码

bool b = EditorUtility.DisplayDialog("Test",
 "Reset or continue?", "Reset", "Continue");
if (b)
{
    ResetGame();
}

,但仅在编辑器中有效,而在游戏中无效.如何用适用于游戏的东西替换EditorUtility.DisplayDialog?

but it works only in Editor and not in Game. How to replace the EditorUtility.DisplayDialog with something that works for game?

推荐答案

任何包含单词"Editor"或来自UnityEditor名称空间的Unity类都意味着class设计用于编辑器,并且将在编辑器中工作.因此EditorUtility仅用于Unity编辑器.

Any Unity class that includes the word "Editor" or came from the UnityEditor namespace means that the class is designed to used in the Editor only and will only work in the Editor. So EditorUtility is for Unity Editor only.

您需要实现自己的模态窗口,并且要实现此功能,您必须了解基本的Unity UI,例如创建按钮,面板,文本.因此,首先学习 Unity 基本 UI .您需要做的就是将UI对象放在面板中,然后在需要时启用/停用它们.

You need to implement your own Modal Window and to be able to this, you must understand basic Unity UI such as creating buttons, panels, texts. So learn the Unity basic UI first. All you need to do is to put the UI Objects in a panel then acivate/deactivate them when needed.

例如,这是您的对话窗格:

For example, this is your dialogue panle:

public GameObject dialoguePanel;

显示UI面板的对话框

dialoguePanel.SetActive(true);

要隐藏它:

dialoguePanel.SetActive(false);

您可以使用onClick.AddListener订阅对话框的按钮或UI控制事件.有关如何订阅UI事件的更多信息,请参见帖子.

You can subscribe to the dialogue's button or UI controls events dynamically with onClick.AddListener. See this post for more information on how to subscribe to UI events.

如果您仍然无法实现模态窗口,请按照下面的教程进行操作,因为这正是您想要的.

If you still can't implement your Modal Window, then follow the tutorials below as that's exactly what you are looking for.

通用模态窗口的Unity教程:

Unity Tutorial for a generic modal Window:

制作通用模态窗口的第1部分

制作通用模态窗口的第2部分

制作通用模态窗口的第3部分

这篇关于创建对话框/弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆