// serialize all components (or only dirty ones for channelId if not initial state) // -> returns TRUE if any date other than dirtyMask was written! internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter writer, bool initialState, int channelId) { if (components.Length > 64) { if (LogFilter.logError) { Debug.LogError("Only 64 NetworkBehaviour components are allowed for NetworkIdentity: " + name + " because of the dirtyComponentMask"); } return(false); } // loop through all components only once and then write dirty+payload into the writer afterwards ulong dirtyComponentsMask = 0L; NetworkWriter payload = new NetworkWriter(); for (int i = 0; i < components.Length; ++i) { // is this component dirty on this channel? // -> always serialize if initialState so all components with all channels are included in spawn packet // -> note: IsDirty() is false if the component isn't dirty or sendInterval isn't elapsed yet NetworkBehaviour comp = m_NetworkBehaviours[i]; if (initialState || (comp.IsDirty() && comp.GetNetworkChannel() == channelId)) { // set bit #i to 1 in dirty mask dirtyComponentsMask |= (ulong)(1L << i); // serialize the data if (LogFilter.logDebug) { Debug.Log("OnSerializeAllSafely: " + name + " -> " + comp.GetType() + " initial=" + initialState + " channelId=" + channelId); } OnSerializeSafely(comp, payload, initialState); // Clear dirty bits only if we are synchronizing data and not sending a spawn message. // This preserves the behavior in HLAPI if (!initialState) { comp.ClearAllDirtyBits(); } } } // did we write anything? then write dirty, payload and return true if (dirtyComponentsMask != 0L) { byte[] payloadBytes = payload.ToArray(); writer.WritePackedUInt64(dirtyComponentsMask); // WritePacked64 so we don't write full 8 bytes if we don't have to writer.Write(payloadBytes, 0, payloadBytes.Length); return(true); } // didn't write anything, return false return(false); }
internal void UNetUpdate() { uint num = 0; for (int index = 0; index < this.m_NetworkBehaviours.Length; ++index) { int dirtyChannel = this.m_NetworkBehaviours[index].GetDirtyChannel(); if (dirtyChannel != -1) { num |= (uint)(1 << dirtyChannel); } } if ((int)num == 0) { return; } for (int channelId = 0; channelId < NetworkServer.numChannels; ++channelId) { if (((int)num & 1 << channelId) != 0) { NetworkIdentity.s_UpdateWriter.StartMessage((short)8); NetworkIdentity.s_UpdateWriter.Write(this.netId); bool flag = false; for (int index = 0; index < this.m_NetworkBehaviours.Length; ++index) { short position = NetworkIdentity.s_UpdateWriter.Position; NetworkBehaviour networkBehaviour = this.m_NetworkBehaviours[index]; if (networkBehaviour.GetDirtyChannel() != channelId) { networkBehaviour.OnSerialize(NetworkIdentity.s_UpdateWriter, false); } else { if (networkBehaviour.OnSerialize(NetworkIdentity.s_UpdateWriter, false)) { networkBehaviour.ClearAllDirtyBits(); NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short)8, networkBehaviour.GetType().Name, 1); flag = true; } if ((int)NetworkIdentity.s_UpdateWriter.Position - (int)position > (int)NetworkServer.maxPacketSize && LogFilter.logWarn) { Debug.LogWarning((object)("Large state update of " + (object)((int)NetworkIdentity.s_UpdateWriter.Position - (int)position) + " bytes for netId:" + (object)this.netId + " from script:" + (object)networkBehaviour)); } } } if (flag) { NetworkIdentity.s_UpdateWriter.FinishMessage(); NetworkServer.SendWriterToReady(this.gameObject, NetworkIdentity.s_UpdateWriter, channelId); } } } }
internal void UNetUpdate() { uint num = 0u; for (int i = 0; i < m_NetworkBehaviours.Length; i++) { NetworkBehaviour networkBehaviour = m_NetworkBehaviours[i]; int dirtyChannel = networkBehaviour.GetDirtyChannel(); if (dirtyChannel != -1) { num = (uint)((int)num | (1 << dirtyChannel)); } } if (num == 0) { return; } for (int j = 0; j < NetworkServer.numChannels; j++) { if (((int)num & (1 << j)) == 0) { continue; } s_UpdateWriter.StartMessage(8); s_UpdateWriter.Write(netId); bool flag = false; for (int k = 0; k < m_NetworkBehaviours.Length; k++) { short position = s_UpdateWriter.Position; NetworkBehaviour networkBehaviour2 = m_NetworkBehaviours[k]; if (networkBehaviour2.GetDirtyChannel() != j) { networkBehaviour2.OnSerialize(s_UpdateWriter, initialState: false); continue; } if (networkBehaviour2.OnSerialize(s_UpdateWriter, initialState: false)) { networkBehaviour2.ClearAllDirtyBits(); flag = true; } if (s_UpdateWriter.Position - position > NetworkServer.maxPacketSize && LogFilter.logWarn) { Debug.LogWarning("Large state update of " + (s_UpdateWriter.Position - position) + " bytes for netId:" + netId + " from script:" + networkBehaviour2); } } if (flag) { s_UpdateWriter.FinishMessage(); NetworkServer.SendWriterToReady(base.gameObject, s_UpdateWriter, j); } } }
internal void UNetUpdate() { uint num = 0; for (int i = 0; i < this.m_NetworkBehaviours.Length; i++) { int dirtyChannel = this.m_NetworkBehaviours[i].GetDirtyChannel(); if (dirtyChannel != -1) { num |= ((uint)1) << dirtyChannel; } } if (num != 0) { for (int j = 0; j < NetworkServer.numChannels; j++) { if ((num & (((int)1) << j)) != 0) { s_UpdateWriter.StartMessage(8); s_UpdateWriter.Write(this.netId); bool flag = false; for (int k = 0; k < this.m_NetworkBehaviours.Length; k++) { short position = s_UpdateWriter.Position; NetworkBehaviour behaviour2 = this.m_NetworkBehaviours[k]; if (behaviour2.GetDirtyChannel() != j) { behaviour2.OnSerialize(s_UpdateWriter, false); } else { if (behaviour2.OnSerialize(s_UpdateWriter, false)) { behaviour2.ClearAllDirtyBits(); NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, 8, behaviour2.GetType().Name, 1); flag = true; } if (((s_UpdateWriter.Position - position) > NetworkServer.maxPacketSize) && LogFilter.logWarn) { Debug.LogWarning(string.Concat(new object[] { "Large state update of ", s_UpdateWriter.Position - position, " bytes for netId:", this.netId, " from script:", behaviour2 })); } } } if (flag) { s_UpdateWriter.FinishMessage(); NetworkServer.SendWriterToReady(base.gameObject, s_UpdateWriter, j); } } } } }
internal void UNetUpdate() { uint num = 0; for (int i = 0; i < this.m_NetworkBehaviours.Length; i++) { int dirtyChannel = this.m_NetworkBehaviours[i].GetDirtyChannel(); if (dirtyChannel != -1) { num |= ((uint)1) << dirtyChannel; } } if (num != 0) { for (int j = 0; j < NetworkServer.numChannels; j++) { if ((num & (((int)1) << j)) != 0) { s_UpdateWriter.StartMessage(8); s_UpdateWriter.Write(this.netId); bool flag = false; for (int k = 0; k < this.m_NetworkBehaviours.Length; k++) { NetworkBehaviour behaviour2 = this.m_NetworkBehaviours[k]; if (behaviour2.GetDirtyChannel() != j) { behaviour2.OnSerialize(s_UpdateWriter, false); } else if (behaviour2.OnSerialize(s_UpdateWriter, false)) { behaviour2.ClearAllDirtyBits(); NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, 8, behaviour2.GetType().Name, 1); flag = true; } } if (flag) { s_UpdateWriter.FinishMessage(); NetworkServer.SendWriterToReady(base.gameObject, s_UpdateWriter, j); } } } } }
// invoked by unity runtime immediately after the regular "Update()" function. internal void UNetUpdate() { // check if any behaviours are ready to send uint dirtyChannelBits = 0; for (int i = 0; i < m_NetworkBehaviours.Length; i++) { NetworkBehaviour comp = m_NetworkBehaviours[i]; int channelId = comp.GetDirtyChannel(); if (channelId != -1) { dirtyChannelBits |= (uint)(1 << channelId); } } if (dirtyChannelBits == 0) { return; } for (int channelId = 0; channelId < NetworkServer.numChannels; channelId++) { if ((dirtyChannelBits & (uint)(1 << channelId)) != 0) { s_UpdateWriter.StartMessage(MsgType.UpdateVars); s_UpdateWriter.Write(netId); bool wroteData = false; short oldPos; for (int i = 0; i < m_NetworkBehaviours.Length; i++) { oldPos = s_UpdateWriter.Position; NetworkBehaviour comp = m_NetworkBehaviours[i]; if (comp.GetDirtyChannel() != channelId) { // component could write more than one dirty-bits, so call the serialize func comp.OnSerialize(s_UpdateWriter, false); continue; } if (comp.OnSerialize(s_UpdateWriter, false)) { comp.ClearAllDirtyBits(); #if UNITY_EDITOR UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing, MsgType.UpdateVars, comp.GetType().Name, 1); #endif wroteData = true; } if (s_UpdateWriter.Position - oldPos > NetworkServer.maxPacketSize) { if (LogFilter.logWarn) { Debug.LogWarning("Large state update of " + (s_UpdateWriter.Position - oldPos) + " bytes for netId:" + netId + " from script:" + comp); } } } if (!wroteData) { // nothing to send.. this could be a script with no OnSerialize function setting dirty bits continue; } s_UpdateWriter.FinishMessage(); NetworkServer.SendWriterToReady(gameObject, s_UpdateWriter, channelId); } } }
internal void UNetUpdate() { uint num = 0u; for (int i = 0; i < this.m_NetworkBehaviours.Length; i++) { NetworkBehaviour networkBehaviour = this.m_NetworkBehaviours[i]; int dirtyChannel = networkBehaviour.GetDirtyChannel(); if (dirtyChannel != -1) { num |= 1u << dirtyChannel; } } if (num == 0u) { return; } for (int j = 0; j < NetworkServer.numChannels; j++) { if ((num & 1u << j) != 0u) { NetworkIdentity.s_UpdateWriter.StartMessage(8); NetworkIdentity.s_UpdateWriter.Write(this.netId); bool flag = false; for (int k = 0; k < this.m_NetworkBehaviours.Length; k++) { short position = NetworkIdentity.s_UpdateWriter.Position; NetworkBehaviour networkBehaviour2 = this.m_NetworkBehaviours[k]; if (networkBehaviour2.GetDirtyChannel() != j) { networkBehaviour2.OnSerialize(NetworkIdentity.s_UpdateWriter, false); } else { if (networkBehaviour2.OnSerialize(NetworkIdentity.s_UpdateWriter, false)) { networkBehaviour2.ClearAllDirtyBits(); flag = true; } if (NetworkIdentity.s_UpdateWriter.Position - position > (short)NetworkServer.maxPacketSize) { Debug.LogWarning(string.Concat(new object[] { "Large state update of ", (int)(NetworkIdentity.s_UpdateWriter.Position - position), " bytes (max is ", NetworkServer.maxPacketSize, " for netId:", this.netId, " from script:", networkBehaviour2 })); } } } if (flag) { NetworkIdentity.s_UpdateWriter.FinishMessage(); NetworkServer.SendWriterToReady(base.gameObject, NetworkIdentity.s_UpdateWriter, j); } } } }