Circle

编程改变世界!

6.Unity3D商业游戏源码研究-变身吧主公-SceneLogin

本文固定链接:http://blog.csdn.net/u013108312/article/details/70232414

using System;
using System.Collections.Generic;

/// <summary>
/// 收听器
/// </summary>
public interface INotifier
{
    void OnReceiveData(uint cmdId, object param1, object param2);
}
using UnityEngine;
using System.Collections;
using protos.ReturnMessage;
using protos.Login;

public class SceneLogin : SceneBase, INotifier
{
    private UIInput mInputAcc;
    private UIInput mInputPass;

    protected override void OnInitSkin()
    {
        base.SetMainSkinPath("Game/UI/SceneLogin");
        base.OnInitSkin();
    }

    protected override void OnInitDone()
    {
        base.OnInitDone();

        GameServerMgr.GetInstance().RegisterNotifier(NetMessageDef.ResReturnDefaultInfo, this);

        mInputAcc = skinTransform.Find("InputAcc").GetComponent<UIInput>();
        mInputPass = skinTransform.Find("InputPass").GetComponent<UIInput>();

        string str = (string)sceneArgs[0];
        int i = (int)sceneArgs[1];
        bool bo = (bool)sceneArgs[2];

        mInputAcc.value = PlayerPrefs.GetString("LoginAcc");
        mInputPass.value = PlayerPrefs.GetString("LoginPass");

        Debug.LogError(str + "---" + i + "---" + bo);
    }
    void OnDestroy()
    {
        GameServerMgr.GetInstance().UnregisterNotifier(NetMessageDef.ResReturnDefaultInfo, this);
    }
    public void OnReceiveData(uint cmdId, object param1, object param2)
    {

        switch(cmdId)
        {
            case NetMessageDef.ResReturnDefaultInfo:
                ResDefaultInfo info = param1 as ResDefaultInfo;
                if(info.results == 1)
                {
                    SceneMgr.Instatance.SwitchScene(SceneType.SceneLoding, "Hello");
                    PlayerPrefs.SetString("LoginAcc", mInputAcc.value);
                    PlayerPrefs.SetString("LoginPass", mInputPass.value);
                }
                else if(info.results == 2)
                {
                    //跳转到创建角色界面
                    SceneMgr.Instatance.SwitchScene(SceneType.SceneLoding, "Hello");
                }
                break;
        }
    }


    protected override void OnClick(GameObject click)
    {
        base.OnClick(click);
        ClickButton(click);
    }
    protected override void OnDestroyFront()
    {
        base.OnDestroyFront();
        Debug.Log("OnDestroyFront");
        mInputAcc = null;
        mInputPass = null;
    }
    protected override void OnDestroyEnd()
    {
        base.OnDestroyEnd();
        Debug.Log("OnDestroyEnd");
    }


    void ClickButton(GameObject click)
    {
        if (click.name.Equals("BtnLogin"))
        {
            if (string.IsNullOrEmpty(mInputAcc.value) || string.IsNullOrEmpty(mInputPass.value))
            {
                Debug.LogError("账号或密码不能为空");
                return;
            }
            ReqLogin login = new ReqLogin();
            login.account = mInputAcc.value;
            login.password = mInputPass.value;
            GameServerMgr.GetInstance().SendMessage(new MuffinMsg(NetMessageDef.ReqLogin, login));
        }
        else if (click.name.Equals("BtnReg"))
        {
            if (string.IsNullOrEmpty(mInputAcc.value) || string.IsNullOrEmpty(mInputPass.value))
            {
                Debug.LogError("注册的账号或密码不能为空,请输入");
                return;
            }

            ReqCreateAccount createAccount = new ReqCreateAccount();
            createAccount.account = mInputAcc.value;
            createAccount.password = mInputPass.value;
            GameServerMgr.GetInstance().SendMessage(new MuffinMsg(NetMessageDef.ReqCreateAccount, createAccount));
        }
    }

}
阅读更多
版权声明:欢迎转载,转载请注明原博客链接:http://blog.csdn.net/u013108312 和本文章的链接。谢谢合作。作者:CircleGood https://blog.csdn.net/u013108312/article/details/70232414
文章标签: 游戏 界面 源码
个人分类: Unity3D商业游戏
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭