2014-01-19 118 views
0

我想在统一的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(); 
} 

回答

0

我工作的一个类似的项目已有一段时间,我用了GUI.passwordfield (https://docs.unity3d.com/Documentation/ScriptReference/GUI.PasswordField.html) 此设置输入到asterixes。 我真的不知道你的意思的第二个问题是什么,但第三: 您可以轻松地在这个例子中分配布局设计信息到你的元素,如:

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

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

有关更多信息,请参阅http://docs.unity3d.com/Documentation/ScriptReference/index.html