当事件被触发时,我们正在使用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();
我找到了从哈希表中获取数据的代码,但这也不起作用。
感谢
肖恩
答案 0 :(得分: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);
}
这为我提供了接收客户端上的以下输出行:
收到以下字符串作为词典值:test