这是我在这里的第一个问题,所以如果它不能真正与一些更高级的问题相提并论,请原谅。我主要是一名 Java 开发人员,但我最近开始转向 C#,并且我决定选择 Photon Networking Library,以便开始在我使用 Unity3D 创建的游戏中实现它作为业余爱好。
我收到的错误如下:
Error 1 'MMO.Photon.Server.PhotonServerHandler' does not implement interface member 'MMO.Framework.IHandler.HandleMeessage(MMO.Framework.IMessage, MMO.Photon.Server.PhotonServerPeer)' c:\users\boyz\documents\visual studio 2012\Projects\MMO.Framework\MMO.PhotonFramework\Server\PhotonServerHandler.cs 11 27 MMO.Photon
我不太明白,据我所知,它正在实现接口(interface),但我并不完全理解它是如何工作的。所以我将只向您展示这里有问题的类。
PhotonServerHandler 是错误派生的类(或者看起来如此)
namespace MMO.Photon.Server
{
public abstract class PhotonServerHandler : IHandler<PhotonServerPeer>
{
public abstract MessageType Type { get; }
public abstract byte Code { get; }
public abstract int? SubCode { get; }
protected PhotonApplication Server;
public PhotonServerHandler(PhotonApplication application)
{
this.Server = application;
}
public bool HandleMessage(IMessage message, PhotonServerPeer serverPeer)
{
OnHandleMessage(message, serverPeer);
return true;
}
protected abstract bool OnHandleMessage(IMessage message, PhotonServerPeer serverPeer);
}
}
然后是它导入或继承的 IHandler;不管你用 C# 怎么说。
namespace MMO.Framework
{
public interface IHandler<T>
{
MessageType Type { get; }
byte Code { get; }
int? SubCode { get; }
bool HandleMeessage(IMessage message, T peer);
}
}
最后但同样重要的是,我们有 PhotonServerPeer 类
namespace MMO.Photon.Server
{
public class PhotonServerPeer : ServerPeerBase
{
private readonly PhotonServerHandlerList handlerList;
protected readonly PhotonApplication Server;
#region Factory Method
public delegate PhotonServerPeer Factory(IRpcProtocol protocol, IPhotonPeer photonPeer);
#endregion
public PhotonServerPeer(IRpcProtocol protocol, IPhotonPeer photonPeer, PhotonServerHandlerList handlerList, PhotonApplication application) : base(protocol, photonPeer)
{
this.handlerList = handlerList;
this.Server = application;
}
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
handlerList.HandleMessage(new PhotonRequest(operationRequest.OperationCode, operationRequest.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(operationRequest.Parameters[Server.SubCodeParameterKey]) : null, operationRequest.Parameters), this);
}
protected override void OnEvent(IEventData eventData, SendParameters sendParameters)
{
handlerList.HandleMessage(new PhotonEvent(eventData.Code, eventData.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(eventData.Parameters[Server.SubCodeParameterKey]) : null, eventData.Parameters), this);
}
protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
{
handlerList.HandleMessage(new PhotonResponse(operationResponse.OperationCode, operationResponse.Parameters.ContainsKey(Server.SubCodeParameterKey) ? (int?)Convert.ToInt32(operationResponse.Parameters[Server.SubCodeParameterKey]) : null, operationResponse.Parameters, operationResponse.DebugMessage, operationResponse.ReturnCode), this);
}
protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
{
//Server.ConnectionCollection.OnDisconnect(this);
}
}
}
我根本不明白这个错误,它已经困扰我几个小时了,我已经尝试了所有我知道的方法,我一直在谷歌搜索,这可能只是一个非常基本的错误,我错过了,但任何帮助将不胜感激。
请您参考如下方法:
您当前在 PhotonServerHandler 中获得了 public bool HandleMessage,但错误是提示 PhotonServerHandler 没有实现 HandleMeessage 。
看起来你这里有一个错字:
public interface IHandler<T>
{
MessageType Type { get; }
byte Code { get; }
int? SubCode { get; }
bool HandleMeessage(IMessage message, T peer);
}
将 HandleMeessage 重命名为 HandleMessage 并且该特定错误应该消失。
