Ejemplo n.º 1
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(netId);
     writer.WritePackedUInt32((uint)stateHash);
     writer.Write(normalizedTime);
     writer.WriteBytesAndSize(parameters);
 }
Ejemplo n.º 2
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32(netId);
     writer.WritePackedUInt32((uint)componentIndex);
     writer.Write(functionHash);
     writer.WriteBytesAndSize(payload);
 }
Ejemplo n.º 3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        // vis2k: readstring bug prevention: https://issuetracker.unity3d.com/issues/unet-networkwriter-dot-write-causing-readstring-slash-readbytes-out-of-range-errors-in-clients
        // -> OnSerialize writes length,componentData,length,componentData,...
        // -> OnDeserialize carefully extracts each data, then deserializes each component with separate readers
        //    -> it will be impossible to read too many or too few bytes in OnDeserialize
        //    -> we can properly track down errors
        internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, bool initialState)
        {
            // serialize into a temporary writer
            NetworkWriter temp   = new NetworkWriter();
            bool          result = false;

            try
            {
                result = comp.OnSerialize(temp, initialState);
            }
            catch (Exception e)
            {
                // show a detailed error and let the user know what went wrong
                Debug.LogError("OnSerialize failed for: object=" + name + " component=" + comp.GetType() + " sceneId=" + m_SceneId + "\n\n" + e.ToString());
            }
            byte[] bytes = temp.ToArray();
            if (LogFilter.logDebug)
            {
                Debug.Log("OnSerializeSafely written for object=" + comp.name + " component=" + comp.GetType() + " sceneId=" + m_SceneId + " length=" + bytes.Length);
            }

            // original HLAPI had a warning in UNetUpdate() in case of large state updates. let's move it here, might
            // be useful for debugging.
            if (bytes.Length > Transport.MaxPacketSize)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp);
                }
            }

            // serialize length,data into the real writer, untouched by user code
            writer.WriteBytesAndSize(bytes);
            return(result);
        }
Ejemplo n.º 4
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(netId);
     writer.Write(sceneId);
     writer.Write(position);
     writer.WriteBytesAndSize(payload);
 }
Ejemplo n.º 5
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32(netId);
     writer.Write(assetId);
     writer.Write(position);
     writer.Write(rotation);
     writer.WriteBytesAndSize(payload);
 }
Ejemplo n.º 6
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WriteBytesAndSize(value);
 }
Ejemplo n.º 7
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(netId);
     writer.WritePackedUInt32(childIndex);
     writer.WriteBytesAndSize(payload);
 }
Ejemplo n.º 8
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(netId);
     writer.WriteBytesAndSize(parameters);
 }
Ejemplo n.º 9
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(netId);
     writer.Write(syncListHash);
     writer.WriteBytesAndSize(payload);
 }
Ejemplo n.º 10
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WriteBytesAndSize(msgData);
 }
Ejemplo n.º 11
0
 public static void WriteBytesAndSizeSegment(this NetworkWriter writer, ArraySegment <byte> buffer)
 {
     writer.WriteBytesAndSize(buffer.Array, buffer.Offset, buffer.Count);
 }
Ejemplo n.º 12
0
 // Weaver needs a write function with just one byte[] parameter
 // (we don't name it .Write(byte[]) because it's really a WriteBytesAndSize since we write size / null info too)
 public static void WriteBytesAndSize(this NetworkWriter writer, byte[] buffer)
 {
     // buffer might be null, so we can't use .Length in that case
     writer.WriteBytesAndSize(buffer, 0, buffer != null ? buffer.Length : 0);
 }
Ejemplo n.º 13
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32((uint)playerControllerId);
     writer.WriteBytesAndSize(msgData);
 }
Ejemplo n.º 14
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32(netId);
     writer.Write(eventHash);
     writer.WriteBytesAndSize(payload);
 }