---------------------------------------李明阳---2016/5/29---------ExitGames-Photon-Server-SDK_v3-4-31-10808------------------------
创建C#项目类库
Application主类
Application.cs
Application类继承ApplicationBase
public class MyApplication : ApplicationBase
实现ApplicationBase接口
为Application增加日志输出功能
//日志输出(调用log.Debug("");)
private static readonly ILogger log = ExitGames.Logging.LogManager.GetCurrentClassLogger();
#region ApplicationBase
//创建和客户端通信的Peer类
protected override PeerBase CreatePeer(InitRequest initRequest)
{
return new ClientPeer(initRequest.Protocol, initRequest.PhotonPeer);
}
//为Photon增加日志输出用来查看服务端的运行状况
protected override void Setup()
{
ExitGames.Logging.LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath, "log");
GlobalContext.Properties["LogFileName"] = "My" + this.ApplicationName;
XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(this.BinaryPath, "log4net.config")));
log.Debug("Application setup complete.");
}
//当PhotonSerer停止时调用
protected override void TearDown()
{
log.Debug("Application tear down.");
}
#endregion
处理客户端请求类
ClientPeer.cs
继承自PeerBase
public class ClientPeer : PeerBase
Peer构造函数
public ClientPeer(IRpcProtocol protocol, IPhotonPeer peer)
: base(protocol, peer)
{
}
为ClientPeer增加日志输出功能
//日志输出(调用log.Debug("");)
private static readonly ILogger log = ExitGames.Logging.LogManager.GetCurrentClassLogger();
实现PeerBase接口
#region PeerBase
protected override void OnDisconnect(PhotonHostRuntimeInterfaces.DisconnectReason reasonCode, string reasonDetail)
{
}
//处理客户端传递来的消息,同时客户端返回消息(SendOperationResponse(response, sendParameters);)
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
OperationResponse response = new OperationResponse();
response.OperationCode = operationRequest.OperationCode;
response.Parameters = new Dictionary<byte, object>();
SendOperationResponse(response, sendParameters);
log.Debug("operation code : " + operationRequest.OperationCode);
}
#endregion
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------//
//-------------------------------以上内容完成Unity3D客户端和PhotonServer的通信框架-----------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------//