出品概述www.27111.com

 

Product Overview 产品概述

 

     On the client-side, Photon supports various platforms. Even though
programming in C, C# and Flash is very different, the basic workflow
stays similar. In this online documentation we try to explain the
concepts and background, while language specifics are left to the
reference documentation per platform.

   
 在客户端,Photon帮助多元的阳台,使用C,C#,Flash举行编程的点子是例外的,不过基本的工作流是一般的。在那文书档案中大家品尝去解释它的概念和背景,而语言的细节部分要求查阅各种语言平台的参阅文书档案。

 

     Each Photon Client SDK comes with a fitting reference documentation
for its platform and language.

     每1个客户端SDk都富含相关平台的参考文书档案。

     Project Setup 项目设置

 

     You need to include a single library to communicate with Photon on
the client-side. This is a different setup per platform.

     在客户端你需求包蕴叁个单独的library ,各种平台的设置是差异的。

  • DotNet

     Add a reference to the PhotonDotNet.dll in your DotNet project to
make its classes known. Import the lib’s namespace with: using
ExitGames.Client.Photon;

     在项目中援引PhotonDotNet.dll,引用命名空间using
Exit加梅斯.Client.Photon

  • Unity3d

     You need to import the PhotonUnity3D.dll into your project in
Unity. Simply open a Unity project/scene, open an explorer and drag and
drop the .dll from <sdk>\libs\debug\ into the editor. Again,
import the lib’s namespace with: using ExitGames.Client.Photon;

   
 你须求导入PhotonUnity3D.dll到品种中,打开Unity 的project/scene,打开财富管理器从<sdk>\libs\debug\ 拖放PhotonUnity3D.dll到editor,导入命名空间using
Exit加梅斯.Client.Photon;

 

     Workflow 工作流

 

     The simplified lifecycle for any multiplayer game looks like this:

     多个人游玩的简化生命周期如下:

 

  • Connect to server

          连接服务器

  • Make RPC calls

          RPC调用

  • Receive something

          接收数据

  • Disconnect

          断开连接

 

     Pretty simple. Let’s have a look at each step, assuming you use C#
and the Lite
Application
 .

     很简短,让大家来探望每二个手续,以Lite为例。

 

  • Connect to server 连接服务器

 

     Actually, you do a little more than just connect in this step. In
short:

     事实上,你做的不只是连接而已:

 

  • Implement the interface IPhotonPeerListener in one of your
    classes

          在你的类中贯彻接口IPhotonPeerListener

  • Create a LitePeer instance with your server’s address

          创制LitePeer 实例和您服务器的地址

  • In your game loop, call Service about 10 times a second

          在你的游玩循环中山大学约10秒调用3次服务

  • Now call Connect to establish the connection. The application
    name should match one in the PhotonServer.config

          未来树立连接,这应用程序的名字要与PhotonServer.config中的匹配

  • Your implementation if PeerStatusCallback is called when the
    connection is ready or failed

          你要贯彻的是当连接是未连接的时候调用PeerStatusCallback 

  • The returned status be StatusCode.Connect

          再次回到的情形是StatusCode.Connect

 

     The peer instance provides you with some methods to talk to Photon.
It does not have its own thread. It updates when you
call Service instead. This will keep the connection alive

   
 peer 实例提供了一些措施去拜访Photon,它从未团结的线程,当你调用服务时它实行立异,并保险着连连

 

     We assume that Photon is running the “Lite” Application, which it
does by default.

     大家如若Photon运维着Lite,以下是默许意况。

 

  • Make RPC calls RPC调用

 

     After connecting, the client can call methods in the Lite
Application just about anytime it needs to. The methods available as
“remote procedure call” are called operations.

   
 连接后,客户端能够再任何时候去调用Lite应用的措施,那样的远程进度调用被喻为操作

 

     Operation calls are asynchronous and won’t block your game. They
are queued internally until you intently send something by
calling SendOutgoingCommands. There will be a short delay until the
result is received. These results are defined per operation and are not
used at all sometimes.

   
 操作调用是异步的,并且不会阻拦你的娱乐。他们是在个中排队的直到你要求发送他们的时候经过SendOutgoingCommands出殡。收到结果只须求极短暂的延迟时间,这一个结果是被定义为操作并且不是有着的岁月都被选择的。

 

  • Call OpJoin with any room name to get into a game

          调用OpJoin 能够投入游戏

  • Wait for the
    callback: OperationResult with opCodeLiteOpCode.Join

         
等待回调带有 opCodeLiteOpCode.Join 的 OperationResult 

  • Send any hashtable with content by calling OpRaiseEvent. Other
    players in the room will receive events.

         
通过调用OpRaiseEvent发送带有内容的hashtable ,其余这几个房间的玩家也将收到有关的风浪音信。

 

     Joining a room and raising events in it is provided (server side)
by the Lite Application logic we use in this sample. You can use other
applications and implement your own operations.

   
 那是二个根据Lite应用的逻辑加入房间并触及事件的例证,你能够应用其它的利用还要达成您本身的操作

 

  • Receive something 接收数据

 

     In the previous step you already received an operation result. We
differentiate those from other incoming messages, so called events. Lite
will forward the event you raised to others in a room.

   
 在头里的步子,你早已收到到了操作的结果,小编有别于来自其余地点的新闻,所以称为事件,Lite将发送那事件触发到房间中的其余人。

 

     Receiving events will call IPhotonPeerListener.EventAction.
The evCode will match the one you used in OpRaiseEvent

   
 调用IPhotonPeerListener.EventAction接到事件,evCode 将与您使用的OpRaiseEvent进展匹配

 

     The client library will internally queue received packages, so your
game decides when to use them. EventAction is called by your calls
to PhotonPeer.Service.

   
 这客户端将接收到的多寡包进行之中排队,由你的游玩操纵曾几何时使用它们,通过调用PhotonPeer.Service来调用EventAction 

 

  • Disconnect 断开连接

 

     When a client is closed, the best is to disconnect. That’s nice,
but not a must-have as a timeout will disconnect clients that don’t
answer anymore.

     当客户端是倒闭的时候,最好是断开连接,但不是作为超时断开。

 

  • To close the connection: call Disconnect

          关闭连接:调用Disconnect

  • Check “disconnect” return
    in PeerStatusCallback with statusCodeStatusCode.Disconnect

         
检查 “disconnect” ,PeerStatusCallback 的重返值为statusCodeStatusCode.Disconnect

  • Now the client can stop calling service

          以往客户端能够告一段落调用服务了

     LitePeer versus PhotonPeer LitePeer与PhotonPeer 

 

     Aside from the LitePeer, the client libraries also include a
PhotonPeer which could be used. The PhotonPeer has the bare minimum of
API needed for Photon. It is the base for LitePeer, which adds
operations like “Join”, “Leave” and “RaiseEvent”, which are available
with the Lite Application.

   
 除了LitePeer,客户端还蕴涵了四个PhotonPeer 可以行使,PhotonPeer 对于Photon唯有少数的API,它是LitePeer的底蕴,Lite中LitePeer扩大了“Join”、“Leave”
、“Raise伊芙nt”等。

     Reliable UDP 可靠的UDP

 

     Under the hood, Photon clients and servers send operations and
events via UDP. This guarantees low overhead, flexibility and
performance but is unreliable by definition.

   
 在尾部,Photon客户端和服务器通过UDP发送操作和事件的,那保险了低成本、灵活性和总体性可是被定义为不可信赖的。

 

     Within the UDP packages, Photon uses a thin binary protocol to
enable aggregation, ordering, detection of packet loss and more. It is
based on eNet and used in similar form on client and server.

   
 在UDP包中,Photon 使用了一个精简的二进制协议来实行联谊、排序、检测数据包不见,它是基于eNet的被用来服务器和客户端

 

     So called “commands” are used to transfer the payload, such as
operations. On the client side, Photon gives you full control of when
commands are put into a UDP package and send.

   
 所谓的“commands”是用以传递那负载的,例如操作。在客户端,由Photon控制命令以UDP包的款式开始展览发送

 

     As a result, the API also includes methods that manage the
connection to the server. Basically, there are two “layers”: the
“command layer” and the “operation layer”:

   
 因而,API还包含管理总是服务器的艺术,基本上,他们是由八个层组成:“command
layer” 和 “operation layer”

  • Command layer: manages the communication protocol to establish
    and maintain communication.

          命令层:管理通讯协议建立连接并保障通讯

  • Operation layer: gives access to rooms, events and custom
    Operations. Client side, methods of this layer are prefixed with
    “Op”.

         
操作层:用于访问房间、事件、自定义操作。在客户端,那层的章程被添加了前缀 “Op”

     Reliable vs. Unreliable 可信对不可信

 

     With Photon’s underlying protocol, everything that’s sent across
can be made flagged as reliable or unreliable. The operation request is
not changed by this though, only the command that’s used.

   
 Photon的底层协议,能够被标记为有限支撑或不可靠,仅仅在命令被选拔的时候操作请求是不可改变的。

 

www.27111.com,     Photon keeps track of the ordering. Even unreliable commands are
synchronized/sequenced within the order of reliable commands. So an
unreliable command, which was sent after a certain reliable command,
will also be dispatched after the reliable command was dispatched (even
if that command was delayed).

   
 Photon 保持跟踪,不可靠的一声令下是随着保证的下令举行协同测序,所以1个不可靠的命令,被发送在一个可信赖的通令之后,也将在保障命令被分摊之后再举办分摊。

 

     Operations and events that are sent as unreliable might get lost.
As example, this is no problem for position updates, which are quickly
replaced. On the server side, Operations that are received unreliable,
should not create a result: The client can not expect that the operation
even reached the server.

   
 操作和事件发送是不容许丢掉的,举例,对于地点的换代那符合规律,更新不慢就被沟通了,在服务端,接收到的不可靠的操作不会创建这样四个结实:客户端不会期待那操作到达服务器。

     Connection and Timeout 连接与超时

 

     The client has two rules to define a timeout:

     那客户端有三种规则去定义超时:

 

  • Retries: A reliable command is sent multiple times to be
    acknowledged, each time the interval between retries gets longer,
    depending on general rountrip times. If the number of retries
    reaches a limit (in DotNet: SentCountAllowance), this causes a
    disconnect.

         
重试:二个保险的吩咐将会被发送数十次以作为确认,每一趟重试的日子间隔变长,依据统一的区域时间概念,就算重试次数高达3个极限,将会断开连接。

  • DisconnectTimeout: This defines a maximum number of
    milliseconds, before a reliable command must be answered. This is
    independent of the retry counting. In DotNet, the setting
    is: DisconnectTimeout.

         
断开超时:那定义了多少个保证命令必须答应的时间间隔的最大皮秒值,那是独自于重试计数的,在DotNet中安装为DisconnectTimeout

 

     The settings are described in more detail in the client API
documentation.

     这详细的音信请阅读客户端文书档案。

     

发表评论

电子邮件地址不会被公开。 必填项已用*标注