我们在触发事件时使用 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();
我找到了从哈希表中获取数据的代码,但这也不起作用。
谢谢
肖恩
最佳答案
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);
}
这在接收客户端上给出了以下输出行:
received the following string as Dictionary value: test
关于c++ - 如何从 Photon eventContent 字典中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35603884/