ict.lixian.single/Assets/Scripts/UI/LogOn/LogOn.cs

118 lines
3.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
public class LogOn : UIController
{
[SerializeField] Image BG;
[SerializeField] Image mainBody;
[SerializeField] Toggle RememberTog;
[SerializeField] Button CancellationBtn;//取消按钮
[SerializeField] Button LogOnBtn;//登录按钮
[SerializeField] Button plaintextBtn;//明文按钮
[SerializeField] TMP_InputField AccountNumberInput;//账号
[SerializeField] TMP_InputField PasswordInput;//密码
[SerializeField] TextMeshProUGUI AccountNumberText;//账号
[SerializeField] TextMeshProUGUI PasswordText;//密码
new string name;
string password;
int plaintextSum = 0;
int remember = 0;
// Start is called before the first frame update
void Start()
{
try
{
init();
}
catch (Exception ex)
{
Debug.LogError("LogOn"+ex.Message);
throw;
}
}
private void OnEnable()
{
base.show(mainBody, BG);
}
void init()
{
remember = PlayerPrefs.GetInt("remember");
name = PlayerPrefs.GetString("name");
password = PlayerPrefs.GetString("password");
if (remember > 0)
{
RememberTog.isOn = true;
}
else
{
RememberTog.isOn = false;
}
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(password) && name != "账号" && password != "密码"&& RememberTog.isOn)
{
AccountNumberInput.text = name;
PasswordInput.text = password;
}
plaintextBtn.onClick.AddListener(() =>
{
if (plaintextSum % 2 == 0)
{
PasswordInput.contentType = TMP_InputField.ContentType.Standard;
PasswordInput.enabled = false;
PasswordInput.enabled = true;
}
else
{
PasswordInput.contentType = TMP_InputField.ContentType.Password;
PasswordInput.enabled = false;
PasswordInput.enabled = true;
}
plaintextSum++;
});
CancellationBtn.onClick.AddListener(() =>
{
base.hide(mainBody, BG);
});
LogOnBtn.onClick.AddListener(() =>
{
name = AccountNumberInput.text;
password = PasswordInput.text;
if (name.Equals("255255255")&&password.Equals("abc123456789"))
{
UIManager.ins.LogOnState = LogOnState.ok;
UIManager.ins.LogOnTrue();
}
else
{
UIManager.ins.LogOnState = LogOnState.no;
}
if (RememberTog.isOn)
{
PlayerPrefs.SetString("name", name);
PlayerPrefs.SetString("password", password);
}
else
{
PlayerPrefs.SetString("name", "账号");
PlayerPrefs.SetString("password", "密码");
}
base.hide(mainBody, BG);
});
RememberTog.onValueChanged.AddListener((x) =>
{
if (RememberTog.isOn)
{
remember = 1;
}
else
{
remember = 0;
}
PlayerPrefs.SetInt("remember", remember);
});
}
}