写入游戏管理的统计信息
本主题提供演示如何编写游戏管理的统计信息的示例代码。
仅更新指定的游戏管理的统计信息
可以通过调用 XblTitleManagedStatsUpdateStatsAsync 发送要更新的指定统计信息,后者有选择地更新调用用户的统计信息。仅当指定的统计信息已存在时,才会覆盖该统计信息。 调用 XblTitleManagedStatsUpdateStatsAsync
中未指定的任何统计信息保持不变。
C API
std::vector<XblTitleManagedStatistic> stats{ s_svd->Stats() };
auto stat1 = std::find_if(stats.begin(), stats.end(), [](const XblTitleManagedStatistic& s)
{
return std::string{ "AddedStat" } == s.statisticName;
});
auto asyncBlock = std::make_unique<XAsyncBlock>();
asyncBlock->queue = Data()->queue;
asyncBlock->callback = [](XAsyncBlock* asyncBlock)
{
std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock }; // Take over ownership of the XAsyncBlock*
HRESULT hr = XAsyncGetStatus(asyncBlock, false);
};
HRESULT hr = XblTitleManagedStatsUpdateStatsAsync(
Data()->xboxLiveContext,
&(*stat1),
1,
asyncBlock.get()
);
if (SUCCEEDED(hr))
{
// The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* since the callback will take over ownership.
// If the call fails, the std::unique_ptr will keep ownership and delete the XAsyncBlock*
asyncBlock.release();
}
参考
写入希望保留的所有统计信息,然后删除其余统计信息
要仅写入希望保留的游戏管理的统计信息,并删除其余统计信息,请调用 XblTitleManagedStatsWriteAsync 并提供希望写入的所有统计信息。 将删除未包含在调用中的任何统计信息。 此调用将服务上的最后一个统计信息文档替换为仅包含你发送的值的新统计信息文档。
C API
std::vector<XblTitleManagedStatistic> statList;
statList.push_back(XblTitleManagedStatistic{ "MyStatName1", XblTitleManagedStatType::Number, 200 });
statList.push_back(XblTitleManagedStatistic{ "MyStatName2", XblTitleManagedStatType::String, 0, "SomeValue" });
auto asyncBlock = std::make_unique<XAsyncBlock>();
asyncBlock->queue = queue;
asyncBlock->context = nullptr;
asyncBlock->callback = [](XAsyncBlock* asyncBlock)
{
std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock }; // Take over ownership of the XAsyncBlock*
HRESULT hr = XAsyncGetStatus(asyncBlock, false);
};
HRESULT hr = XblTitleManagedStatsWriteAsync(
xboxLiveContext,
xboxUserId,
statList.data(), statList.size(),
asyncBlock.get());
if (SUCCEEDED(hr))
{
// The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* since the callback will take over ownership.
// If the call fails, the std::unique_ptr will keep ownership and delete the XAsyncBlock*
asyncBlock.release();
}
参考