马上注册,加入CGJOY,让你轻松玩转CGJOY。
您需要 登录 才可以下载或查看,没有帐号?立即注册
×
最近的四个项目,统一加了一个登录界面,除了验证用户名和密码外,还加了一个到指定时间就不好用的功能,用这个来实现加密。
要点包括:GUIskin的设置,TextField,PasswordField,系统时间的获取等
上个代码吧- using UnityEngine;
- using System.Collections;
- public class Login : MonoBehaviour {
- public Texture bgTexture;
- private float widthF = Screen.width;
- private float heightF = Screen.height;
- public GUIStyle dengluStyle;
- public GUIStyle tuichuStyle;
- private float btnWidth = 164;
- private float btnHeight = 117;
- public GUISkin windowSkin;
- //帐号
- private string _name;
- //密码
- private string _password;
- public string nameInput="";//获取输入的帐号
- public string passwordInput = "";//获取输入的密码
-
- private bool tishi;
- void Start(){
- _name = "liaoshihua";
- _password = "liaoshihua";
- }
- void OnGUI(){
- GUI.DrawTexture(new Rect(0,0,widthF,heightF),bgTexture,ScaleMode.StretchToFill,true,10.0f);
- GUI.skin = windowSkin;
- nameInput = GUI.TextField(new Rect(690,392,150,30),nameInput);
- passwordInput = GUI.PasswordField(new Rect(690,428,150,30),passwordInput,"*"[0],16);
-
-
- if(GUI.Button(new Rect(550,440,btnWidth,btnHeight),"",dengluStyle)){
-
- int yearStr = System.DateTime.Now.Year;
- if(yearStr>2012){
- return;
- }
- int monthStr = System.DateTime.Now.Month;
- if(monthStr>10){
- return;
- }
- int dayStr = System.DateTime.Now.Day;
- if(dayStr>15){
- return;
- }
-
- if(_name == nameInput && _password == passwordInput){
- Application.LoadLevel(1);
- tishi = false;
- }else{
- Debug.Log("用户名或密码错误");
- tishi = true;
- }
-
- }
- if(tishi){
- GUI.Label(new Rect(850,392,150,30),"Try Again");
- }
-
- if(GUI.Button(new Rect(710,440,btnWidth,btnHeight),"",tuichuStyle)){
- Application.Quit();
- }
- }
- }
复制代码 转自:http://ilaoxu.com/gui-write-a-lo ... ing-encryption.html |