Friend Query Callback (GUAQuereyFriendObserver)
[MSDK & Player Network SDK] Register the friend module callback. The game needs to register the callback for handling.For more information about the callback data structure, see GUAFriendResult.
note
It is strongly recommended that games register in the application startup function.
Function Definition
- Unity
- Unreal Engine
Method list for handling callback events
| Callback Event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| FriendBaseEvents | QueryFriends | * | - |
event OnResultHandler<GUAFriendResult> QuereyFriendEvents;
Method list for handling callback events
| Callback Event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| OnQueryFriendNotify | QueryFriends | * | - |
class GUA_EXTERN GUAFriendObserver
{
public:
virtual ~GUAFriendObserver() {};
virtual void OnQueryFriendNotify(const GUAFriendResult &friend_ret){};
};
Code Example
- Unity
- Unreal Engine
// Add callback
UnionAdapterAPI.GetFriendService().QuereyFriendEvents += OnFriendQueryFriend;
// Remove callback
UnionAdapterAPI.GetFriendService().QuereyFriendEvents -= OnFriendQueryFriend;
// QuereyFriendEvents callback handling
private void OnFriendQueryFriend(GUAFriendResult friendRet)
{
string methodTag = "";
if (friendRet.MethodId == (int)GUAMethodID.GUA_FRIEND_QUERY_FRIENDS)
{
methodTag = "QueryFriends";
}
Debug.Log(methodTag + friendRet.ToString());
}
// 1. In the engine layer, define an observer class inheriting from GUA_NAMESPACE::GUAFriendObserver
// 2. Implement the callback interface with the same method name (e.g., OnQueryFriendNotify)
class FGUAFriendObserver : public GUA_NAMESPACE::GUAFriendObserver {
public:
static FGUAFriendObserver Instance;
void OnQueryFriendNotify(const GUA_NAMESPACE::GUAFriendResult& friend_ret)
{
}
};
FGUAFriendObserver FGUAFriendObserver::Instance;
// Set callback
GUA_NAMESPACE::GUAFriendService::SetFriendObserver(&FGUAFriendObserver::Instance);