Kbengine+Unity实现简单的注册登录 登陆成功切换场景

1.根据kbe官方文档配置kbe
2.下载kbe插件导入项目
3.项目制作

登陆界面UI对应的脚本

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using KBEngine;
using System;

public class LaunchSystem : MonoBehaviour {

    public InputField userName;
    public InputField passWord;

    void Start()
    {
        DontDestroyOnLoad(this.gameObject);
        KBEngine.Event.registerOut("onConnectStatus",this,"Event_onConnectStatus"); //服务器连接状态
        KBEngine.Event.registerOut("onLoginFailed",this,"Event_onLoginFailed");     //登录失败事件
        KBEngine.Event.registerOut("onLoginSuccessfully",this,"Event_onLoginSuccessfully");//登陆成功事件
    }

    public void Login()
    {
        KBEngine.Event.fireIn("login",userName.text,passWord.text,System.Text.Encoding.UTF8.GetBytes("2016-10-11"));//执行登陆
    }

    public void CreateAccount()
    {
        KBEngine.Event.fireIn("createAccount",userName.text,passWord.text,System.Text.Encoding.UTF8.GetBytes("2016-10-11"));//执行注册
    }

    //连接状态的回调事件
    public void Event_onConnectStatus(bool status)
    {
        if(!status)
            Debug.LogError("connect fail");
        else
            Debug.LogError("Connect success");
    }

    //登录失败回调事件
    public void Event_onLoginFailed(UInt16 i)
    {
        Debug.LogError("Login Failed"+KBEngineApp.app.serverErr(i));
    }

    //登陆成功回调事件
    public void Event_onLoginSuccessfully(UInt64 uuid,Int32 id,Account account)
    {
        Debug.LogError("Login Successfully");
        Application.LoadLevel("scene2");
    }
}

对应服务端account的脚本

namespace KBEngine
{
    using UnityEngine;
    using System.Collections;
    //using KBEngine;

    public class Account : Entity {

        public override void __init__()
        {
            Event.fireOut("onLoginSuccessfully", new object[]{KBEngineApp.app.entity_uuid, id, this});
            //baseCall("reqAvatarList", new object[0]);
        }
    }

}

你可能感兴趣的:(unity3d)