Пример #1
0
        public static void Serialize(this NetworkWriter writer, UpdateTileMessage.NetMessage message)
        {
            writer.WriteUInt(message.MatrixSyncNetID);
            foreach (var delayedData in message.Changes)
            {
                writer.WriteBool(true);
                writer.WriteVector3Int(delayedData.Position);
                writer.WriteInt((int)delayedData.TileType);
                writer.WriteInt((int)delayedData.layerType);
                writer.WriteString(delayedData.TileName);

                if (delayedData.Colour != Color.white)
                {
                    writer.WriteByte((byte)EnumOperation.Colour);
                    writer.WriteColor(delayedData.Colour);
                }

                if (delayedData.TransformMatrix != Matrix4x4.identity)
                {
                    writer.WriteByte((byte)EnumOperation.Matrix4x4);
                    writer.WriteMatrix4x4(delayedData.TransformMatrix);
                }
                writer.WriteByte((byte)EnumOperation.NoMoreData);
            }
            writer.WriteBool(false);
        }
 public static void WriteScanner(this NetworkWriter writer, Scanner scanner)
 {
     writer.WriteBool(scanner.ScannerOpen);
     writer.WriteBool(scanner.ScannerEmpty);
     writer.WriteString(scanner.DocumentText);
     writer.WriteString(scanner.ScannedText);
 }
Пример #3
0
 public void Serialize(ref bool value)
 {
     if (IsReading)
     {
         value = m_Reader.ReadBool();
     }
     else
     {
         m_Writer.WriteBool(value);
     }
 }
Пример #4
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WriteInt32(connectionId);
     writer.WriteBool(toServer);
     if (extra != null)
         extra.Serialize(writer);
 }
Пример #5
0
        public void Write(NetworkWriter writer)
        {
            writer.Write(ObjectId);
            writer.Write(Id);
            writer.Write(X);
            writer.Write(Y);

            writer.Write(Stats.Length);
            foreach (var i in Stats)
            {
                i.Write(writer);
            }

            writer.Write(LastDirection);
            writer.WriteBool(IsPlayer);
            writer.WriteBool(IsEntity);
        }
Пример #6
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WriteBool(toServer);
     writer.WriteNetworkObjectId(objectId);
     writer.WriteNetworkInstanceId(instanceId);
     if (parameter != null)
     {
         parameter.Serialize(writer);
     }
 }
        public static void Serialize(this NetworkWriter writer, RequestInteractMessage.NetMessage message)
        {
            // indicate unknown component if client requested it
            if (message.ComponentType == null)
            {
                writer.WriteUShort(RequestInteractMessage.UNKNOWN_COMPONENT_TYPE_ID);
            }
            else
            {
                writer.WriteUShort(RequestInteractMessage.componentTypeToComponentID[message.ComponentType]);
            }
            writer.WriteByte(RequestInteractMessage.interactionTypeToInteractionID[message.InteractionType]);
            //server determines processor object if client specified unknown component
            if (message.ComponentType != null)
            {
                writer.WriteUInt(message.ProcessorObject);
            }
            writer.WriteByte((byte)message.Intent);

            if (message.InteractionType == typeof(PositionalHandApply))
            {
                writer.WriteUInt(message.TargetObject);
                writer.WriteVector2(message.TargetVector);
                writer.WriteUInt((uint)message.TargetBodyPart);
                writer.WriteBool(message.IsAltUsed);
            }
            else if (message.InteractionType == typeof(HandApply))
            {
                writer.WriteUInt(message.TargetObject);
                writer.WriteUInt((uint)message.TargetBodyPart);
                writer.WriteBool(message.IsAltUsed);
            }
            else if (message.InteractionType == typeof(AimApply))
            {
                writer.WriteVector2(message.TargetVector);
                writer.WriteBool(message.MouseButtonState == MouseButtonState.PRESS);
                writer.WriteUInt((uint)message.TargetBodyPart);
            }
            else if (message.InteractionType == typeof(MouseDrop))
            {
                writer.WriteUInt(message.TargetObject);
                writer.WriteUInt(message.UsedObject);
            }
            else if (message.InteractionType == typeof(InventoryApply))
            {
                writer.WriteUInt(message.StorageIndexOnGameObject);
                writer.WriteUInt(message.UsedObject);
                writer.WriteUInt(message.Storage);
                writer.WriteInt(message.SlotIndex);
                writer.WriteInt((int)message.NamedSlot);
                writer.WriteBool(message.IsAltUsed);
            }
            else if (message.InteractionType == typeof(TileApply))
            {
                writer.WriteVector2(message.TargetVector);
            }
            else if (message.InteractionType == typeof(TileMouseDrop))
            {
                writer.WriteUInt(message.UsedObject);
                writer.WriteVector2(message.TargetVector);
            }
            else if (message.InteractionType == typeof(ConnectionApply))
            {
                writer.WriteUInt(message.TargetObject);
                writer.WriteVector2(message.TargetVector);
                writer.WriteByte((byte)message.connectionPointA);
                writer.WriteByte((byte)message.connectionPointB);
            }
            else if (message.InteractionType == typeof(ContextMenuApply))
            {
                writer.WriteUInt(message.TargetObject);
                writer.WriteString(message.RequestedOption);
            }
            else if (message.InteractionType == typeof(AiActivate))
            {
                writer.WriteUInt(message.TargetObject);
                writer.WriteByte((byte)message.ClickTypes);
            }
        }
Пример #8
0
 public void Write(NetworkWriter writer, object val)
 {
     writer.WriteBool((bool)val);
 }
 protected override void OnSerialize(NetworkWriter writer)
 {
     writer.WriteString(weaponId);
     writer.WriteInt(currentProjectileCount);
     writer.WriteBool(isReloading);
 }
Пример #10
0
 public static void WritePrinter(this NetworkWriter writer, Printer printer)
 {
     writer.Write(printer.TrayCount);
     writer.Write(printer.TrayCapacity);
     writer.WriteBool(printer.TrayOpen);
 }
        /// <summary>
        /// Used to serialize a NetworkObjects during scene synchronization that occurs
        /// upon a client being approved or a scene transition.
        /// </summary>
        /// <param name="writer">writer into the outbound stream</param>
        /// <param name="targetClientId">clientid we are targeting</param>
        internal void SerializeSceneObject(NetworkWriter writer, ulong targetClientId)
        {
            writer.WriteBool(IsPlayerObject);
            writer.WriteUInt64Packed(NetworkObjectId);
            writer.WriteUInt64Packed(OwnerClientId);

            NetworkObject parentNetworkObject = null;

            if (!AlwaysReplicateAsRoot && transform.parent != null)
            {
                parentNetworkObject = transform.parent.GetComponent <NetworkObject>();
            }

            if (parentNetworkObject == null)
            {
                // We don't have a parent
                writer.WriteBool(false);
            }
            else
            {
                // We do have a parent
                writer.WriteBool(true);
                // Write the parent's NetworkObjectId to be used for linking back to the child
                writer.WriteUInt64Packed(parentNetworkObject.NetworkObjectId);
            }

            // Write if we are a scene object or not
            writer.WriteBool(IsSceneObject ?? true);

            // Write the hash for this NetworkObject
            writer.WriteUInt32Packed(GlobalObjectIdHash);

            if (IncludeTransformWhenSpawning == null || IncludeTransformWhenSpawning(OwnerClientId))
            {
                // Set the position and rotation data marker to true (i.e. flag to know, when reading from the stream, that position and rotation data follows).
                writer.WriteBool(true);

                // Write position
                writer.WriteSinglePacked(transform.position.x);
                writer.WriteSinglePacked(transform.position.y);
                writer.WriteSinglePacked(transform.position.z);

                // Write rotation
                writer.WriteSinglePacked(transform.rotation.eulerAngles.x);
                writer.WriteSinglePacked(transform.rotation.eulerAngles.y);
                writer.WriteSinglePacked(transform.rotation.eulerAngles.z);
            }
            else
            {
                // Set the position and rotation data marker to false (i.e. flag to know, when reading from the stream, that position and rotation data *was not included*)
                writer.WriteBool(false);
            }

            // Write whether we are including network variable data
            writer.WriteBool(NetworkManager.NetworkConfig.EnableNetworkVariable);

            //If we are including NetworkVariable data
            if (NetworkManager.NetworkConfig.EnableNetworkVariable)
            {
                var buffer = writer.GetStream() as NetworkBuffer;

                // Write placeholder size, NOT as a packed value, initially as zero (i.e. we do not know how much NetworkVariable data will be written yet)
                writer.WriteUInt32(0);

                // Mark our current position before we potentially write any NetworkVariable data
                var positionBeforeNetworkVariableData = buffer.Position;

                // Write network variable data
                WriteNetworkVariableData(buffer, targetClientId);

                // If our current buffer position is greater than our positionBeforeNetworkVariableData then we wrote NetworkVariable data
                // Part 1: This will include the total NetworkVariable data size, if there was NetworkVariable data written, to the stream
                // in order to be able to skip past this entry on the deserialization side in the event this NetworkObject fails to be
                // constructed (See Part 2 below in the DeserializeSceneObject method)
                if (buffer.Position > positionBeforeNetworkVariableData)
                {
                    // Store our current stream buffer position
                    var endOfNetworkVariableData = buffer.Position;

                    // Calculate the total NetworkVariable data size written
                    var networkVariableDataSize = endOfNetworkVariableData - positionBeforeNetworkVariableData;

                    // Move the stream position back to just before we wrote our size (we include the unpacked UInt32 data size placeholder)
                    buffer.Position = positionBeforeNetworkVariableData - sizeof(uint);

                    // Now write the actual data size written into our unpacked UInt32 placeholder position
                    writer.WriteUInt32((uint)(networkVariableDataSize));

                    // Finally, revert the buffer position back to the end of the network variable data written
                    buffer.Position = endOfNetworkVariableData;
                }
            }
        }
 public void Serialize(NetworkWriter writer)
 {
     writer.WriteString(WeaponId);
     writer.WriteInt(CurrentBullets);
     writer.WriteBool(IsReloading);
 }