public SerializationFlags Deserialize(byte[] buffer, ref int bitposition, int bitsForColliderId) { hits.Clear(); SerializationFlags flags = SerializationFlags.None; //bool nearestOnly = definition.hitscanType.IsCast() && definition.nearestOnly; if (nearestOnly) { if (buffer.ReadBool(ref bitposition)) { hits.Add(NetworkHit.Deserialize(buffer, ref bitposition, bitsForContactGroupMask, bitsForColliderId)); flags = SerializationFlags.HasContent; nearestIndex = 0; } else { nearestIndex = -1; } } else { while (buffer.ReadBool(ref bitposition)) { hits.Add(NetworkHit.Deserialize(buffer, ref bitposition, bitsForContactGroupMask, bitsForColliderId)); flags = SerializationFlags.HasContent; } } return(flags); }
public static int GenericHitscanNonAlloc(this HitscanDefinition hd, Transform origin, NetObject ownerNetObj, ref List <NetworkHit> hitscanHits, ref int nearestIndex, bool showDebugWidgets = false, bool useSecondaryRealm = false) { if (hitscanHits == null) { hitscanHits = reusableHitscanHitList; } int nearestRayHit = -1; nearestIndex = -1; int count = GenericHitscanNonAlloc(hd, origin, ref reusableColliderArray, ref reusableRayHitArray, ref nearestRayHit, showDebugWidgets, useSecondaryRealm); reusableGameObjIntDict.Clear(); hitscanHits.Clear(); if (count > 0) { /// Check each collider hit for its contactGroup and its rootgameobject/viewID - add to our outgoing List<HitscanHit> for (int i = 0; i < count; ++i) { var hit = reusableColliderArray[i]; var netObjs = reusableNetObjectsList; #if PUN_2_OR_NEWER /// Collect all nested NetObjects - child to parent in order hit.transform.GetNestedComponentsInParents(netObjs); #endif /// We are only interested in objects with IDs int noCount = netObjs.Count; if (noCount == 0) { continue; } /// Determine if any of the nested NetObjs is the owner. bool selfHit = false; for (int c = 0; c < noCount; ++c) { if (ReferenceEquals(netObjs[c], ownerNetObj)) { selfHit = true; break; } } if (selfHit) { continue; } var netObj = netObjs[0]; var viewID = netObj.ViewID; var contactGroupassign = hit.GetComponent <IContactGroupsAssign>(); var mask = (ReferenceEquals(contactGroupassign, null)) ? 0 : contactGroupassign.Mask; int existingIndex; bool exists = reusableGameObjIntDict.TryGetValue(viewID, out existingIndex); int colliderId = netObj.colliderLookup[hit]; if (exists) { var hitscanHit = hitscanHits[existingIndex]; //Debug.Log("EXIST Hitscan hit on " + origin.name + "/" + hit.name + " m: " + mask + "->" + (hitscanHit.hitMask | mask)); hitscanHits[existingIndex] = new NetworkHit(hitscanHit.netObjId, hitscanHit.hitMask | mask, colliderId); /// If we are adding the nearest raycast, log it. if (i == nearestRayHit) { nearestIndex = existingIndex; } } else { //Debug.Log("NEW Hitscan hit on " + rootGO.name + "/" + hit.name + " " + mask); /// If we are adding the nearest raycast, log it. if (i == nearestRayHit) { nearestIndex = hitscanHits.Count; } hitscanHits.Add(new NetworkHit(viewID, mask, colliderId)); reusableGameObjIntDict.Add(viewID, hitscanHits.Count - 1); } } } return(reusableGameObjIntDict.Count); }