Write() public method

This writes a reference to an object, value, buffer or network message, together with a NetworkIdentity component to the stream.

public Write ( Color value ) : void
value Color The object to write.
return void
Example #1
0
    // A "Voos Name" may be a 32-char GUID or just some string, like
    // __DEFAULT_BEHAVIOR__
    public static void WriteVoosName(this NET.NetworkWriter writer, string name)
    {
        if (name.IsNullOrEmpty())
        {
            writer.Write(VN_EMPTY);
            return;
        }

        System.Guid guid;
        if (System.Guid.TryParseExact(name, "N", out guid))
        {
            writer.Write(VN_GUID); // Indicate GUID
            byte[] bytes = guid.ToByteArray();
            Debug.Assert(bytes.Length == 16);
            for (int i = 0; i < 16; i++)
            {
                writer.Write(bytes[i]);
            }
        }
        else
        {
            // Some string, maybe null/empty
            writer.Write(VN_UTF16);
            writer.WriteUtf16(name);
        }
    }
Example #2
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(this.netId);
     writer.WritePackedUInt32((uint) this.stateHash);
     writer.Write(this.normalizedTime);
     writer.WriteBytesAndSize(this.parameters, this.parameters.Length);
 }
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(this.netId);
     writer.Write(this.sceneId);
     writer.Write(this.position);
     writer.WriteBytesFull(this.payload);
 }
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(this.netId);
     writer.WriteBytesFull(this.payload);
     writer.Write(this.teleport);
     writer.WritePackedUInt32((uint) this.time);
 }
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(proxyId);
     writer.Write((short)packet.Compression);
     writer.Write(packet.Length);
     writer.WriteBytesFull(packet.Data);
 }
    public byte[] Serialize()
    {
        byte[] buffer = new byte[
            4   // version
            + 4 // zero for block count
            + 4 // south count
            + southSideMap.Count * 4
            + 4 // west count
            + westSideMap.Count * 4
            + 1 // ending sanity check number
            + 1 // extra byte cuz NetworkWriter is buggy:
                // https://bitbucket.org/Unity-Technologies/networking/src/78ca8544bbf4e87c310ce2a9a3fc33cdad2f9bb1/Runtime/NetworkBuffer.cs?at=5.3&fileviewer=file-view-default#NetworkBuffer.cs-160
                        ];
        var writer = new UnityEngine.Networking.NetworkWriter(buffer);

        writer.Write(CurrentVersion);

        // Write dummy block count
        writer.Write(0);

        SerializeSideMap(southSideMap, writer);
        SerializeSideMap(westSideMap, writer);

        // Sanity check
        writer.Write((byte)42);

        // Util.Log($"Wrote {blockMap.Count} blocks, {southSideMap.Count} south walls, and {westSideMap.Count} west walls to {buffer.Length} bytes");
        return(buffer);
    }
Example #7
0
 public override void Serialize(NetworkWriter writer)
 {
     base.Serialize(writer);
     writer.Write(Polyline.Count);
     foreach (var vector3 in Polyline)
         writer.Write(vector3);
 }
Example #8
0
 public static void WriteColor(this UnityEngine.Networking.NetworkWriter writer, Color c)
 {
     writer.Write(c.r);
     writer.Write(c.g);
     writer.Write(c.b);
     writer.Write(c.a);
 }
Example #9
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32((uint) this.connectionId);
     writer.Write(this.address);
     writer.WritePackedUInt32((uint) this.port);
     writer.Write(this.isHost);
     writer.Write(this.isYou);
 }
    /// <summary>
    /// Server: Serialize the state over network
    /// </summary>
    /// <param name="writer"></param>
    /// <param name="initialState"></param>
    /// <returns></returns>
    public override bool OnSerialize(NetworkWriter writer, bool initialState)
    {
        writer.Write(serverLastState.state);
        writer.Write(serverLastState.position);
        writer.Write(serverLastState.rotation);

        return true;
    }
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(ChannelId);
     writer.Write(SenderUserId);
     writer.Write(SenderUserName);
     writer.Write(Message);
     var json = JsonWrapper.SerializeObject(Timestamp);
     writer.Write(json);
 }
Example #12
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write((ushort) this.scripts.Length);
     for (int i = 0; i < this.scripts.Length; i++)
     {
         writer.Write(this.scripts[i].name);
         writer.Write(this.scripts[i].channel);
     }
 }
 public override void Serialize(NetworkWriter writer)
 {
     base.Serialize(writer);
     writer.Write(_instructionBase);
     writer.Write(_variantReplacements.Length);
     foreach (string replacement in _variantReplacements) {
         writer.Write(replacement);
     }
 }
 /// <summary>
 /// Send an Update to all Clients of the Status Connection of a Player
 /// </summary>
 /// <remarks>
 /// Order:
 /// String UserName
 /// bool ConnectedStatus
 /// float ServerTime
 /// </remarks>
 /// <param name="UserName"></param>
 /// <param name="connectedStatus"></param>
 /// <param name="ServerTime"></param>
 public void PlayerStatusUpdate(String UserName, bool connectedStatus, float ServerTime)
 {
     NetworkWriter data = new NetworkWriter();
     data.Write((ushort)Subjects.PlayerStatusUpdate);
     data.Write(UserName);
     data.Write(connectedStatus);
     data.Write(ServerTime);
     OutputMessage output = new OutputMessage(data);
     GameServer.LLApiServer.addOutPutMessageToQueue(output);
 }
 void SerializeSideMap(SortedDictionary <Cell, SideInfo> map, UnityEngine.Networking.NetworkWriter writer)
 {
     writer.Write(map.Count);
     foreach (var pair in map)
     {
         writer.Write(pair.Value.b0);
         Debug.Assert(pair.Key.x + cellArrayOffsetX < 256);
         Debug.Assert(pair.Key.y + cellArrayOffsetY < 256);
         Debug.Assert(pair.Key.z + cellArrayOffsetZ < 256);
         writer.Write((byte)(pair.Key.x + cellArrayOffsetX));
         writer.Write((byte)(pair.Key.y + cellArrayOffsetY));
         writer.Write((byte)(pair.Key.z + cellArrayOffsetZ));
     }
 }
 public override bool OnSerialize(NetworkWriter writer, bool initialState)
 {
     var serialized = base.OnSerialize (writer, initialState);
     var time = animator.playbackTime;
     writer.Write (time);
     return serialized;
 }
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32((uint) this.oldConnectionId);
     writer.WritePackedUInt32((uint) this.playerControllerId);
     writer.Write(this.netId);
     writer.WriteBytesAndSize(this.msgData, this.msgSize);
 }
Example #18
0
    public void TestNetworkWriterSize()
    {
        var writer = new UnityEngine.Networking.NetworkWriter();

        writer.Write((byte)42);
        byte[] bytes = writer.ToArray();
        Assert.AreEqual(1, bytes.Length);
    }
Example #19
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write((ushort) this.peers.Length);
     foreach (PeerInfoMessage message in this.peers)
     {
         message.Serialize(writer);
     }
 }
Example #20
0
    public static void WriteUtf16(this UnityEngine.Networking.NetworkWriter writer, string s)
    {
        if (s == null)
        {
            writer.Write((ushort)0);
            return;
        }

        if (s.Length >= 65535)
        {
            throw new System.Exception("We do not support serializing strings of length beyond 65k chars");
        }
        writer.Write((ushort)s.Length);
        for (int i = 0; i < s.Length; i++)
        {
            writer.Write((ushort)s[i]);
        }
    }
Example #21
0
    public void TestNetworkWriterWorkaround()
    {
        // Work around is to add 1 more byte to the end to avoid the resize...
        byte[] buffer = new byte[2];
        var    writer = new UnityEngine.Networking.NetworkWriter(buffer);

        writer.Write((byte)42);
        Assert.AreEqual((byte)42, buffer[0]);
    }
Example #22
0
    public void TestNetworkWriterBug()
    {
        byte[] buffer = new byte[1];
        var    writer = new UnityEngine.Networking.NetworkWriter(buffer);

        writer.Write((byte)42);
        // You'd expect this to be 42...but actually it's 0 cuz NetworkWriter wrongly resized into a new buffer...
        Assert.AreEqual((byte)0, buffer[0]);
    }
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32((uint) this.oldServerConnectionId);
     writer.Write((ushort) this.peers.Length);
     for (int i = 0; i < this.peers.Length; i++)
     {
         this.peers[i].Serialize(writer);
     }
 }
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(this.netId);
     if (this.parameters == null)
     {
         writer.WriteBytesAndSize(this.parameters, 0);
     }
     else
     {
         writer.WriteBytesAndSize(this.parameters, this.parameters.Length);
     }
 }
Example #25
0
    public override bool OnSerialize(NetworkWriter writer, bool initialState)
    {
        bool needToUpdate = false;

        if (fbxObj != null)
        {
            //Call an fbxobj method to write whatever is necessary, return true if "needToUpdate"
            writer.Write(fbxObj.gameObject.transform.position);
            needToUpdate = true;
        }
        return needToUpdate;
    }
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32((uint) this.connectionId);
     writer.Write(this.address);
     writer.WritePackedUInt32((uint) this.port);
     writer.Write(this.isHost);
     writer.Write(this.isYou);
     if (this.playerIds == null)
     {
         writer.WritePackedUInt32(0);
     }
     else
     {
         writer.WritePackedUInt32((uint) this.playerIds.Length);
         for (int i = 0; i < this.playerIds.Length; i++)
         {
             writer.Write(this.playerIds[i].netId);
             writer.WritePackedUInt32((uint) this.playerIds[i].playerControllerId);
         }
     }
 }
Example #27
0
    public override void Serialize(NetworkWriter writer)
    {
        base.Serialize(writer);

        Type t = _actionSet.GetType();
        if (t == typeof(SinglePanelActionSet)) {
            writer.Write((byte)0);
        } else if (t == typeof(ReplacementPanelActionSet)) {
            writer.Write((byte)1);
        } else if (t == typeof(CodePanelActionSet)) {
            writer.Write((byte)2);
        } else {
            throw new Exception("Unexpected Action Set Type " + t);
        }

        _actionSet.Serialize(writer);

        writer.Write(_x);
        writer.Write(_y);
        writer.Write(_prefabIndex);
    }
Example #28
0
    public void AddOurselves(ClientPlayer player, NetworkWriter nw)
    {
        player.currentVessel = this;
        player.ChunkI = WorldToChunkI((Vector2)player.transform.position);

        int rangeT = (PLAYER_CHUNK_RANGE * 2) + 1;

        nw.Write((ushort)ClientMessageType.RequestChunk);
        nw.Write((ushort)(rangeT * rangeT));

        for (int i = 0; i < rangeT; i++) {
            for (int j = 0; j < rangeT; j++) {

                Vec2i temp = player.ChunkI + new Vec2i(i - PLAYER_CHUNK_RANGE, j - PLAYER_CHUNK_RANGE);
                if (!((temp - player.ChunkI) <= PLAYER_CHUNK_RANGE)) {
                    VesselChunk temp2 = chunks.TryGet(temp.x, temp.y);

                    nw.Write(temp.x);
                    nw.Write(temp.y);

                    if (temp2 != null) {
                        nw.Write(temp2.version);
                    } else {
                        nw.Write((uint)uint.MaxValue);
                    }
                }
            }
        }
    }
Example #29
0
	public void WriteSetChunk(NetworkWriter nw)
	{
		if (updateMessageBytes) {

			NetworkWriter temp = new NetworkWriter();

			temp.Write(index.x);
			temp.Write(index.y);
			
			temp.Write(version);
			temp.Write(tileCount);
			
			for (int i = 0; i < VesselChunk.SIZE; i++) {
				
				for (int j = 0; j < VesselChunk.SIZE; j++) {
					
					VesselTile tile = TileAt(i, j);
					
					if (tile != null) {
						
						temp.Write(i);
						temp.Write(j);
						temp.Write((byte)tile.floor0);
						temp.Write((byte)tile.floor1);
						temp.Write((byte)tile.wallMask);
						temp.Write(tile.wallNode);
						
					}
				}
			}
			
			messageBytes = temp.ToArray();
			
			updateMessageBytes = false;
		}

		nw.WriteBytesFull(messageBytes);
	}
 /// <summary>
 /// Return Information of the Server
 /// </summary>
 /// <remarks>
 /// Order:
 /// bool success
 /// float ServerTime
 /// string detailMessage
 /// ushort ConnetedUserCount -> UserNames Length
 /// string[] UserNames
 /// </remarks>
 /// <param name="connectionID"></param>
 /// <param name="success"></param>
 /// <param name="detailMessage"></param>
 private void ServerInfoResponse(int connectionID, bool success, string detailMessage)
 {
     NetworkWriter data = new NetworkWriter();
     data.Write((ushort)Subjects.ServerInfoResponse);
     data.Write(success);
     if (success)
     {
         data.Write(GameServer.getServerTime());
     }
     else
     {
         data.Write((float)0);
     }
     
     data.Write(detailMessage);
     if (!success)
     {
         data.Write((ushort)0);
     }
     else
     {
         List<string> UserNames = GameServer.UserManager.getConnectedUserNames();
         data.Write((ushort)UserNames.Count);
         foreach(string userName in UserNames)
         {
             data.Write(userName);
         }
     }
     OutputMessage output = new OutputMessage(data, connectionID);
     GameServer.LLApiServer.addOutPutMessageToQueue(output);
 }
 /// <summary>
 ///  Return the DisconnectResponse to the client
 /// </summary>
 /// <remarks>
 ///  Order:
 ///  String success
 ///  String detailMessage
 ///  float serverTime
 /// </remarks>
 /// <param name="connectionID"></param>
 /// <param name="success"></param>
 /// <param name="detailMessage"></param>
 private void DisconnectResponse(int connectionID, bool success, string detailMessage)
 {
     NetworkWriter data = new NetworkWriter();
     data.Write((ushort)Subjects.LogOutResponse);
     data.Write(success);
     data.Write(detailMessage);
     data.Write(GameServer.getServerTime());
     OutputMessage output = new OutputMessage(data, connectionID);
     GameServer.LLApiServer.addOutPutMessageToQueue(output);
 }
 public static void SerializeVelocity3D(NetworkWriter writer, Vector3 velocity, NetworkTransform.CompressionSyncMode compression)
 {
   writer.Write(velocity);
 }
 private static void WriteAngle(NetworkWriter writer, float angle, NetworkTransform.CompressionSyncMode compression)
 {
   switch (compression)
   {
     case NetworkTransform.CompressionSyncMode.None:
       writer.Write(angle);
       break;
     case NetworkTransform.CompressionSyncMode.Low:
       writer.Write((short) angle);
       break;
     case NetworkTransform.CompressionSyncMode.High:
       writer.Write((short) angle);
       break;
   }
 }
Example #34
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write((int)ActionMode);
 }
        //send transform data out
        void SerializeModeTransform(NetworkWriter writer)
        {
            int        start = writer.Position;
            int        i     = 0;
            Quaternion relativeRotation;
            Vector3    relativePosition;

            print("Serialize: numbones=" + m_Bones.Length);
            foreach (var bone in m_Bones)
            {
                if (!bone)
                {  //send bad quaternion if no bone
                    Debug.Log("server skipping bone " + i + ",bone=" + boneIndex2MecanimMap[i]);
                    i++;
                    relativeRotation   = Quaternion.identity;
                    relativePosition   = Vector3.zero;
                    relativePosition.x = 111f;
                    relativePosition.y = 222f;
                    relativePosition.z = 333f;
                    writer.Write(relativePosition);
                    if (m_SyncRotationAxis != NetworkTransform.AxisSyncMode.None)
                    {
                        NetworkTransform.SerializeRotation3D(writer, relativeRotation, syncRotationAxis, rotationSyncCompression);
                    }
                    continue;
                }
                // position
                if (globalData)
                {
                    relativePosition = bone.position;
                }
                else
                {
                    relativePosition = bone.localPosition;
                }

                writer.Write(relativePosition);

                if (globalData)
                {
                    //                    relativeRotation = Quaternion.Inverse(initialRotations[i]) * bone.rotation;
                    relativeRotation = bone.rotation * Quaternion.Inverse(initialRotations[i]);
                }
                else
                {
                    relativeRotation = bone.localRotation; // * Quaternion.Inverse(initialLocalRotations[i++]);
                }
                // rotation
                if (m_SyncRotationAxis != NetworkTransform.AxisSyncMode.None)
                {
                    NetworkTransform.SerializeRotation3D(writer, relativeRotation, syncRotationAxis, rotationSyncCompression);
                }
                if (i == -1)
                {
                    print("server processing bone " + i + ",bone=" + boneIndex2MecanimMap[i]);
                    print("server processing bone " + i + ",rot=" + relativeRotation);
                    print("server processing bone " + i + ",pos=" + relativePosition);
                }
                i++;
            }

            int sz = writer.Position - start;

            if (sz > 1400 && binarySize == 0)
            {
                // this is only generated once.
                Debug.LogWarning("NetworkSkeleton binary serialization size is very large:" + sz + ". Consider reducing the number of levels being synchronized.");
            }
            binarySize = sz;
        }
Example #36
0
        // 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);
                }
            }
        }
Example #37
0
 public static void SerializeVelocity2D(NetworkWriter writer, Vector2 velocity, CompressionSyncMode compression)
 {
     writer.Write(velocity);
 }
Example #38
0
 public override bool OnSerialize(NetworkWriter writer, bool initialState)
 {
     writer.WritePackedUInt32(1);
     writer.Write(this.m_Slot);
     writer.Write(this.m_ReadyToBegin);
     return true;
 }
 public override void Serialize(UnityEngine.Networking.NetworkWriter writer)
 {
     base.Serialize(writer);
     writer.Write(_actionInstruction);
 }
 private void SerializeModeTransform(NetworkWriter writer)
 {
   writer.Write(this.m_Target.localPosition);
   if (this.m_SyncRotationAxis != NetworkTransform.AxisSyncMode.None)
     NetworkTransform.SerializeRotation3D(writer, this.m_Target.localRotation, this.syncRotationAxis, this.rotationSyncCompression);
   this.m_PrevPosition = this.m_Target.localPosition;
   this.m_PrevRotation = this.m_Target.localRotation;
 }
 private void SerializeMode2D(NetworkWriter writer)
 {
   if (this.isServer && (double) this.m_LastClientSyncTime != 0.0)
   {
     writer.Write((Vector2) this.m_TargetSyncPosition);
     NetworkTransform.SerializeVelocity2D(writer, (Vector2) this.m_TargetSyncVelocity, NetworkTransform.CompressionSyncMode.None);
     if (this.syncRotationAxis != NetworkTransform.AxisSyncMode.None)
     {
       float rot = this.m_TargetSyncRotation2D % 360f;
       if ((double) rot < 0.0)
         rot += 360f;
       NetworkTransform.SerializeRotation2D(writer, rot, this.rotationSyncCompression);
     }
   }
   else
   {
     writer.Write(this.m_RigidBody2D.position);
     NetworkTransform.SerializeVelocity2D(writer, this.m_RigidBody2D.velocity, NetworkTransform.CompressionSyncMode.None);
     if (this.syncRotationAxis != NetworkTransform.AxisSyncMode.None)
     {
       float rot = this.m_RigidBody2D.rotation % 360f;
       if ((double) rot < 0.0)
         rot += 360f;
       NetworkTransform.SerializeRotation2D(writer, rot, this.rotationSyncCompression);
     }
   }
   if (this.m_SyncSpin)
     NetworkTransform.SerializeSpin2D(writer, this.m_RigidBody2D.angularVelocity, this.rotationSyncCompression);
   this.m_PrevPosition = (Vector3) this.m_RigidBody2D.position;
   this.m_PrevRotation = this.transform.rotation;
   this.m_PrevVelocity = this.m_RigidBody2D.velocity.sqrMagnitude;
 }
Example #42
0
 public override void Serialize(NetworkWriter writer)
 {
     base.Serialize(writer);
     writer.Write(Point);
 }
Example #43
0
 public static void WriteVoosVector3(this UnityEngine.Networking.NetworkWriter writer, Vector3 v)
 {
     writer.Write(v.x);
     writer.Write(v.y);
     writer.Write(v.z);
 }
Example #44
0
 public virtual void Serialize(UnityEngine.Networking.NetworkWriter writer)
 {
     writer.Write(_setId);
     writer.Write(_currentVariantIndex);
     writer.Write(_panelLabel);
 }
Example #45
0
 protected override void SerializeItem(NetworkWriter writer, bool item)
 {
     writer.Write(item);
 }
 public override void Serialize(UnityEngine.Networking.NetworkWriter writer)
 {
     writer.Write(slotId);
     writer.Write(loadedState);
 }
Example #47
0
 public static void WriteVoosBoolean(this UnityEngine.Networking.NetworkWriter writer, bool val)
 {
     writer.Write((byte)(val ? 1 : 0));
 }