private void SerializePacketInternal(NetDataWriter externalWriter, INetSerializable packet, bool prependLength)
    {
        byte value;
        INetworkPacketSubSerializer <TData> networkPacketSubSerializer;

        if (!this.TryGetPacketType(packet.GetType(), out value, out networkPacketSubSerializer))
        {
            return;
        }
        NetDataWriter netDataWriter = prependLength ? this._internalWriter : externalWriter;

        netDataWriter.Put(value);
        if (networkPacketSubSerializer != null)
        {
            networkPacketSubSerializer.Serialize(netDataWriter, packet);
        }
        else
        {
            packet.Serialize(netDataWriter);
        }
        if (prependLength)
        {
            externalWriter.PutVarUInt((uint)this._internalWriter.Length);
            externalWriter.Put(this._internalWriter.Data, 0, this._internalWriter.Length);
            this._internalWriter.Reset();
        }
    }
 public void SendKnown(NetManager netManager, INetSerializable o, DeliveryMethod deliveryMethod = DeliveryMethod.ReliableOrdered)
 {
     using (var nw = new NetDataWriter())
     {
         WriteHash(o.GetType(), nw);
         o.Serialize(nw);
         netManager.SendToAll(nw, deliveryMethod);
     }
 }
Beispiel #3
0
        public void OnNetSerialize(NetDataWriter writer)
        {
            writer.Write(_isSceneObject);
            writer.Write(_ownerSessionId);
            writer.Write(transform.localPosition);
            writer.Write(transform.localRotation);
            writer.Write(transform.localScale);

            _serializer?.Serialize(writer);
        }
Beispiel #4
0
        public NetWriter Write(INetSerializable serializable)
        {
            if (serializable == null)
            {
                Write(false);
                return(this);
            }

            Write(true);
            serializable.Serialize(this);
            return(this);
        }
        public void Serialize(NetDataWriter writer, object messageData)
        {
            INetSerializable serializable = messageData as INetSerializable;

            if (serializable != null)
            {
                serializable.Serialize(writer);
            }
            else
            {
                Debug.LogError("cant change INetSerializable");
            }
        }
Beispiel #6
0
 private void RequestProceeded(long connectionId, uint ackId, AckResponseCode responseCode, INetSerializable response, SerializerDelegate responseSerializer)
 {
     // Write response
     writer.Reset();
     writer.PutPackedUShort(ResponseMessageType);
     writer.PutPackedUInt(ackId);
     writer.PutValue(responseCode);
     response.Serialize(writer);
     if (responseSerializer != null)
     {
         responseSerializer.Invoke(writer);
     }
     // Send response
     SendMessage(connectionId, DeliveryMethod.ReliableOrdered, writer);
 }
Beispiel #7
0
        //private NetDataWriter writer = null;
        public byte[] Serialize(object msgType, object data)
        {
            NetDataWriter writer = new NetDataWriter(byteOrder);

            writer.Reset();
            writer.PutValue(msgType);
            INetSerializable serializable = data as INetSerializable;

            if (serializable != null)
            {
                serializable.Serialize(writer);
            }
            else
            {
                NetDebug.LogError("cant change INetSerializable");
            }
            return(writer.CopyData());
        }
 public void Serialize(NetDataWriter writer, INetSerializable packet)
 {
     writer.Put(packet.GetType().ToString());
     packet.Serialize(writer);
 }