Create Dialog Box/pop up windows

前端 未结 1 1573
抹茶落季
抹茶落季 2020-12-04 04:10

have such code

bool b = EditorUtility.DisplayDialog(\"Test\",
 \"Reset or continue?\", \"Reset\", \"Continue\");
if (b)
{
    ResetGame();
}
<
相关标签:
1条回答
  • 2020-12-04 05:02

    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.

    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;
    

    to show a dialogue of the UI Panel

    dialoguePanel.SetActive(true);
    

    To hide it:

    dialoguePanel.SetActive(false);
    

    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 Tutorial for a generic modal Window:

    MAKING A GENERIC MODAL WINDOW Part 1

    MAKING A GENERIC MODAL WINDOW Part 2

    MAKING A GENERIC MODAL WINDOW Part 3

    0 讨论(0)
提交回复
热议问题