网络诊断回调处理(DetectNetWortResultObserver)[仅限 Player Network SDK]
注册网络诊断的回调,游戏需要注册回调函数进行处理。更多关于回调数据结构,可以查看 GUADetectNetWortResult。
注意
强烈建议游戏在应用启动函数中进行注册 [仅限 Player Network SDK]。
函数定义
- Unity
- Unreal Engine
回调事件用于处理的方法列表
回调事件 | Common | [仅限 Player Network SDK] | [仅限 MSD] |
---|---|---|---|
DetectNetWortResultEvents | - | 网络诊断(StartDetectNetwork) | - |
event OnResultHandler<GUADetectNetworkResult> DetectNetWortResultEvents;
回调事件用于处理的方法列表
回调事件 | Common | [仅限 Player Network SDK] | [仅限 MSD] |
---|---|---|---|
OnDetectNetworkResultNotify | - | 网络诊断(StartDetectNetwork) | - |
class GUA_EXTERN GUADetectNetworkObserver
{
public:
virtual ~GUADetectNetworkObserver(){};
virtual void OnDetectNetworkResultNotify(const GUADetectNetworkResult &detect_network_ret) {};
};
代码示例
- Unity
- Unreal Engine
UnionAdapterAPI.GetToolsService().DetectNetWortResultEvents += OnDetectNetWortResultEvents;
UnionAdapterAPI.GetToolsService().DetectNetWortResultEvents -= OnDetectNetWortResultEvents;
private void OnDetectNetWortResultEvents(GUADetectNetworkResult result)
{
string methodTag = "";
if (result.MethodId == (int)GUAMethodID.GUA_TOOLS_DETECT_NETWORK)
{
methodTag = "OnDetectNetworkResult";
}
Debug.Log(methodTag + result.ToString());
}
// 1.在引擎层定义继承自 GUA_NAMESPACE::GUADetectNetworkObserver 的观察者类
// 2.实现方法名一样的回调接口(如:OnDetectNetworkResultNotify)
class FGUADetectNetworkObserver : public GUA_NAMESPACE::GUADetectNetworkObserver {
public:
static FGUADetectNetworkObserver Instance;
void OnDetectNetworkResultNotify(const GUA_NAMESPACE::GUADetectNetworkResult &ret)
{
}
};
FGUADetectNetworkObserver FGUADetectNetworkObserver::Instance;
// 设置回调
GUA_NAMESPACE::GUAToolsService::SetDetectNetworkObserver(&FGUADetectNetworkObserver::Instance);