【问题标题】:RaiseEvent seems to not execute properlyRaiseEvent 似乎没有正确执行
【发布时间】:2020-07-18 16:14:42
【问题描述】:

光子网络新手 我正在为我的棋盘游戏使用 raise 事件。有时事件不会触发,但大多数时候它们工作正常需要帮助。

private void OnEnable() {
      
   PhotonNetwork.NetworkingClient.EventReceived += NetworkingClient_EventReceived;

 }

private void Disable()
    {
      
       PhotonNetwork.NetworkingClient.EventReceived -= NetworkingClient_EventReceived;
    }

 private void NetworkingClient_EventReceived(EventData obj)
    {
 
        byte eventCode = obj.Code;

        if (eventCode == (byte)EnumGame.DiceRoll)
        {

            EventManager.instance.rolldiceEvent(obj);
        }

        if (eventCode == (byte)EnumGame.DiceNumber)
        {

            EventManager.instance.displaydiceNumber(obj);
        }

        if (eventCode == (byte)EnumGame.Passdice)
        {

            EventManager.instance.passdicetootherPlayer(obj);


        }


        if (eventCode == (byte)EnumGame.PassTurn)
        {

            EventManager.instance.passturntootherPlayer(obj);
        

        }

    }

这就是我在脚本中用来引发事件的方式,我没有收到任何异常:

    object[] data = new object[] { Photonplayer.instance.getplayerId() };
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others };
        PhotonNetwork.RaiseEvent((byte)EnumGame.Passdice, data, raiseEventOptions, SendOptions.SendUnreliable);

【问题讨论】:

    标签: c# unity3d photon


    【解决方案1】:
     object[] data = new object[] { Photonplayer.instance.getplayerId() };
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.Others };
        PhotonNetwork.RaiseEvent((byte)EnumGame.Passdice, data, raiseEventOptions, SendOptions.SendReliable);
    

    在 RaiseEvent 的第 4 个参数中将“SendOptions.SendUnreliable”更改为“SendOptions.SendReliable”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多