1:实现IPhotonPeerListener接口用来接收消息。
接口中有如下4个方法:
摘要:当photon服务器派发事件到客户端时被调用。
void OnEvent(EventData eventData);
摘要:Callback method which gives you (async) responses for called operations.
void OnOperationResponse(OperationResponse operationResponse);
摘要: OnStatusChanged is called to let the game know when asyncronous actions finished or when errors happen.
publicvoidOnStatusChanged(StatusCode statusCode)
2.Main Part:
创建一个listener实例 :var listener = new Program();
创建一个photonPeer实例 :var peer = new PhotonPeer(listener, ConnectionProtocol.Udp);
连接photon服务器peer.Connect("localhost:5055","Lite");
调用peer.Service();触发网络传输,派发消息。
3.Operations :通过请求(request)和响应(response)调用远程程序,它是我们的术语远程调用。
就是在服务器端实现的方法在客户端被调用。operations是运行在服务器端的应用程序。
Events :发送到客户端的消息和通知。和operation不同的是,events来自外部,服务器或者是其他客户端。
客户端通过OnEvent回调函数响应。例如有玩家加入房间,该玩家会发送一个请求使用OpCustom方法来调用operation,并且使用一个Dictionary来传递参数。

本文介绍了Photon客户端API的使用,包括实现IPhotonPeerListener接口以接收消息,如OnEvent用于处理服务器事件,OnOperationResponse处理操作响应,以及OnStatusChanged通知异步动作状态。主要内容包括创建监听器和 PhotonPeer 实例,连接到服务器,以及运用Operations进行远程调用和Events进行消息传递。当接收到StatusCode.Connect时,通过OpCustom方法调用操作并传递参数。
最低0.47元/天 解锁文章
2175

被折叠的 条评论
为什么被折叠?



