unity战斗卡牌视频教程 第六课 - 登录对接服务成功跳转Loading

预览图

1

2

 

客户端代码

using UnityEngine;
using System.Collections;

public class SceneLogin2 : SceneBase
{
    #region 界面加载相关
    protected override void OnInitFront()
    {
        base.OnInitFront();
        _type = SceneType.SceneLogin2;
    }
    protected override void OnInitSkinFront()
    {
        base.OnInitSkinFront();
        SetMainSkinPath("Game/Login/SceneLogin2");
    }
    protected override void OnInitDone()
    {
        base.OnInitDone();
        InitData();

    }
    protected override void OnDestroyDone()
    {
        base.OnDestroyDone();

    }
    protected override void OnDestroyFront()
    {
        base.OnDestroyFront();
    }
    protected override void OnClick(GameObject target)
    {
        base.OnClick(target);
        ButtonClick(target);
    }

    public override void OnInit(params object[] sceneArgs)
    {
        base.OnInit(sceneArgs);
    }
    public override void OnShowed()
    {
        base.OnShowed();

    }
    #endregion

    #region 数据定义

    private UIInput mInputAccount;
    private UIInput mInputPassword;

    #endregion

    #region ui逻辑

    void InitData()
    {
        mInputAccount = skinTransform.Find("InputAccount").GetComponent<UIInput>();
        mInputPassword = skinTransform.Find("InputPassword").GetComponent<UIInput>();
    }


    void ButtonClick(GameObject click)
    {
        if (click.name.Equals("BtnLogin"))
        {
            if(mInputAccount.value == "" || mInputPassword.value == "")
            {
                LogicMgr.GetInstance().GetLogic<LogicTips>().AddTips("没有输入账号或密码!");
            }
            else
            {
                //LogicMgr.GetInstance().GetLogic<LogicTips>().AddTips("开始验证账号密码");
                ActionParam ap = new ActionParam();
                ap["account"] = mInputAccount.value;
                ap["password"] = mInputPassword.value;
                Net.Instance.Send(101, LoginServerReturn, ap);
                Debug.LogError(string.Concat("账号:", mInputAccount.value, "  密码:", mInputPassword.value));
            }
        }
        else if (click.name.Equals("BtnRegis"))
        {
            mInputAccount.value = "123456";
            mInputPassword.value = "654321";
        }
    }
    #endregion

    #region 服务器返回
    void LoginServerReturn(ActionParam acion)
    {
        int relu = acion.Get<int>("Relu");
        if(relu == 0)
        {
            SceneMgr.GetInstance().SwitchingScene(SceneType.SceneLoading);
        }
        else
        {
            LogicMgr.GetInstance().GetLogic<LogicTips>().AddTips("账号或密码错误!");
        }
    }
    #endregion
}

 

using UnityEngine;
using System.Collections;

public class SceneLoading : SceneBase
{
    #region 界面加载相关
    protected override void OnInitFront()
    {
        base.OnInitFront();
        _type = SceneType.SceneLoading;
    }
    protected override void OnInitSkinFront()
    {
        base.OnInitSkinFront();
        SetMainSkinPath("Game/Loading/SceneLoading");
    }
    protected override void OnInitDone()
    {
        base.OnInitDone();
        InitData();

    }
    protected override void OnDestroyDone()
    {
        base.OnDestroyDone();

    }
    protected override void OnDestroyFront()
    {
        base.OnDestroyFront();
    }
    protected override void OnClick(GameObject target)
    {
        base.OnClick(target);
    }

    public override void OnInit(params object[] sceneArgs)
    {
        base.OnInit(sceneArgs);
    }
    public override void OnShowed()
    {
        base.OnShowed();

    }
    #endregion

    private UILabel mSliderLabel;
    private UISlider mSlider;

    void InitData()
    {
        mSliderLabel = skinTransform.Find("SliderLabel").GetComponent<UILabel>();
        mSlider = skinTransform.Find("Slider").GetComponent<UISlider>();
        StartCoroutine(PlayTest());
    }

    IEnumerator PlayTest()
    {
        mSlider.value += 0.008f;
        mSliderLabel.text = (mSlider.value * 100).ToString("0.00") + " %";

        mSliderLabel.transform.localPosition = new Vector3(mSliderLabel.transform.localPosition.x + mSlider.foregroundWidget.width * 0.008f, mSliderLabel.transform.localPosition.y, 0);
        yield return new WaitForSeconds(0.1f);
        if(mSlider.value >= 1)
        {
            LogicMgr.GetInstance().GetLogic<LogicTips>().AddTips("加载完成!");  
        }
        else StartCoroutine(PlayTest());
        
    }
}

 服务端代码

using System;
using System.Collections.Generic;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Service;

namespace GameServer.CsScript.Action
{

    /// <summary>
    /// 测试登陆
    /// </summary>
    /// <remarks>继续BaseStruct类:允许无身份认证的请求;AuthorizeAction:需要身份认证的请求</remarks>
    public class Action101 : AuthorizeAction
    {

        #region class object
        #endregion

        /// <summary>
        /// 登陆密码
        /// </summary>
        private string _password;
        /// <summary>
        /// 登陆账号
        /// </summary>
        private string _account;
        /// <summary>
        /// 登陆详情
        /// </summary>
        private int _relu;


        public Action101(ActionGetter actionGetter)
            : base((short)101, actionGetter)
        {

        }

        /// <summary>
        /// 检查的Action是否需要授权访问
        /// </summary>
        protected override bool IgnoreActionId
        {
            get { return true; }
        }

        /// <summary>
        /// 客户端请求的参数较验
        /// </summary>
        /// <returns>false:中断后面的方式执行并返回Error</returns>
        public override bool GetUrlElement()
        {
            if (httpGet.GetString("Password", ref _password)
                && httpGet.GetString("Account", ref _account))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 业务逻辑处理
        /// </summary>
        /// <returns>false:中断后面的方式执行并返回Error</returns>
        public override bool TakeAction()
        {
            if(_password == "654321" && _account == "123456")
            {
                _relu = 0;
            }
            else
            {
                _relu = 1;
            }
            return true;
        }

        /// <summary>
        /// 下发给客户的包结构数据
        /// </summary>
        public override void BuildPacket()
        {
            this.PushIntoStack(_relu);

        }

    }
}

 视频下载地址

目录汇总:http://www.bobsong.net/886.html

 

本文链接:

https://bobsong.cn/893.html
1 + 1 =
7 评论
    2015年07月26日 回复

    小宝啊,有个问题我看完所有视频还是没搞清楚。ContractTools工具平台不是快速提供客户端和服务器端的通讯代码吗,但是每次给服务器发请求都是调用Net.Instance.Send方法,我进到Net类里追踪看了,最后还是使用的Socket发送请求。Net,NetPackage这几个类是自动生成的吗?ContractTools好像只能生成各种Action类啊。百撕不得骑姐,望解惑,谢谢

      2015年07月27日 回复

      @公子邢 这个工具。只是为了节省时间的。还是要自己在客户端和服务器加上脚本的

    2015年07月26日 回复

    那个工具只是给你省点时间的。还是要自己新建脚本的

      2015年07月26日 回复

      @小宝 3q

    2015年09月30日 回复

    小宝老师,我在使用vs action100启动scut时,它报错了:

    Time:2015/9/30 18:41:34-Trace>>OnInit error:System.Exception: Redis server is using "192.168.1.38" game server, it's path:F:UnityDemoBPBZG OLHelloWorldTestHelloWorldTest
    at ZyGames.Framework.Redis.RedisConnectionPool.<InitRedisInfo>b__0(RedisClient cli)
    at ZyGames.Framework.Redis.RedisConnectionPool.<>c__DisplayClass10.<>c__DisplayClass12.<ProcessTrans>b__f()
    at ZyGames.Framework.Redis.RedisConnectionPool.ProcessTrans(RedisClient client, String[] watchKeys, Func1 processFunc, Action1 transFunc, Action`2 errorFunc)
    at ZyGames.Framework.Redis.RedisConnectionPool.<>c__DisplayClass10.<ProcessTrans>b__e(RedisClient client)
    at ZyGames.Framework.Redis.RedisConnectionPool.Process(Action`1 func)
    at ZyGames.Framework.Redis.RedisConnectionPool.ProcessTrans(String[] watchKeys, Func2 processFunc, Action1 transFunc, Action`2 errorFunc)
    at ZyGames.Framework.Redis.RedisConnectionPool.ProcessTrans(String watchKeys, Func2 processFunc, Action1 transFunc)
    at ZyGames.Framework.Redis.RedisConnectionPool.InitRedisInfo()
    at ZyGames.Framework.Redis.RedisConnectionPool.Initialize(RedisPoolSetting setting, ICacheSerializer serializer)
    at ZyGames.Framework.Redis.RedisConnectionPool.Initialize(ICacheSerializer serializer)
    at ZyGames.Framework.Game.Runtime.GameEnvironment.Start(EnvironmentSetting setting, CacheSetting cacheSetting)
    at ZyGames.Framework.Game.Runtime.GameEnvironment.Start(EnvironmentSetting setting)
    at ZyGames.Framework.Game.Runtime.RuntimeHost.OnStart()

    请问这要怎么解决?上网查了找不到解决方法,只好求助你了

    2015年10月03日 回复

    老师没空吗?怎么不来帮帮我T-T

      2015年10月04日 回复