Unity实现注册登录模块
using System;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
using Zenject;
public class LoginPanel : MonoBehaviour
{
public InputField userName;
public InputField password;
public Button LoginBtn;
public Button RegistBtn;
[Inject] private User _user;
[Inject] private TipPanel _tipPanel;
[Inject] private RegistPanel _registPanel;
void Start()
{
//用户名输入完成后光标自动跳转到密码输入框
userName.OnEndEditAsObservable()
.Subscribe((s =>
password.Select()));
//输入完密码后敲击回车键或者点击登录按钮 都触发登录事件
var enterDownStream = password.OnEndEditAsObservable()
.Select((s => "回车键触发登录"));
var loginBtnStream = LoginBtn.OnClickAsObservable()
.Select((unit => "通过点击登录按钮触发的登录"));
Observable.Merge(enterDownStream, loginBtnStream)
.Subscribe((s =>
{
Debug.Log(s);
if (LoginCheak(userName.text,password.text))
{
userName.text=String.Empty;
password.text=String.Empty;
_tipPanel.Show("登录成功");
}
else
{
userName.text=String.Empty;
password.text=String.Empty;
_tipPanel.Show("登录失败");
}
}));
RegistBtn.OnClickAsObservable()
.Subscribe((unit =>
{
this.gameObject.SetActive(false);
_registPanel.gameObject.SetActive(true);
}));
}
public bool LoginCheak(string username,string password)
{
bool isOK = false;
if (_user._dictionary.ContainsKey(username))
{
if (_user._dictionary[username] == password)
{
isOK = true;
}
}
return isOK;
}
}
- .NET Core系列之MemoryCache 初识
- 007手机一键Root(安机网一键Root) v3.0 官方最新版 一键ROOT您的Android手机
- 12306密码被盗了怎么办?12306密码外泄解决方法
- 12个字的qq网名
- 150M迷你型无线路由器怎么设置?
- 192.168.1.1打不开怎么办?路由器192.168.1.1打不开的原因以及解决办法
- 2011年电子报合订本 电子报 编辑部 中文 PDF版 [84M]
- 2015年1月15日小米新旗舰发布会现场图文直播
- 2016.3.1vivo Xplay5新品发布会现场视频直播 优酷直播
- 2016华为P9发布会视频直播地址 4月15日华为P9国行发布会直播