【发布时间】: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