Callback of the Friend module (GUAFriendBaseResultObserver)
[MSDK & Player Network SDK] Register the callback of the Friend module. The game needs to register the callback for handling.For more information about the callback data structure, see GUABaseResult.
note
It is strongly recommended that games register in the application startup function.
Function Definition
- Unity
- Unreal Engine
List of methods for handling callback events
| Callback Event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| FriendBaseEvents | SendMessage, Share | * | AddFriend |
event OnResultHandler<GUABaseResult> FriendBaseEvents;
List of methods for handling callback events
| Callback Event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| OnBaseResultNotify | SendMessage, Share | * | AddFriend |
class GUA_EXTERN GUAFriendObserver
{
public:
virtual ~GUAFriendObserver() {};
virtual void OnBaseResultNotify(const GUABaseResult &base_ret){};
}
Code Example
- Unity
- Unreal Engine
// Add callback
UnionAdapterAPI.GetFriendService().FriendBaseEvents += OnFriendBaseEvent;
// Remove callback
UnionAdapterAPI.GetFriendService().FriendBaseEvents -= OnFriendBaseEvent;
// Handle FriendBaseEvents callback
private void OnFriendBaseEvent(GUABaseResult baseRet)
{
string methodTag = "";
if (baseRet.MethodId == (int)GUAMethodID.GUA_FRIEND_SHARE)
{
methodTag = "Share";
}
else if (baseRet.MethodId == (int)GUAMethodID.GUA_FRIEND_SEND_MESSAGE)
{
methodTag = "SendMessage";
}
Debug.Log.(methodTag + baseRet.ToString());
}
// 1. Define an observer class in the engine layer that inherits from GUA_NAMESPACE::GUAFriendObserver
// 2. Implement callback interfaces with the same method names (e.g., OnBaseResultNotify)
class FGUAFriendObserver : public GUA_NAMESPACE::GUAFriendObserver {
public:
static FGUAFriendObserver Instance;
void OnBaseResultNotify(const GUA_NAMESPACE::GUABaseResult& base_ret)
{
}
};
FGUAFriendObserver FGUAFriendObserver::Instance;
// Set the callback
GUA_NAMESPACE::GUAFriendService::SetFriendObserver(&FGUAFriendObserver::Instance);