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,但是之后还有许多包,看起来是想要保持连接的架势

相关推荐
2303_Alpha1 小时前
SpringBoot
笔记·学习
萘柰奈1 小时前
Unity学习----【进阶】TextMeshPro学习(三)--进阶知识点(TMP基础设置,材质球相关,两个辅助工具类)
学习·unity
沐矢羽1 小时前
Tomcat PUT方法任意写文件漏洞学习
学习·tomcat
好奇龙猫1 小时前
日语学习-日语知识点小记-进阶-JLPT-N1阶段蓝宝书,共120语法(10):91-100语法+考え方13
学习
Yasin Chen2 小时前
Unity UI坐标说明
ui·unity
向阳花开_miemie2 小时前
Android音频学习(十八)——混音流程
学习·音视频
工大一只猿2 小时前
51单片机学习
嵌入式硬件·学习·51单片机
c0d1ng2 小时前
量子计算学习(第十四周周报)
学习·量子计算
陈言必行7 小时前
Unity 性能优化 之 编辑器创建资源优化( 工作流 | 场景 | 预制体)
unity·编辑器·游戏引擎
Hello_Embed9 小时前
STM32HAL 快速入门(二十):UART 中断改进 —— 环形缓冲区解决数据丢失
笔记·stm32·单片机·学习·嵌入式软件