/// <summary> /// 通用递归解析方法 /// </summary> /// <param name="bytes">要解析的数据字节数组</param> /// <param name="list">要解析的数据结构</param> /// <param name="unPackObjectList">解析出数据结构每个成员后保存的列表</param> private void CommonUnPack(ref byte[] bytes, List <object> list, ref List <object> unPackObjectList) { for (int i = 0; i < list.Count; i++) { if (list[i] is string) { //解析string是特殊的,需要先获取int(string数据长度)再解析出指定数据长度的string int stringLength = ProtocolUtility.UnPackInt(ref bytes); unPackObjectList.Add(ProtocolUtility.UnPackString(ref bytes, stringLength)); } else if (list[i] is int) { unPackObjectList.Add(ProtocolUtility.UnPackInt(ref bytes)); } else if (list[i] is float) { unPackObjectList.Add(ProtocolUtility.UnPackFloat(ref bytes)); } else if (list[i] is double) { unPackObjectList.Add(ProtocolUtility.UnPackDouble(ref bytes)); } else if (list[i] is bool) { unPackObjectList.Add(ProtocolUtility.UnPackBool(ref bytes)); } else if (list[i] is char) { unPackObjectList.Add(ProtocolUtility.UnPackChar(ref bytes)); } else if (list[i].GetType() == typeof(ClassBase)) { //先解析出它的DataID int dataID = ProtocolUtility.UnPackInt(ref bytes); //根据dataID获取类结构List<object>根据它,解析该类的内部信息存入unPackObjectList CommonUnPack(ref bytes, GetUnPackClassStructByDataID((DataID)dataID), ref unPackObjectList); } else { Debug.LogError("接收了一个未经处理的类型!" + list[i].GetType()); return; } } }