networkBehaviour的几种状态

来源:互联网 发布:vscode使用教程 编辑:程序博客网 时间:2024/04/28 21:10

参考文章:

Unity5.1 新的网络引擎UNET(十五) Networking 引用--上



UNET中常用到networkBehaviour的状态判断,项目中使用率最高时isLocalPlayer/isServer/isClient,不过初学时很容易误解意思,特此来理清一下。


Property:Function:isLocalPlayerTrue if this object is the player object for the local client.
当这个玩家物体属于本地客户端的物体时为true。isServerTrue if this object is running on the server, and has been spawned.
当这个物体是被服务器NetworkServer.Spawn()产生出来的,并且本机端是服务器端(也包括主机端),则为true。startHost/startClient默认调用spawn()。isClientTrue if this object is running on a client.
当这个物体运行,并且本机端是客户端(也包括主机端),则为true。hasAuthorityThis returns true if this object is the authoritative version of the object in the distributed network application.So either on the server, or on the client with localPlayerAuthority.
当这个物体在分布式网络应用中是权威版本,则为true(不清楚)。发现基本与isServer状态同步。所以无论服务器或客户端都有本地玩家授权localPlayerAuthority。assetIdThis is the assetId of the object’s NetworkIdentity.
这是物体资源id,多个玩家使用同一个资源时这个属性会一样。netIdThis is the netId of the object’s NetworkIdentity.
这是物体网络id,针对每个玩家发送不同数据时会用到。playerControllerIdThis is the playerControllerId of the object’s NetworkIdentity.
这是物体的玩家控制id,暂不清楚作用。connectionToServerNetworkConnection object to use to send to the server.
用来发送给服务器的NetworkConnection 对象,暂不清楚作用。connectionToClient

NetworkConnection object to use to send to the client.

用来发送给客户端的NetworkConnection 对象,暂不清楚作用。



打开编辑器和一个导出的exe程序同时运行,演示结果如下(一行一个例子)

 
属于编辑器端物体外部程序物体编辑器host,外部client编辑器client,外部host编辑器server,外部client无编辑器client,外部server



0 0
原创粉丝点击