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 framevoid Update()//角色的選擇和創建我做在一起就可以了{//Debug.Log(GameInfo.GAME_STATE);//初始狀態開始為0//Debug.Log(GameState.PLAYER_CREATE); //這個是4if (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("給我彈出創造頁面");}
}
服務器也收到包了(有問題下次再改)