Callback of the Notification Module (NoticeResultObserver)
[MSDK & Player Network SDK] Register a callback for the notice module. The game needs to register a callback for processing.For more information about the callback data structure, see GUANoticeResult.
note
It is strongly recommended that games register in the application startup function.
Function Definition
- Unity
- Unreal Engine
List of methods used to handle callback events
| Callback Event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| NoticeResultEvents | Load notice information (LoadNoticeData) | * | - |
event OnResultHandler<GUANoticeRet> NoticeResultEvents;
List of methods used to handle callback events
| Callback Event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| OnLoadNoticeData | Load notice information (LoadNoticeData) | * | - |
class GUA_EXTERN GUANoticeObserver
{
public:
virtual ~GUANoticeObserver() {};
virtual void OnLoadNoticeData(const GUANoticeResult ¬ice_result) {};
};
Code Example
- Unity
- Unreal Engine
// Add the callback
UnionAdapterAPI.GetNoticeService().NoticeResultEvents += OnNoticeResultEvent;
// Remove the callback
UnionAdapterAPI.GetNoticeService().NoticeResultEvents -= OnNoticeResultEvent;
// NoticeResultEvents callback handling
private void OnNoticeResultEvent(GUANoticeRet noticeRet)
{
Debug.Log("OnNoticeResultEvent");
string methodTag = "";
if (noticeRet.MethodId == (int)GUAMethodID.GUA_NOTICE_REQUEST_DATA)
{
methodTag = "RequestNoticeData";
}
Debug.Log(methodTag + noticeRet.ToString());
NoticeSample noticeWindow = m_sample as NoticeSample;
if (noticeWindow != null)
{
noticeWindow.SetNoticeResult(noticeRet);
}
}
// 1. In the engine layer, define an observer class that inherits from GUA_NAMESPACE::GUANoticeObserver
// 2. Implement the callback interface with the same method name (e.g., OnLoadNoticeData)
class FGUANoticeObserver : public GUA_NAMESPACE::GUANoticeObserver {
public:
static FGUANoticeObserver Instance;
void OnLoadNoticeData(const GUA_NAMESPACE::GUANoticeResult ¬ice_result)
{
}
};
FGUANoticeObserver FGUANoticeObserver::Instance;
// Set the callback
GUA_NAMESPACE::GUANoticeService::SetNoticeObserver(&FGUANoticeObserver::Instance);