void Start() { chatmanlist = new List <int>(); TypeDo.AddType(); GameObject.DontDestroyOnLoad(this.gameObject); Connection(false); }
/// <summary> /// 消息处理 /// </summary> private static void DealthMsg() { //沾包分包处理 if (buffCount < HEADLENGTH) { return; } //消息长度 msgLength = BitConverter.ToInt32(readBuff, 4);//根据从数组第4位开始获取int(4字节长度)的对应int值获取长度值 //Debug.Log("消息大小:" + msgLength); msgTotalLength = msgLength + HEADLENGTH; if (buffCount < msgTotalLength) { Console.WriteLine("buffCount < msgLength + 8"); return; } //处理消息 whole = new byte[msgTotalLength];//完整的消息长度 // Debug.Log("数据大小:" +msgTotalLength); Array.Copy(readBuff, whole, msgTotalLength); TypeDo.DoType(whole); //命令处理 //清除已处理的消息 int count = buffCount - msgTotalLength; Array.Copy(readBuff, msgTotalLength, readBuff, 0, count); buffCount = count; if (buffCount > 0) { DealthMsg(); } }
/// <summary> /// 命令执行(命令处理“主线程”) /// </summary> void CommandDo() { TypeDo.ProcessAllCommand(); }