错误一:没有实现接口成员

Error 1: does not implement interface member

我正在使用 CRJ 游戏教程创建一个基于 photon 的多人游戏服务器,我 运行 遇到了这个错误,已经尝试修复它超过 2 个小时,重新看了几次教程,我完全迷路了。

错误:

Error   1   'FPS.Photon.Server.PhotonServerHandler' does not implement interface member 'FPS.Framework.IHandler<FPS.Photon.Server.PhotonServerPeer>.HandleMessage(FPS.Framework.IMessage, FPS.Photon.Server.PhotonServerPeer)'  C:\Users\Blagovest\documents\visual studio 2013\Projects\FPS\FPS.Photon\Server\PhotonServerHandler.cs   12  27  FPS.Photon

PhotonServerHandler

using ExitGames.Logging;
using FPS.Framework;
using FPS.Photon.Application;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FPS.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;
        protected ILogger Log = LogManager.GetCurrentClassLogger();

        public PhotonServerHandler(PhotonApplication application)
        {
            Server = application;
        }

        public bool HandleMessge(IMessage message, PhotonServerPeer serverPeer)
        {
            OnHandleMessage(message, serverPeer);
            return true;
        }

        protected abstract bool OnHandleMessage(IMessage message, PhotonServerPeer serverPeer);
    }
}

PhotonServerPeer

using FPS.Photon.Application;
using Photon.SocketServer;
using Photon.SocketServer.ServerToServer;
using PhotonHostRuntimeInterfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FPS.Photon.Server
{
    public class PhotonServerPeer : ServerPeerBase
    {
        private readonly PhotonServerHandlerList _handlerList;
        protected readonly PhotonApplication Server;
        public Guid? ServerId { get; set; }
        public string TcpAddress { get; set; }
        public string UdpAddress { get; set; }
        public string ApplicationName { get; set; }
        public int ServerType { get; set; }

        #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)
        {
            _handlerList = handlerList;
            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 是一个实现接口 IHandler

的抽象 class

这意味着在 IHandler 中声明的所有方法都必须在 PhotonServerHandler 中实现。

这是一个很好的例子,说明为什么会出现该错误

public interface A
{
    void DoThingOne();
    void DoThingTwo();
} 

public abstract class B : A
{
    DoThingOne()
}

以上会抛出错误。

如果您使用的是 visual studio,请尝试右键单击界面,然后实施界面。

应该从接口实现所有必要的方法。