Пример #1
0
 //返回新索引位置
 public int unpackOne(string pStr, int pBeginPos, SerializePackData pSerializePackData)
 {
     //string lStrOut=pStrOut;
     int lCommaIndex = pStr.IndexOf(",", pBeginPos);
     //Debug.Log(pStr.Substring(pBeginPos) );
     pSerializePackData.type = stringToSerializePackType(pStr.Substring(pBeginPos, lCommaIndex - pBeginPos));
     int lCutIndex = pStr.IndexOf(":", ++lCommaIndex);
     int lStrLength = System.Convert.ToInt32(pStr.Substring(lCommaIndex, lCutIndex - lCommaIndex));
     //Debug.Log(lCutIndex);
     //Debug.Log(lStrLength);
     pSerializePackData.data = pStr.Substring(++lCutIndex, lStrLength);
     //Debug.Log(lCutIndex+lStrLength);
     //Debug.Log(lStrOut);
     return lCutIndex + lStrLength;
     //返回新索引位置
 }
Пример #2
0
 public ArrayList unpackToList(string pStr)
 {
     ArrayList lOut = new ArrayList();
     int i = 0;
     while (i < pStr.Length)
     {
         SerializePackData lData =new SerializePackData();
         i = unpackOne(pStr, i, lData);
         lOut.Add(lData);
     }
     return lOut;
 }
Пример #3
0
 //public string SerializePackTypeToString(SerializePackType pType)
 //{
 //    switch (pType)
 //    {
 //        case SerializePackType.stringType: return "s";
 //        case SerializePackType.intType: return "i";
 //        case SerializePackType.floatType: return "f";
 //        case SerializePackType.boolType: return "b";
 //        case SerializePackType.userdata: return "u";
 //    };
 //    Debug.LogError("SerializePackTypeToString error type:" + pType);
 //    return "";
 //}
 public object unpack(SerializePackData pSerializePackData)
 {
     switch (pSerializePackData.type)
     {
         case SerializePackType.stringType: return pSerializePackData.data;
         case SerializePackType.intType: return System.Convert.ToInt32(pSerializePackData.data);
         case SerializePackType.floatType: return System.Convert.ToSingle(pSerializePackData.data);
         //case SerializePackType.boolType: return System.Convert.ToBoolean(pSerializePackData.data);
         case SerializePackType.boolType: return (pSerializePackData.data=="0" ? false : true);
         case SerializePackType.userdata: return pSerializePackData.data;
     };
     Debug.LogError("SerializePackTypeToString error type:" + pSerializePackData.type);
     return null;
 }