/// <summary> /// Кладет структуру в Writer(обертка над массивом байт) /// </summary> public bool PutInWriter(NetDataWriter writer, bool reset = false) { int startLen = writer.Length; try { if (reset) { writer.Reset(); } int count = Hits == null ? 0 : Hits.Count; if (count <= 0) { writer.Put(0); writer.Put(0); return(true); } int count2 = PlayerIDs == null ? 0 : PlayerIDs.Count; int lenIDs = PlayerIDs.GetLen(); if (count2 <= 0 || lenIDs <= -1) { writer.Put(0); writer.Put(0); return(true); } writer.Put(count); int startP = writer.Length; int size = NetworkHitData.SIZE; int offset = 0; writer.ResizeIfNeed(startP + size * count + lenIDs); var bytes = writer.Data; for (int i = 0; i < count; i++) { if (!Hits[i].UnsafeCopyTo(bytes, startP + offset)) { throw new Exception("Не смог записать данные о " + typeof(NetworkHitData)); } offset += size; } writer.AddOffset(offset); writer.Put(count2); startP = writer.Length; offset = 0; for (int i = 0; i < count2; i++) { var str = PlayerIDs[i]; int res = str.ToBytes(bytes, startP + offset); if (res == -1) { throw new Exception("Не смог записать данные о PlayerIDs"); } offset += res; } writer.AddOffset(offset); #region OLD //if (count2 > 0) //{ // int res = PlayerIDs.ToBytes(bytes, startP + offset); // if (res == -1 || res != lenIDs) // { // throw new Exception("Не смог записать данные о PlayerIDs"); // } // offset += lenIDs; // writer.AddOffset(offset); //} //else //{ // writer.Put(0); //} #endregion return(true); } catch (Exception e) { Debug.LogError("PutInWriter is bad=" + e); } writer.Length = startLen; return(false); }