unity学习(58)——选择角色界面--进入游戏

1.点击开始游戏界面触发如下函数

cs 复制代码
public void beginGame()
{
    //nowPlayer = null;
    //Enter
    if (nowPlayer != null)//选了角色才能开始,playerModel数据结构
    {
        //EnterMapDTO edto = new EnterMapDTO();
        //edto.map = nowPlayer.map;
        //edto.point = nowPlayer.point;
        //edto.rotation = nowPlayer.rotation;
        //string m=As
        string message = Coding<StringDTO>.encode(new StringDTO(nowPlayer.id));
        NetWorkScript.getInstance().sendMessage(Protocol.USER,0,UserProtocol.SELECT_CREQ,message);//按部就班的选择请求
    }

收到服务器的返回包如下:

2.在SocketModel.cs的minna命名空间内新增地图相关的command(第三个参数)

cs 复制代码
public class MapProtocol
{
	public const int ENTER_CREQ = 0;
	public const int ENTER_SRES = 1;
	public const int ENTER_BRO = 2;
	public const int MOVE_CREQ = 3;
	public const int MOVE_BRO = 4;
	public const int LEAVE_CREQ = 5;
	public const int LEAVE_BRO = 6;
	public const int TALK_CREQ = 7;
	public const int TALK_BRO = 8;
	public const int ATTACK_CREQ = 9;
	public const int ATTACK_BRO = 10;
	public const int MONSTER_INIT_SRES = 11;
	public const int BE_ATTACK_CREQ = 12;
	public const int BE_ATTACE_BRO = 13;
	public const int MONSTER_DIE_BRO = 14;
	public const int EXP_UP_SRES = 15;
	public const int LEVEL_UP_BRO = 16;
	public const int MONSTER_RELIVE_BRO = 17;
	
	//public const int SKILL_CREQ = 18;
	//public const int SKILL_BRO = 19;
}

3.在socketModel.cs中增加一个新的dto结构体EnterMapDTO

cs 复制代码
public class EnterMapDTO
{
	public int map;
	public Assets.Model.Vector3 point {get; set;}
	public Assets.Model.Vector4 rotation {get; set;}
}

4.MessageManager.cs中对从服务器收到返回的数据包进行解析

cs 复制代码
case UserProtocol.SELECT_SRES:
    //selectPlayer(model.message);
    Debug.Log("SELECT_SRES");
    EnterMapDTO edto = new EnterMapDTO();
    edto.map = SelectMenu.nowPlayer.map;//static 用返回回来的model信息也是可以的
    edto.point = SelectMenu.nowPlayer.point;
    edto.rotation = SelectMenu.nowPlayer.rotation;
    string m1 = Coding<EnterMapDTO>.encode(edto);
    Debug.Log("MessageManager申请进入地图");
    NetWorkScript.getInstance().sendMessage(Protocol.MAP, edto.map, MapProtocol.ENTER_CREQ,m1);//第二个参数是进哪张地图
    break;

5.MessageManager.cs增加MapHandler函数,用来分类处理来自服务器的包!

实测可以进入MapHandler,但是之后还有许多包,看起来是想要保持连接的架势

相关推荐
三只坚果3 小时前
blender制作动画导入unity两种方式
unity·游戏引擎·blender
好望角雾眠3 小时前
第一阶段C#基础-10:集合(Arraylist,list,Dictionary等)
笔记·学习·c#
艾伦~耶格尔3 小时前
【集合框架LinkedList底层添加元素机制】
java·开发语言·学习·面试
星仔编程3 小时前
python学习DAY46打卡
学习
benben0444 小时前
《Unity Shader入门精要》学习笔记二
unity·unity shader
大霞上仙4 小时前
实现自学习系统,输入excel文件,能学习后进行相应回答
python·学习·excel
YF云飞4 小时前
Unity音频管理:打造沉浸式游戏音效
游戏·unity·游戏引擎·游戏程序·个人开发
yatingliu20195 小时前
HiveQL | 个人学习笔记
hive·笔记·sql·学习
武当豆豆5 小时前
C++编程学习(第25天)
开发语言·c++·学习
风和日丽 随波逐流5 小时前
java17学习笔记-Deprecate the Applet API for Removal
笔记·学习