2014-01-19 115 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