unity3d登录验证


最近的四个项目,统一加了一个登录界面,除了验证用户名和密码外,还加了一个到指定时间就不好用的功能,用这个来实现加密。
要点包括: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();
}
}

}

你可能感兴趣的:(unity,登陆验证)