【问题标题】:GUI quick fixes图形用户界面快速修复
【发布时间】:2014-02-08 17:03:38
【问题描述】:

我正在尝试在 Unity 中使用 Javascript 制作一个简单的登录 GUI。我目前从下面的代码中获得了一个简单的 GUI,但我一直在尝试做一些额外的事情:

  • 在其中输入内容时,使密码字段显示为星号 (*)。
  • 将登录窗口从“GUILayout.Window”更改为“GUILayout.Box”,我试图从窗口框中删除标题栏,所以我试图将其更改为一个框,但它不起作用当我也更改其他变量时。
  • 更改底部 3 个按钮的宽度,使其与字段 (80) 的宽度相同,并与框右侧(字段下方)对齐

感谢您的帮助:D

#pragma strict

var newSkin : GUISkin;
var logoTexture : Texture2D;
var aTexture : Texture;

private var username : String = ""; // String content would be shown as placeholder text
private var password : String = ""; // String content would be shown as placeholder text
private var submitted : boolean = false;

private var windowRect0 : Rect;

function Start()
{
}

function OnGUI() // Load GUI skin GUI.skin = newSkin;
{ 

    var screenWidth = Screen.width;
    var screenHeight = Screen.height;

    var windowWidth = 300;
    var windowHeight = 180;
    var windowX = ( 50 );
    var windowY = ( 50 );

    GUI.Box(Rect(0, 0, Screen.width, Screen.height), "" ); // Box around the menu to display the background image

    // Postion the login window
    windowRect0 = Rect( windowX, windowY, windowWidth, windowHeight );

    // Display the login window for the user form below
    GUILayout.Window( 0, windowRect0, UserForm, "" );
}

function UserForm()
{
    GUILayout.BeginVertical();

    // Username Field
    GUILayout.BeginHorizontal();
    GUILayout.Label("Username ", GUILayout.Width(80));
    username = GUILayout.TextField( username );
    GUILayout.EndHorizontal();

    // Password Field
    GUILayout.BeginHorizontal();
    GUILayout.Label("Password ", GUILayout.Width(80));
    password = GUILayout.TextField( password );
    GUILayout.EndHorizontal();

    if ( GUILayout.Button( "Login" ) ) // Login button
    {
        submitted = true;
    }
    if ( GUILayout.Button( "Reset Password" ) ) // Reset password
    {
        username = "Username ";
        password = "Password ";
        submitted = false;
    }
    if ( GUILayout.Button( "Support" ) ) // Support button
    {
        // Enter action here when the "Support" button is pressed
    }

    if ( submitted )
    {
        GUILayout.Label("Submitted!");
    }

    GUILayout.EndVertical();
}

【问题讨论】:

    标签: user-interface unity3d unityscript


    【解决方案1】:

    前段时间我在做一个类似的项目,我使用了 GUI.passwordfield (https://docs.unity3d.com/Documentation/ScriptReference/GUI.PasswordField.html) 这会将输入设置为星号。 我真的不知道你对第二个问题的意思,但第三个: 您可以轻松地将布局信息分配给您的元素,如下例所示:

    }
        if (GUI.Button(Rect(10,70,50,30),"Click"))
            Debug.Log("Clicked the button with text");
    }
    

    重要的是这个位(10,70,50,30),这意味着按钮距左侧 10 像素,距顶部 70 像素,宽 50 像素,高 30 像素。 您几乎可以在每个元素上使用它。

    请参阅http://docs.unity3d.com/Documentation/ScriptReference/index.html 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2016-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多