void OnHit(HitInfo hitInfo) { //Debug.LogError("OnHit Target=" + hitInfo.Target + " SubTarget=" + hitInfo.PartTarget); var playerObj = GetPlayer(hitInfo.Target); if (playerObj == null) { return; } var playerSub = GetPlayer(hitInfo.PartTarget); if (playerSub == null) { return; } var ids = m_CurrentData.PlayerIDs; var idObj = playerObj.Player.ID; var idSub = playerSub.Player.ID; int indexObj = ids.IndexOf(idObj); if (indexObj == -1) { ids.Add(idObj); indexObj = ids.Count - 1; } int indexSub = ids.IndexOf(idSub); if (indexSub == -1) { ids.Add(idSub); indexSub = ids.Count - 1; } //Debug.LogError("OnHit2 Obj=" + playerObj + " Sub=" + playerSub); var hit = new NetworkHitData(); hit.Dir = hitInfo.Direction; hit.Pos = hitInfo.Position; hit.IndexObjectPlayer = (byte)indexObj; hit.IndexSubjectPlayer = (byte)indexSub; m_CurrentData.Hits.Add(hit); }
/// <summary> /// Считываем структуру в Reader(обертка над массивом байт) /// </summary> public bool FromReader(NetDataReader reader) { int startPos = reader.Position; try { int count = reader.GetInt(); if (count <= 0) { reader.GetInt(); return(true); } //var hits = new NetworkHitData[count]; var bytes = reader.RawData; int startP = reader.Position; int size = NetworkHitData.SIZE; int offset = 0; for (int i = 0; i < count; i++) { var data = new NetworkHitData(); if (!data.UnsafeCopyFrom(bytes, startP + offset)) { throw new Exception("Не смог считать данные о " + typeof(NetworkHitData)); } Hits.Add(data); //hits[i] = data; offset += size; } reader.AddOffset(offset); int count2 = reader.GetInt(); startP = reader.Position; offset = 0; for (int i = 0; i < count2; i++) { string str; int res = bytes.ToString(startP + offset, out str); if (res == -1) { throw new Exception("Не смог считать данные о PlayerIDs"); } offset += res; PlayerIDs.Add(str); } /*int lenArray; * string[] outStrs = null; * int res = bytes.ToStringArray(startP + offset, ref outStrs, out lenArray); * if(res == -1) * { * throw new Exception("Не смог считать данные о PlayerIDs"); * } * offset += res;*/ reader.AddOffset(offset); //Hits = hits; //PlayerIDs = outStrs; return(true); } catch (Exception e) { Debug.LogError("FromReader is bad=" + e); } reader.Position = startPos; Clear(); return(false); }