1.客户端的程序结构被我精简过,现在去MessageManager.cs中增加一个UserHandler函数,根据收到的包做对应的GameInfo赋值。
2.在Model文件夹下新增一个协议文件UserProtocol,内容很简单。
using System;
public class UserProtocol
{
public const int LIST_CREQ = 0;
public const int LIST_SRES = 1;
public const int CREATE_CREQ = 2;
public const int CREATE_SRES = 3;
public const int SELECT_CREQ = 4;
public const int SELECT_SRES = 5;
public const int REMOVE_CREQ = 6;
public const int REMOVE_SRES = 7;
}
3.在Model文件夹的SocketModel.cs中增加CreateTDO部分,用来组装数据包,内容如下:
public class CreateDTO{
public int job{get;set;}
public string name{get;set;}
}
4.增加panel中“创建角色”按钮响应函数CreateClick():(用来向服务器发包)(之前叫finish)
代码如下: (vs2022的代码提示功能简直逆天!)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelectMenu : MonoBehaviour
{
// Start is called before the first frame update
//public GameObject c = GameObject.FindWithTag("selectMenuCanvas");
public GameObject quan;//start中就保存好了
public int flag = 0;
void Start()
{
//gameObject.SetActive(false);
//GameObject m = GameObject.FindWithTag("selectMenuCanvas");//现在我挂在camera上就可以这么用了
this.quan = GameObject.FindWithTag("selectMenuCanvas");//同一命名空间即可,canvas在最外边是有道理的
this.quan.SetActive(false);
//gameObject.GetComponent<Renderer>.enabled = false;
}
// Update is called once per frame
void Update()//角色的选择和创建我做在一起就可以了
{
//Debug.Log(GameInfo.GAME_STATE);//初始状态开始为0
//Debug.Log(GameState.PLAYER_CREATE); //这个是4
if (GameInfo.GAME_STATE == GameState.PLAYER_CREATE && this.flag == 0)
{
//Debug.Log(GameInfo.GAME_STATE);//初始状态开始为0
//Debug.Log(GameState.PLAYER_CREATE);
this.flag = 1;
Debug.Log("这里计划是只执行一次");
this.quan.SetActive(true);
}
}
public void GoToCreate()//unity那边想要加载必须public
{
Debug.Log("我确实进入onclick函数了");
//这种藏起来的找不着!第二次犯这个错误了
//下面这两句再次说明了之前false的找不到
//GameObject panel = GameObject.FindWithTag("createPanel");//同一命名空间即可,canvas在最外边是有道理的
//panel.SetActive(true);
Debug.Log(CreatePlayerPanel.panel);
CreatePlayerPanel.panel.SetActive(true);//用的static实例类--这个卡住了
Debug.Log("给我弹出创造页面");
}
}
服务器也收到包了(有问题下次再改)