WritePackedUInt64() public method

This writes the 64-bit value to the stream using variable-length-encoding.

public WritePackedUInt64 ( ulong value ) : void
value ulong Value to write.
return void
 public virtual bool OnSerialize(NetworkWriter writer, bool initialState)
 {
     if (!initialState)
     {
         writer.WritePackedUInt64(0);
     }
     return(false);
 }
Example #2
0
        // 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);
        }