Unity 与 Photon服务器的结合使用 - 关于Photo
2016-10-09 本文已影响3024人
ommoonlight
基础概述:
1,Photon服务器是指由ExitGames公司开发的网络服务器。
2,Photon用的Socket框架【应用于CS,魔兽世界等长连接游戏的服务器需求】
3,Photon包含两部分,一部分是Socket服务器另一部分是针对各平台编写的SDK。
4,部署在windows系统。
引擎特点:
1,服务器端部署在windows并且游戏逻辑采用C#语言编写,相对于C++于java服务器,Photon对于unity开发者更友好。
2,采用纤程处理来做为消息处理机制,从而避免了线程中常见的资源竞争等问题。
3,部署极其简单,下载好的服务器安装包内携带了大量封装好的不同平台需要使用到的底层通讯与数据传输模块,只需将其引入自身项目即可快速实现网络连接。
4,采用小尺寸的二进制协议,减少数据传输流量开销,对UDP进行优化,使其成为可靠有序的UDP协议,
5,支持的客户端平台 包括Unity3D,Cocos2D-x,Single Platform平台(安卓,IOS等原生平台)。
下载Poton服务器
【相对其他方案,Server方案没有人数上限限制,功能更全面更灵活】
服务器程序下载地址:
https://www.photonengine.com/zh-TW/OnPremise




当前最新版本为4.0.29,我们使用较为稳定的版本3.4.31


解压后的四个文档概述:
1)doc文件夹用来存放说明文档。
2)deploy文件夹用来存放部署程序与相关配置文件和示例项目【bin文件】。
3)lib文件夹则包含已经编译好的各个平台的与Poton服务器通讯所需sdk文件。
4)Src-server文件夹包含官方提供的示例项目【工程文件】。
打开deploy文件夹,找到与当前系统匹配的部署程序

找到配置文件,获取到服务的监听端口和需要开启的服务名,等下访问时要填写






再次用鼠标滑过菜单栏图标时能看到该部署程序占用内存上升,表明相应服务以经跑起来了。

unity客户端与Photon服务器连接体验




PhotonPeer构造函数重载之一需要实现IPhotonReerListener接口的对象作为参数,PhotonPeer对象会在收到消息后调用实现过IPhotonReerListener接口的对象的接口函数来作为消息传递机制,所以需要制作一个IPhotonReerListener实现类做为消息处理类,这里直接使用本类实现IPhotonReerListener接口,然后将当前类作为参数传递给PhotonPeer的构造函数;



