Пример #1
0
 /// <summary>
 /// 通用打包方法
 /// </summary>
 /// <param name="bytes"></param>
 /// <param name="objectList"></param>
 private void CommonPack(ref byte[] bytes, List <object> objectList)
 {
     foreach (var o in objectList)
     {
         if (o is int || o is DataID)
         {
             ProtocolUtility.PacketInt(ref bytes, (int)o);
         }
         else if (o is float)
         {
             ProtocolUtility.PacketFloat(ref bytes, (float)o);
         }
         else if (o is double)
         {
             ProtocolUtility.PacketDouble(ref bytes, (double)o);
         }
         else if (o is bool)
         {
             ProtocolUtility.PacketBool(ref bytes, (bool)o);
         }
         else if (o is string)
         {
             ProtocolUtility.PacketString(ref bytes, (string)o);
         }
         else if (o.GetType().BaseType == typeof(ClassBase))
         {
             CommonPack(ref bytes, ((ClassBase)o).objectList);
         }
         else
         {
             Debug.LogError("发送了一个未经处理的类型!" + o.GetType());
         }
     }
 }