简体   繁体   English

在Android的统一游戏中制作警报/弹出框

[英]Make alert/popup box in unity game for android

I am trying to make a game, for which I completed a whole framework and other stuff, but GUI programming is painful. 我正在尝试制作一个游戏,为此我完成了整个框架和其他内容,但GUI编程很痛苦。 I want to create a box as shown in the picture below. 我想创建一个框,如下图所示。 I tried to do it so many times, but every time it's just not working at all. 我试过这么多次,但每次都没有工作。

I have done many things for it with GUI.BOX , GUI.DrawTexture , GUI.Window and tried to make android plugin code, too. 我用GUI.BOXGUI.DrawTextureGUI.Window为它做了很多事情,并尝试制作android插件代码。

I want to make my box like this image: 我想让我的盒子像这样的形象:

示例图片

void OnGUI()
{
    GUI.BeginGroup(new Rect(10, Screen.height / 2 - 50, Screen.width - 20, hintTexture.height));
    GUI.DrawTexture(new Rect(10,Screen.height /2 - 50,Screen.width -20 , hintTexture.height),hintTexture);
    GUI.Label(new Rect(20, Screen.height / 2 - 50, Screen.width - 20, 50), "Are you sure want to Quit?", noGUIStyle);
    if (GUI.Button(new Rect(10, Screen.height / 2, Screen.width - 20, yesBtn.height), yesBtn,noGUIStyle))
    {
        Application.Quit();
    }

    if (GUI.Button(new Rect(10, Screen.height / 2, Screen.width - 20, noBtn.height), noBtn,noGUIStyle))
    {
        Time.timeScale = 1;
        Destroy(this.gameObject);
    }
    GUI.EndGroup();
}

For Unity Android : 对于Unity Android:

I would strongly suggest you look into NGUI , 2D Toolkit or any other GUI framework that is currently in the Asset Store . 我强烈建议您查看NGUI2D Toolkit或当前位于Asset Store中的任何其他GUI框架。 Prime31's UIToolkit is even free and opensource. Prime31的UIToolkit甚至是免费的和开源的。

Most, if not all, provide a way to design a dialog in a WYSIWYG fashion and also take care of multiple resolutions, anchoring, scaling, etc. 大多数(如果不是全部)提供了一种以所见即所得的方式设计对话框的方法,并且还可以处理多种分辨率,锚定,缩放等。

Also, Unity's OnGUI is generally not recommended for heavy UI, especially for mobile devices, since it has serious performance issues. 此外,Unity的OnGUI通常不建议用于繁重的UI,尤其是移动设备,因为它有严重的性能问题。 Although, that depends on the complexity of your UI and might not be the case. 虽然,这取决于UI的复杂性,但可能并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM