Unity实现注册登录模块的方法-创新互联
小编给大家分享一下Unity实现注册登录模块的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
超过10多年行业经验,技术领先,服务至上的经营模式,全靠网络和口碑获得客户,为自己降低成本,也就是为客户降低成本。到目前业务范围包括了:成都网站设计、网站建设,成都网站推广,成都网站优化,整体网络托管,成都微信小程序,微信开发,app软件定制开发,同时也可以让客户的网站和网络营销和我们一样获得订单和生意!使用Zenject和UniRx的入门级技术实现了伪登录注册功能。
运行效果
登录面板
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; } }
注册面板
using UniRx; using UnityEngine; using UnityEngine.UI; using Zenject; public class RegistPanel : MonoBehaviour { [Inject] private TipPanel _tipPanel; [Inject] private LoginPanel _loginPanel; [Inject] private User _user; public InputField userName; public InputField password01; public InputField password02; public Button Regist; public Button mainMenu; void Start() { //光标跳转 userName.OnEndEditAsObservable() .Subscribe((s => password01.Select())); password01.OnEndEditAsObservable() .Subscribe((s => password02.Select())); var enterPress=password02.OnEndEditAsObservable() .Select((s => "回车键触发注册")); var btnClick = Regist.OnClickAsObservable() .Select((unit => "点击注册按钮触发注册")); Observable.Merge(enterPress, btnClick) .Subscribe((s => { Debug.Log(s); if ((userName.text != null) && (password01.text == password02.text)) { if (_user._dictionary.ContainsKey(userName.text)) { _tipPanel.Show("用户名已存在"); } else { _user._dictionary.Add(userName.text,password01.text); _loginPanel.userName.text = userName.text; _loginPanel.password.text = password01.text; _tipPanel.Show("注册成功"); } } else { _tipPanel.Show("注册失败"); } } )); mainMenu.OnClickAsObservable() .Subscribe((unit => { this.gameObject.SetActive(false); _loginPanel.gameObject.SetActive(true); })); } }
提示面板
using UniRx; using UnityEngine; using UnityEngine.UI; public class TipPanel : MonoBehaviour { public Button CloseBtn; public Text InfoText; void Start() { CloseBtn.OnClickAsObservable() .Subscribe(Hide); } public void Show(string message) { InfoText.text = message; this.gameObject.SetActive(true); } private void Hide(Unit unit) { InfoText.text = string.Empty; this.gameObject.SetActive(false); } }
Installer
using System.Collections.Generic; using Zenject; public class LoginInstaller : MonoInstaller { public LoginPanel _loginPanel; public RegistPanel _registPanel; public TipPanel _tipPanel; public User _user=new User(); public override void InstallBindings() { Container.Bind().FromInstance(_loginPanel).AsSingle(); Container.Bind ().FromInstance(_registPanel).AsSingle(); Container.Bind ().FromInstance(_tipPanel).AsSingle(); Container.Bind ().FromInstance(_user); } } public class User { public Dictionary _dictionary; public User() { _dictionary=new Dictionary (); } }
以上是“Unity实现注册登录模块的方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联成都网站设计公司行业资讯频道!
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页标题:Unity实现注册登录模块的方法-创新互联
网站地址:http://scyanting.com/article/ijsoc.html