1

当触发事件时,我们正在使用 ExitGames Photon Realtime 引擎接收此回调

customEventAction(int playerNr, 
                  nByte eventCode,
                  const ExitGames::Common::Object& eventContent)

如果对象是一个字符串,我们使用这段代码来提取它

ExitGames::Common::JString str = 
    ExitGames::Common::ValueObject<ExitGames::Common::JString>(eventContent).getDataCopy(); 

但是,被发送的对象是字典。它是使用 BroadcastEvent 从服务器发送的。

我们如何从中获取数据?

我们已经尝试过了,但它没有任何意义:

ExitGames::Common::Dictionary<byte,ExitGames::Common::Object>  pdic
    = ExitGames::Common::ValueObject<ExitGames::Common::Dictionary<byte,ExitGames::Common::Object>>(eventContent).getDataCopy();

我找到了从哈希表中获取数据的代码,但这也不起作用。

谢谢

肖恩

4

1 回答 1

2
ExitGames::Common::Dictionary<nByte, ExitGames::Common::Object> dic = ExitGames::Common::ValueObject<ExitGames::Common::Dictionary<nByte, ExitGames::Common::Object> >(eventContent).getDataCopy();

是绝对正确的,对我有用。

您的问题的原因必须在另一行内。

当您使用以下代码片段替换 Photon C++ 客户端 SDK 中 demo_loadBalancing 中的 sendEvent() 和 customEventAction() 的实现时,该演示成功发送和接收字典:

发送:

void NetworkLogic::sendEvent(void)
{
    ExitGames::Common::ValueObject<ExitGames::Common::JString> obj(L"test");
    ExitGames::Common::Dictionary<nByte, ExitGames::Common::Object> dic;
    dic.put(1, obj);
    mLoadBalancingClient.opRaiseEvent(false, dic, 0);
}

收到:

void NetworkLogic::customEventAction(int /*playerNr*/, nByte /*eventCode*/, const ExitGames::Common::Object& eventContent)
{
    EGLOG(ExitGames::Common::DebugLevel::ALL, L"");
    ExitGames::Common::Dictionary<nByte, ExitGames::Common::Object> dic = ExitGames::Common::ValueObject<ExitGames::Common::Dictionary<nByte, ExitGames::Common::Object> >(eventContent).getDataCopy();
    const ExitGames::Common::Object* pObj = dic.getValue(1);
    ExitGames::Common::JString str = ExitGames::Common::ValueObject<ExitGames::Common::JString>(pObj).getDataCopy();
    mpOutputListener->write(L"received the following string as Dictionary value: " + str);
}

这给了我接收客户端的以下输出行:

收到以下字符串作为字典值:测试

于 2016-03-01T11:31:39.840 回答