当前位置: 首页>>代码示例>>C#>>正文


C# NetworkWriter.ToArray方法代码示例

本文整理汇总了C#中UnityEngine.Networking.NetworkWriter.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkWriter.ToArray方法的具体用法?C# NetworkWriter.ToArray怎么用?C# NetworkWriter.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Networking.NetworkWriter的用法示例。


在下文中一共展示了NetworkWriter.ToArray方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteSetChunk

	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);
	}
开发者ID:NickPowers43,项目名称:SW,代码行数:38,代码来源:ServerVC.cs

示例2: SendWriter

 /// <summary>
 /// <para>This sends the contents of a NetworkWriter object on the connection.</para>
 /// </summary>
 /// <param name="writer">A writer object containing data to send.</param>
 /// <param name="channelId">The transport channel to send on.</param>
 /// <returns>
 /// <para>True if the data was sent.</para>
 /// </returns>
 public virtual bool SendWriter(NetworkWriter writer, int channelId)
 {
     if (this.logNetworkMessages)
     {
         this.LogSend(writer.ToArray());
     }
     return (this.CheckChannel(channelId) && this.m_Channels[channelId].SendWriter(writer));
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:16,代码来源:NetworkConnection.cs

示例3: SendWriter

 /// <summary>
 ///   <para>This sends the contents of a NetworkWriter object on the connection.</para>
 /// </summary>
 /// <param name="writer">A writer object containing data to send.</param>
 /// <param name="channelId">The transport channel to send on.</param>
 /// <returns>
 ///   <para>True if the data was sent.</para>
 /// </returns>
 public virtual bool SendWriter(NetworkWriter writer, int channelId)
 {
   if (this.logNetworkMessages)
     this.LogSend(writer.ToArray());
   if (this.CheckChannel(channelId))
     return this.m_Channels[channelId].SendWriter(writer);
   return false;
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:16,代码来源:NetworkConnection.cs

示例4: AddPlayer

 /// <summary>
 ///   <para>This adds a player object for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer will be called. If an extra message was passed to AddPlayer, then OnServerAddPlayer will be called with a NetworkReader that contains the contents of the message.</para>
 /// </summary>
 /// <param name="readyConn">The connection to become ready for this client.</param>
 /// <param name="playerControllerId">The local player ID number.</param>
 /// <param name="extraMessage">An extra message object that can be passed to the server for this player.</param>
 /// <returns>
 ///   <para>True if player was added.</para>
 /// </returns>
 public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId, MessageBase extraMessage)
 {
   if ((int) playerControllerId < 0)
   {
     if (LogFilter.logError)
       Debug.LogError((object) ("ClientScene::AddPlayer: playerControllerId of " + (object) playerControllerId + " is negative"));
     return false;
   }
   if ((int) playerControllerId > 32)
   {
     if (LogFilter.logError)
       Debug.LogError((object) ("ClientScene::AddPlayer: playerControllerId of " + (object) playerControllerId + " is too high, max is " + (object) 32));
     return false;
   }
   if ((int) playerControllerId > 16 && LogFilter.logWarn)
     Debug.LogWarning((object) ("ClientScene::AddPlayer: playerControllerId of " + (object) playerControllerId + " is unusually high"));
   while ((int) playerControllerId >= ClientScene.s_LocalPlayers.Count)
     ClientScene.s_LocalPlayers.Add(new PlayerController());
   if (readyConn == null)
   {
     if (!ClientScene.s_IsReady)
     {
       if (LogFilter.logError)
         Debug.LogError((object) "Must call AddPlayer() with a connection the first time to become ready.");
       return false;
     }
   }
   else
   {
     ClientScene.s_IsReady = true;
     ClientScene.s_ReadyConnection = readyConn;
   }
   PlayerController playerController;
   if (ClientScene.s_ReadyConnection.GetPlayerController(playerControllerId, out playerController) && playerController.IsValid && (Object) playerController.gameObject != (Object) null)
   {
     if (LogFilter.logError)
       Debug.LogError((object) ("ClientScene::AddPlayer: playerControllerId of " + (object) playerControllerId + " already in use."));
     return false;
   }
   if (LogFilter.logDebug)
     Debug.Log((object) ("ClientScene::AddPlayer() for ID " + (object) playerControllerId + " called with connection [" + (object) ClientScene.s_ReadyConnection + "]"));
   if (ClientScene.s_ReconnectId == -1)
   {
     AddPlayerMessage addPlayerMessage = new AddPlayerMessage();
     addPlayerMessage.playerControllerId = playerControllerId;
     if (extraMessage != null)
     {
       NetworkWriter writer = new NetworkWriter();
       extraMessage.Serialize(writer);
       addPlayerMessage.msgData = writer.ToArray();
       addPlayerMessage.msgSize = (int) writer.Position;
     }
     ClientScene.s_ReadyConnection.Send((short) 37, (MessageBase) addPlayerMessage);
   }
   else
   {
     if (LogFilter.logDebug)
       Debug.Log((object) ("ClientScene::AddPlayer reconnect " + (object) ClientScene.s_ReconnectId));
     if (ClientScene.s_Peers == null)
     {
       ClientScene.SetReconnectId(-1, (PeerInfoMessage[]) null);
       if (LogFilter.logError)
         Debug.LogError((object) "ClientScene::AddPlayer: reconnecting, but no peers.");
       return false;
     }
     foreach (PeerInfoMessage peer in ClientScene.s_Peers)
     {
       if (peer.playerIds != null && peer.connectionId == ClientScene.s_ReconnectId)
       {
         foreach (PeerInfoPlayer playerId in peer.playerIds)
         {
           ReconnectMessage reconnectMessage = new ReconnectMessage();
           reconnectMessage.oldConnectionId = ClientScene.s_ReconnectId;
           reconnectMessage.netId = playerId.netId;
           reconnectMessage.playerControllerId = playerId.playerControllerId;
           if (extraMessage != null)
           {
             NetworkWriter writer = new NetworkWriter();
             extraMessage.Serialize(writer);
             reconnectMessage.msgData = writer.ToArray();
             reconnectMessage.msgSize = (int) writer.Position;
           }
           ClientScene.s_ReadyConnection.Send((short) 47, (MessageBase) reconnectMessage);
         }
       }
     }
     ClientScene.SetReconnectId(-1, (PeerInfoMessage[]) null);
   }
   return true;
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:99,代码来源:ClientScene.cs

示例5: SendSpawnMessage

 internal void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn)
 {
     if (uv.serverOnly)
     return;
       if (uv.sceneId.IsEmpty())
       {
     ObjectSpawnMessage objectSpawnMessage = new ObjectSpawnMessage();
     objectSpawnMessage.netId = uv.netId;
     objectSpawnMessage.assetId = uv.assetId;
     objectSpawnMessage.position = uv.transform.position;
     NetworkWriter writer = new NetworkWriter();
     uv.UNetSerializeAllVars(writer);
     if ((int) writer.Position > 0)
       objectSpawnMessage.payload = writer.ToArray();
     if (conn != null)
       conn.Send((short) 3, (MessageBase) objectSpawnMessage);
     else
       NetworkServer.SendToReady(uv.gameObject, (short) 3, (MessageBase) objectSpawnMessage);
     NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short) 3, uv.assetId.ToString(), 1);
       }
       else
       {
     ObjectSpawnSceneMessage spawnSceneMessage = new ObjectSpawnSceneMessage();
     spawnSceneMessage.netId = uv.netId;
     spawnSceneMessage.sceneId = uv.sceneId;
     spawnSceneMessage.position = uv.transform.position;
     NetworkWriter writer = new NetworkWriter();
     uv.UNetSerializeAllVars(writer);
     if ((int) writer.Position > 0)
       spawnSceneMessage.payload = writer.ToArray();
     if (conn != null)
       conn.Send((short) 10, (MessageBase) spawnSceneMessage);
     else
       NetworkServer.SendToReady(uv.gameObject, (short) 3, (MessageBase) spawnSceneMessage);
     NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short) 10, "sceneId", 1);
       }
 }
开发者ID:Kitabalef,项目名称:Unet-Decompiles,代码行数:37,代码来源:NetworkServer.cs

示例6: SendMessage

 public bool SendMessage(int connectionId, NetworkWriter writer, int channel, out NetworkError Error)
 {
     byte error;
     byte[] buffer = writer.ToArray();
     NetworkTransport.Send(SocketId, connectionId, channel, buffer, buffer.Length, out error);
     Error = (NetworkError)error;
     if (Error != NetworkError.Ok)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
开发者ID:buronix,项目名称:LLApi-Basic-Implementation,代码行数:15,代码来源:LLApiServer.cs

示例7: AddPlayer

 /// <summary>
 /// <para>This adds a player GameObject for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer is called. If an extra message was passed to AddPlayer, then OnServerAddPlayer will be called with a NetworkReader that contains the contents of the message.</para>
 /// </summary>
 /// <param name="readyConn">The connection to become ready for this client.</param>
 /// <param name="playerControllerId">The local player ID number.</param>
 /// <param name="extraMessage">An extra message object that can be passed to the server for this player.</param>
 /// <returns>
 /// <para>True if player was added.</para>
 /// </returns>
 public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId, MessageBase extraMessage)
 {
     PlayerController controller;
     if (playerControllerId < 0)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is negative");
         }
         return false;
     }
     if (playerControllerId > 0x20)
     {
         if (LogFilter.logError)
         {
             Debug.LogError(string.Concat(new object[] { "ClientScene::AddPlayer: playerControllerId of ", playerControllerId, " is too high, max is ", 0x20 }));
         }
         return false;
     }
     if ((playerControllerId > 0x10) && LogFilter.logWarn)
     {
         Debug.LogWarning("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is unusually high");
     }
     while (playerControllerId >= s_LocalPlayers.Count)
     {
         s_LocalPlayers.Add(new PlayerController());
     }
     if (readyConn == null)
     {
         if (!s_IsReady)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("Must call AddPlayer() with a connection the first time to become ready.");
             }
             return false;
         }
     }
     else
     {
         s_IsReady = true;
         s_ReadyConnection = readyConn;
     }
     if (s_ReadyConnection.GetPlayerController(playerControllerId, out controller) && (controller.IsValid && (controller.gameObject != null)))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " already in use.");
         }
         return false;
     }
     if (LogFilter.logDebug)
     {
         Debug.Log(string.Concat(new object[] { "ClientScene::AddPlayer() for ID ", playerControllerId, " called with connection [", s_ReadyConnection, "]" }));
     }
     if (s_ReconnectId == -1)
     {
         AddPlayerMessage msg = new AddPlayerMessage {
             playerControllerId = playerControllerId
         };
         if (extraMessage != null)
         {
             NetworkWriter writer = new NetworkWriter();
             extraMessage.Serialize(writer);
             msg.msgData = writer.ToArray();
             msg.msgSize = writer.Position;
         }
         s_ReadyConnection.Send(0x25, msg);
     }
     else
     {
         if (LogFilter.logDebug)
         {
             Debug.Log("ClientScene::AddPlayer reconnect " + s_ReconnectId);
         }
         if (s_Peers == null)
         {
             SetReconnectId(-1, null);
             if (LogFilter.logError)
             {
                 Debug.LogError("ClientScene::AddPlayer: reconnecting, but no peers.");
             }
             return false;
         }
         for (int i = 0; i < s_Peers.Length; i++)
         {
             PeerInfoMessage message2 = s_Peers[i];
             if ((message2.playerIds != null) && (message2.connectionId == s_ReconnectId))
             {
                 for (int j = 0; j < message2.playerIds.Length; j++)
                 {
//.........这里部分代码省略.........
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:101,代码来源:ClientScene.cs

示例8: StrokeMessage

    // line only
    private byte[] StrokeMessage(byte tile,
                                 Color color,
                                 int size,
                                 Vector2 start,
                                 Vector2 end)
    {
        var writer = new NetworkWriter();

        uint sx = (uint) Mathf.FloorToInt(start.x);
        uint sy = (uint) Mathf.FloorToInt(start.y);
        uint ex = (uint) Mathf.FloorToInt(end.x);
        uint ey = (uint) Mathf.FloorToInt(end.y);

        byte index = world.ColorToPalette(color, true);

        writer.Write((byte) Type.TileStroke);
        writer.Write(tile);
        PackBits(writer,
                 5, sx,
                 5, sy,
                 5, ex,
                 5, ey,
                 4, index,
                 4, (uint) size);

        return writer.ToArray();
    }
开发者ID:Ragzouken,项目名称:smooltool,代码行数:28,代码来源:Test.cs

示例9: AddPlayer

 public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId, MessageBase extraMessage)
 {
     PlayerController controller;
     if (playerControllerId < 0)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is negative");
         }
         return false;
     }
     if (playerControllerId > 0x20)
     {
         if (LogFilter.logError)
         {
             Debug.LogError(string.Concat(new object[] { "ClientScene::AddPlayer: playerControllerId of ", playerControllerId, " is too high, max is ", 0x20 }));
         }
         return false;
     }
     if ((playerControllerId > 0x10) && LogFilter.logWarn)
     {
         Debug.LogWarning("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is unusually high");
     }
     while (playerControllerId >= s_LocalPlayers.Count)
     {
         s_LocalPlayers.Add(new PlayerController());
     }
     if (readyConn == null)
     {
         if (!s_IsReady)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("Must call AddPlayer() with a connection the first time to become ready.");
             }
             return false;
         }
     }
     else
     {
         s_IsReady = true;
         s_ReadyConnection = readyConn;
     }
     if ((s_ReadyConnection.GetPlayerController(playerControllerId, out controller) && controller.IsValid) && (controller.gameObject != null))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " already in use.");
         }
         return false;
     }
     if (LogFilter.logDebug)
     {
         Debug.Log(string.Concat(new object[] { "ClientScene::AddPlayer() for ID ", playerControllerId, " called with connection [", s_ReadyConnection, "]" }));
     }
     AddPlayerMessage msg = new AddPlayerMessage {
         playerControllerId = playerControllerId
     };
     if (extraMessage != null)
     {
         NetworkWriter writer = new NetworkWriter();
         extraMessage.Serialize(writer);
         msg.msgData = writer.ToArray();
         msg.msgSize = writer.Position;
     }
     s_ReadyConnection.Send(0x25, msg);
     return true;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:68,代码来源:ClientScene.cs

示例10: SendMessage

 private bool SendMessage(NetworkWriter writer, int channelId, out NetworkError error)
 {
     error = NetworkError.WrongConnection;
     if (!isConnected)
     {
         Debug.LogWarning("LLApiClient is not Connected");
         return false;
     }
     byte errorByte;
     byte[] buffer = writer.ToArray();
     NetworkTransport.Send(SocketId, ConnectionId, channelId, buffer, buffer.Length, out errorByte);
     error = (NetworkError)errorByte;
     if(error!= NetworkError.Ok)
     {
         Debug.LogError("LLApiClient Sock: " + SocketId + " ConId: " + ConnectionId + " Error Sending Message : " + error);
         return false;
     }
     return true;
 }
开发者ID:ChaseHuegel,项目名称:LLApi-Basic-Implementation,代码行数:19,代码来源:LLApiClient.cs


注:本文中的UnityEngine.Networking.NetworkWriter.ToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。