[Unity] 用GUI写了一个登录验证(含时间加密)

查看:902 |回复:5 | 2014-10-11 01:59:47

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 大西几 于 2021-2-24 16:32 编辑

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

} image.png
2014-10-11 01:59:47  
 赞 赞 1

使用道具 登录

5个回答,把该问题分享到群,邀请大神一起回答。
3#
{:1_144:}
回复 收起回复
2014-11-3 16:43:09   回复
 赞 赞 1

使用道具 登录

4#
挺不错的素材!!!!!!!!!!
回复 收起回复
2014-12-2 09:49:24   回复
 赞 赞 1

使用道具 登录

5#
回复 收起回复
2018-10-23 09:14:20   回复
 赞 赞 1

使用道具 登录

6#
好东西~多谢分享~!
回复 收起回复
2018-10-24 21:04:35   回复
 赞 赞 1

使用道具 登录

CG 游戏行业专业问题

Unity3D技术手机游戏引擎手游引擎
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表