显示密码按钮(I/C#)

显示密码按钮(I/C#),c#,unity3d,passwords,ngui,C#,Unity3d,Passwords,Ngui,我需要做的按钮,显示用户输入的密码。 我尝试用按钮更改输入类型字段,但这只适用于密码->标准号->密码 这是我的按钮脚本 { GameObject NewPasswordInput; private UIInput passwordInput; // Use this for initialization void Start() { NewPasswordInput = GameObject.Find("ActuallyPasswordInpu

我需要做的按钮,显示用户输入的密码。 我尝试用按钮更改输入类型字段,但这只适用于密码->标准号->密码

这是我的按钮脚本

{
GameObject NewPasswordInput;
    private UIInput passwordInput;

    // Use this for initialization
    void Start()
    {
        NewPasswordInput = GameObject.Find("ActuallyPasswordInput");


    }
    // Update is called once per frame
    void Update () {
        passwordInput = GameObject.Find("ActuallyPasswordInput").GetComponent<UIInput>();
        passwordInput.UpdateLabel();
    }
    //
    public void Cancel()
    {
        _stateManager.ChangeScreen(ScreenStateEnum.ProfileEdit);
    }
    //
    public void Confirm()
    {
        _stateManager.ChangeScreen(ScreenStateEnum.ProfileEdit);
    }
    public void ShowPassword()
    {
        if (passwordInput.inputType == UIInput.InputType.Standard) {

                passwordInput.inputType = UIInput.InputType.Password;
            passwordInput.UpdateLabel();
        }
        if (passwordInput.inputType == UIInput.InputType.Password){

            passwordInput.inputType = UIInput.InputType.Standard;
            passwordInput.UpdateLabel();

        }
 }
}
{
游戏对象NewPasswordInput;
专用UIInput密码输入;
//用于初始化
void Start()
{
NewPasswordInput=GameObject.Find(“实际密码输入”);
}
//每帧调用一次更新
无效更新(){
passwordInput=GameObject.Find(“ActuallyPasswordInput”).GetComponent();
passwordInput.UpdateLabel();
}
//
公开作废取消()
{
_stateManager.ChangeScreen(ScreenStateEnum.ProfileEdit);
}
//
公开无效确认()
{
_stateManager.ChangeScreen(ScreenStateEnum.ProfileEdit);
}
公共密码()
{
if(passwordInput.inputType==UIInput.inputType.Standard){
passwordInput.inputType=UIInput.inputType.Password;
passwordInput.UpdateLabel();
}
if(passwordInput.inputType==UIInput.inputType.Password){
passwordInput.inputType=UIInput.inputType.Standard;
passwordInput.UpdateLabel();
}
}
}

如果需要,请使用
!目前这两条语句都已执行

public void ShowPassword()
{
    if (passwordInput.inputType == UIInput.InputType.Standard) 
    {
        passwordInput.inputType = UIInput.InputType.Password;
        passwordInput.UpdateLabel();
    }

    // after the first statement was executed this will allways be true 
    // and will revert the change right ahead
    if (passwordInput.inputType == UIInput.InputType.Password)
    {
        passwordInput.inputType = UIInput.InputType.Standard;
        passwordInput.UpdateLabel();
    }
}
所以结果总是
passwordInput.inputType=UIInput.inputType.Standard
,不管它以前是什么


改用

if (passwordInput.inputType == UIInput.InputType.Standard) 
{
    passwordInput.inputType = UIInput.InputType.Password;
    passwordInput.UpdateLabel();
} 
// execute the second check only if the frírst condition wasn't met before
else if (passwordInput.inputType == UIInput.InputType.Password)
{
    passwordInput.inputType = UIInput.InputType.Standard;
    passwordInput.UpdateLabel();
}
或者让它更容易阅读,我会这样做

public void TooglePasswordVisablilty()
{
    bool isCurrentlyPassword = passwordInput.inputType == UIInput.InputType.Password;

    passwordInput.inputType = isCurrentlyPassword ? UIInput.InputType.Standard : UIInput.InputType.Password;

    passwordInput.UpdateLabel();
}

如果需要,请使用
!目前这两条语句都已执行

public void ShowPassword()
{
    if (passwordInput.inputType == UIInput.InputType.Standard) 
    {
        passwordInput.inputType = UIInput.InputType.Password;
        passwordInput.UpdateLabel();
    }

    // after the first statement was executed this will allways be true 
    // and will revert the change right ahead
    if (passwordInput.inputType == UIInput.InputType.Password)
    {
        passwordInput.inputType = UIInput.InputType.Standard;
        passwordInput.UpdateLabel();
    }
}
所以结果总是
passwordInput.inputType=UIInput.inputType.Standard
,不管它以前是什么


改用

if (passwordInput.inputType == UIInput.InputType.Standard) 
{
    passwordInput.inputType = UIInput.InputType.Password;
    passwordInput.UpdateLabel();
} 
// execute the second check only if the frírst condition wasn't met before
else if (passwordInput.inputType == UIInput.InputType.Password)
{
    passwordInput.inputType = UIInput.InputType.Standard;
    passwordInput.UpdateLabel();
}
或者让它更容易阅读,我会这样做

public void TooglePasswordVisablilty()
{
    bool isCurrentlyPassword = passwordInput.inputType == UIInput.InputType.Password;

    passwordInput.inputType = isCurrentlyPassword ? UIInput.InputType.Standard : UIInput.InputType.Password;

    passwordInput.UpdateLabel();
}