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


C# NetworkWriter.SeekZero方法代码示例

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


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

示例1: Update


//.........这里部分代码省略.........

                foreach (var vessel in ServerVessel.Vessels) {
                    vessel.Update(nw);
                }

                NetworkEventType recData;
                while (true) {
                    recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, recBuffer.Length, out dataSize, out error);
                    if(error != 0)
                    {
                        Debug.Log ((NetworkError)error + " " + dataSize + " ");
                        Shutdown();
                        return;
                    } else if (recData == NetworkEventType.Nothing) {
                        break;
                    } else {
                        switch(recData) {
                        case NetworkEventType.ConnectEvent:
                        {
                            Debug.Log("Client connecting");
                            //start this player off from the beginning
                            StartingVessel startVessel = StartingVessel.GetStartingVessel();
                            GameObject playerGO = GameObject.Instantiate(playerPrefab) as GameObject;
                            ServerPlayer player = playerGO.AddComponent<ServerPlayer>();
                            serverPlayers.Add(recHostId, player);
                            player.hostId = recHostId;
                            startVessel.AddPlayer(player, nw);

                            break;
                        }
                        case NetworkEventType.DataEvent:  //if server will receive echo it will send it back to client, when client will receive echo from serve wit will send other message
                        {
                            ServerPlayer player;
                            try {
                                player = serverPlayers[recHostId];
                            } catch (System.Exception ex) {
                                //							string pairs = "";
                                //							foreach (KeyValuePair<int, ServerPlayer> kvp in serverPlayers)
                                //							{
                                //								//textBox3.Text += ("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
                                //								pairs += string.Format("Key = {0}, Value = {1}", kvp.Key.ToString(), kvp.Value.ToString()) + "\n";
                                //							}
                                //							Debug.LogError("Failed to get ServerPlayer with hostId: " + recHostId.ToString() + "\n" + pairs);
                                break;
                            }

                            Debug.Log ("Client message received");

                            nr.SeekZero();
                            nw.SeekZero();
                            while (nr.Position != dataSize) {
                                switch ((ClientMessageType)nr.ReadUInt16()) {
                                case ClientMessageType.RequestChunk:
                                    Debug.Log ("ClientMessageType.RequestChunk");
                                    player.currentVessel.HandleChunkRequestMessage(nr, nw);
                                    break;
                                case ClientMessageType.Inputs:
                                    Debug.Log ("ClientMessageType.Inputs");
                                    player.ReadInputsMessage(nr);
                                    break;
                                case ClientMessageType.FillAt:
                                    Debug.Log ("ClientMessageType.FillAt");
                                    player.currentVessel.HandleFillAtMessage(nr);
                                    break;
                                default:
                                    break;
                                }
                            }

                            if (nw.Position != 0) {
                                Debug.Log("Sending response: " + recHostId + "," + connectionId + "," + channelId + "," + nw.AsArray() + "," + nw.Position + ".");
                                NetworkTransport.Send(recHostId, connectionId, channelId, nw.AsArray(), nw.Position, out error);
                            }
                            if(error != 0)
                            {
                                Debug.Log ((NetworkError)error);
                                Shutdown();
                                return;
                            }
                            break;
                        }
                        case NetworkEventType.DisconnectEvent:
                        {
                            Debug.Log("Client disconnecting");
                            ServerPlayer player = serverPlayers[recHostId];
                            player.currentVessel.RemovePlayer(player, nw);
                            serverPlayers.Remove(recHostId);
                            break;
                        }
                        default:
                            break;
                        }
                    }
                }
            } catch (System.Exception ex) {
                //Debug.Log(ex.StackTrace);
                Shutdown ();
            }
        }
    }
开发者ID:NickPowers43,项目名称:SW,代码行数:101,代码来源:GameManager.cs

示例2: RemovePlayer

    public void RemovePlayer(ServerPlayer player, NetworkWriter nw)
    {
        int id = playersOnBoard.IndexOf(player);
        playersOnBoard.RemoveAt(id);
        player.currentVessel = null;
        if (playersOnBoard.Count == 0) {
            noPlayers = true;
        }

        if (GameManager.Instance.Initialized) {
            nw.SeekZero();
            nw.Write((ushort)ServerMessageType.RemovePlayer);
            nw.Write((ushort)id);
            for (int i = 0; i < playersOnBoard.Count; i++) {
                //send
            }
        }
    }
开发者ID:NickPowers43,项目名称:SW,代码行数:18,代码来源:ServerVessel.cs

示例3: WriteSyncVessel

 public void WriteSyncVessel(NetworkWriter nw)
 {
     nw.SeekZero();
     nw.Write((ushort)ServerMessageType.SyncVessel);
     nw.Write(Index);
     nw.Write(interiorPosition);
 }
开发者ID:NickPowers43,项目名称:SW,代码行数:7,代码来源:ServerVessel.cs

示例4: AddPlayer

    public void AddPlayer(ServerPlayer player, Vector2 position, NetworkWriter nw)
    {
        if (!interiorExists) {
            AllocateInteriorSpace();
        }

        player.transform.position = (Vector3)(interiorPosition + position);

        player.currentVessel = this;
        playersOnBoard.Add(player);
        player.ChunkI = WorldToChunkI((Vector2)player.transform.position);
        InstantiateNearbyChunks(player);

        noPlayers = false;
        timeEmpty = 0.0f;

        if (GameManager.Instance.Initialized) {
            WriteSyncVessel(nw);
            //send
        }
        if (GameManager.Instance.Initialized) {
            nw.SeekZero();
            nw.Write((ushort)ServerMessageType.AddPlayer);
            nw.Write((ushort)(playersOnBoard.Count - 1));
            nw.Write((Vector2)player.transform.position);
            //TODO: write player info here
            for (int i = 0; i < playersOnBoard.Count; i++) {
                //send
            }
        }
    }
开发者ID:NickPowers43,项目名称:SW,代码行数:31,代码来源:ServerVessel.cs


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