错误1:未实现接口成员

时间:2015-03-22 09:39:18

标签: c# photon

我正在创建一个基于光子的多人服务器使用CRJ游戏教程我遇到了这个错误,一直试图修复它超过2个小时,重复教程几次,我完全迷失了。

Erorr:

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);
        }

    }
}

1 个答案:

答案 0 :(得分:0)

错误消息为您提供了您需要了解的所有信息。

PhotonServerHandler是一个实现接口IHandler

的抽象类

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

以下是一个可以解决错误原因的可靠示例

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

public abstract class B : A
{
    DoThingOne()
}

上述情况会引发错误。

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

应该从界面实现所有必要的方法。