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


C# NetworkReader.SeekZero方法代码示例

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


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


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