zoukankan      html  css  js  c++  java
  • Unity5.1 新的网络引擎UNET(十五) Networking 引用--中

    孙广东 2015.7.21

    本节提供了与网络系统一起使用的组件的具体信息。


    3、NetworkClient

            NetworkClient 是一个 HLAPI 类,管理网络连接到服务器 — — 相应着 UNET NetworkServer。它能够用于将消息发送到服务器和从服务器接收消息。NetworkClient 还能够帮助管理衍生的网络对象和 RPC 消息和网络事件的路由。

    Properties

    Property:Function:
    serverIPThe IP address of the server that this client is connected to.
    serverPortThe port of the server that this client is connected to.
    connectionThe NetworkConnection object this client is using.
    handlersThe set of registered message handler functions.
    numChannelsThe number of configured NetworkTransport QoS channels.
    isConnectedTrue if the client is connected to a server.
    allClientsList of active network clients (static).
    activeTrue if any network clients are active (static).

    4、NetworkConnection

    NetworkConnection是一个 HLAPI 类。封装了网络连接。NetworkClient 对象具有一个NetworkConnections,和 NetworkServers 有多个NetworkConnections------来自每一个客户端。   网络连接已能发送字节数组,或序列化的对象作为 网络消息。

    Properties

    Property:Function:
    hostIdThe NetworkTransport hostId for this connection.
    connectionIdThe NetworkTransport connectionId for this connection.
    isReadyFlag to control whether state updates are sent to this client.
    addressThe IP address of the end-point that this connection is connected to.
    playerControllersThe set of players that have been added with AddPlayer().

    5、NetworkIdentity

              NetworkIdentity 组件是Unity 组件,它是 新网络系统的核心 。

    它能够被加入到对象。

    从-AddComponents->Network->NetworkIdentity 菜单项 。此组件控制对象的网络标识。这表明 NetworkIdentity 组件在一个对象上例如以下所看到的:


    与Unity Network System的 服务器权威系统,网络的对象的NetworkIdentities 必须是由服务器使用 NetworkServer.Spawn()所  “spawned” 。这会导致他们被分配NetworkInstanceId。在连接到服务器的客户端上创建。


            场景物体比动态实例化对象有点差别对待。

    这些对象是全部  出如今客户端和服务器上的场景中。然而。当建设游戏 的全部场景对象的identities 将被都禁用。

    当客户端连接到服务器时,服务器将通知客户端应启用哪些场景对象 和其最新的状态信息是通过 spawn 消息。这可确保客户端将不会包括对象放置在如今不对的位置。当他開始playing。或 甚至对象会马上被删除连接由于一些事件中移除他们之前客户端连接。

    "ServerOnly"  复选框将确保这某一特定对象不会催生了或在客户端上启用。


            此组件包括像什么场景 ID,网络 ID 和 资产 ID 已分配给对象的跟踪信息。场景 ID 是一个在 NetworkIdentity 组件的全部场景物体中有效。网络 ID 是此特定对象实例的 ID,可能有多个对象的特定对象类型的实例化和  网络 ID 用于的标识的对象,比如,网络更新应适用。资产 ID 是指什么源资产对象被实例化。

    这是内部使用。当特定对象预置被网络spawned 。

    此信息被公开的预览面板底部的Inspector:


         在执行时是要在此处显示的具体信息 (disabled  NetworkBehaviour 显示 非粗体):

    Properties

    Property:Function:
    netIdA unique identifier for this network session, assigned when spawned.
    sceneIdA unique identifier for networked objects in a scene. This is only populated in play-mode.
    isClientTrue if this object is running on a client.
    isServerTrue if this object is running on the server, and has been spawned.
    hasAuthorityTrue if this object is the authoritative version of the object. So either on a the server, or on the client with localPlayerAuthority.
    localPlayerAuthorityTrue if this object is controlled by the client that owns it - the local player object on that client has authority over it. This is used by other components such as NetworkTransform.
    serverOnlyA flag to make this object not be spawned on clients.
    assetIdThis identifies the prefab associated with this object (for spawning).
    playerControllerIdThe identifier of the controller associated with this object. Only valid for player objects.
    observersThe list of client NetworkConnections that are able to see this object. This is read-only.

    Hints

    • Put a NetworkIdentity component on prefabs that will be spawned.
    • A NetworkIdentity is required for every object that is networked.


    6、Network Lobby Manager

    NetworkLobbyManager 是一种特殊的网络管理器。主要玩游戏进入主场景之前的提供一个多层的大堂。

    • 提供网络大厅的player限制
    • 游戏開始时全部玩家都是准备好了
    • 玩家不能加入game-in-progress
    • 支持“Couch Multiplayer”
    • 可自己定义的方式为玩家选择在大厅中的选项

    有两种类型的球员与 NetworkLobbyManager 的对象:
    LobbyPlayer 对象
    • 对于每一个玩家
    • 创建客户端连接,或player被加入时
    • 持续,直到客户端断开连接
    • 拥有准备flag和配置数据
    • 处理在大厅里的命令
    • 应该使用 NetworkLobbyPlayer 组件

    GamePlayer 对象
    • 对于每一个玩家
    • 開始游戏场景时被创建
    • 又一次进入大厅时被摧毁
    • 处理在游戏中命令

    Properties

    Property:Function:
    showLobbyGUIShow the legacy OnGUI controls for the lobby.
    maxPlayersThe maximum number of players allowed in the lobby.
    maxPlayersPerConnectionThe maximum number of players allowed to be added for each client connection.
    lobbyPlayerPrefabThe prefab to create for players when they enter the lobby.
    gamePlayerPrefabThe prefab to create for players when the game starts.
    lobbySceneThe scene to use for the lobby.
    playSceneThe scene to use for main game play.

    Details

    •  LobbyPlayerPrefab 插槽应填写。一个对象的 NetworkLobbyPlayer 组件。
    •  有一个lobby manager GUI。看到多人游戏大厅资产包。


    7、Network Lobby Player

    NetworkLobbyPlayer 是 NetworkLobbyManager 用于存储在大厅中的每一个球员状态。

    Properties

    Property:Function:
    ShowLobbyGUITrue to show the legacy user interface for players in the lobby.
    slotThe slot that this player was allocated too. Only one player can be in each lobby slot.
    readyToBeginFlag to control if the player is ready for the game to start.

    8、Network Manager UNet


    网络 管理器是一个更高的水平类  使您能够控制一个网络游戏的状态 。

    它提供了界面编辑器用于 ,和场景。以用于不同的网络游戏状态的预置控制网络的配置中。

    Properties

    Property:Function:
    networkPortThe network port used to listen on and connect to.
    networkAddressThe network address to connect to.
    dontDestroyOnLoadFlag to make the NetworkManager persist between scenes.
    runInBackgroundFlag to make the player run in the background by default.
    sendPeerInfoFlag to have network information on all peers sent to all participating clients.
    maxDelayThe maximum time in seconds to delay buffered messages.
    logLevelThe level of network logging to write.
    playerPrefabThe prefab to instantiate for players when a client connects.
    autoCreatePlayerFlag to automatically add a player when a client connects.
    playerSpawnMethodHow to spawn players at StartPositions.
    offlineSceneThe scene to switch to when the network goes off-line.
    onlineSceneThe scene to switch to when the network goes on-line.
    spawnPrefabsThe set of registered spawnable prefabs.
    startPositionsThe set of NetworkStartPosition objects found in the scene.
    customConfigFlag to use custom network configuration (advanced).
    connectionConfigAdvanced custom network configuration data.
    maxConnectionsThe maximum number of connections allowed by the server.
    channelsThe number of transport layer QoS Channels.
    secureTunnelEndpointEnd point for XBox Live connectivity.
    useSimulatorFlag to use network conditions simulation.
    simulatedLatencyLatency in milliseconds to add when network simulator active.
    packetLossPercentageThe percentage of packet loss to add when network simulator active
    matchHostMatchmaker host address.
    matchPortMatchmaker host port.


    9、Network Manager HUD


    控制游戏的网络状态提供了默认的用户界面。它还在编辑器中显示有关网络管理器的当前状态信息。

    Properties

    Property:Function:
    showGUIFlag to show the default UI.
    offsetXThe horizontal pixel offset of the UI.
    offsetYThe vertical pixel offset of the UI..

    Details

    NetworkManagerHUD 同意您查看在编辑器中,比如connections,非常多细节 列出 已知的网络的对象,和激活 玩家对象。





















    
    
  • 相关阅读:
    【转】最奇特的编程语言特征
    【原】mysql 视图
    自己动手写ORM框架(一):目标效果预览
    (二)Javascript面向对象:命名空间
    在JAVA中封装JSONUtils工具类及使用(一)
    .NET3.5中JSON用法以及封装JsonUtils工具类(二)
    (四)Javascript面向对象:继承
    自己动手写ORM框架(三):关系映射配置—Table属性
    (一)javascript面向对象:(2)类
    自己动手写ORM框架(二):AdoHelper支持多数据库操作的封装(1)
  • 原文地址:https://www.cnblogs.com/yfceshi/p/7116842.html
Copyright © 2011-2022 走看看