.h
D:\Program Files\Epic Games\UE_5.3\Engine\Plugins\Online\OnlineSubsystemOculus\Source\Classes\OculusFindSessionsCallbackProxy.h
ヘッダーでデリゲート変数の型指定してる
FOnFindSessionsCompleteDelegate Delegate; これがデリゲート変数の型指定
ヘッダーでデリゲートハンドルの型指定してる。
//登録された OnFindSessionsComplete デリゲートへのハンドル
FDelegateHandle DelegateHandle;
というのは・・・・
D:\Program Files\Epic Games\UE_5.3\Engine\Plugins\Online\OnlineSubsystem\Source\Public\Interfaces\OnlineSessionDelegates.h
でこのように定義されている
OnlineSessionDelegates.hでの FOnFindSessionsCompleteDelegate の定義
- オンライン セッションの検索が完了したときに呼び出されるデリゲート
- @param bWasSuccessful 非同期アクションがエラーなしで完了した場合は true、エラーがあった場合は false
DECLARE_MULTICAST_DELEGATE_OneParam(FOnFindSessionsComplete, bool);
typedef FOnFindSessionsComplete::FDelegate FOnFindSessionsCompleteDelegate;
.h 全文
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "UObject/Object.h"
#include "Net/OnlineBlueprintCallProxyBase.h"
#include "Interfaces/OnlineSessionInterface.h"
#include "FindSessionsCallbackProxy.h"
#include "OculusFindSessionsCallbackProxy.generated.h"
/**
* Exposes FindSession of the Platform SDK for blueprint use.
*/
UCLASS(MinimalAPI)
class UOculusFindSessionsCallbackProxy : public UOnlineBlueprintCallProxyBase
{
GENERATED_UCLASS_BODY()
// Called when there is a successful query
UPROPERTY(BlueprintAssignable)
FBlueprintFindSessionsResultDelegate OnSuccess;
// Called when there is an unsuccessful query
UPROPERTY(BlueprintAssignable)
FBlueprintFindSessionsResultDelegate OnFailure;
// Searches for matchmaking room sessions with the oculus online subsystem
UFUNCTION(BlueprintCallable, Category = "Oculus|Session", meta = (BlueprintInternalUseOnly = "true"))
static UOculusFindSessionsCallbackProxy* FindMatchmakingSessions(int32 MaxResults, FString OculusMatchmakingPool);
// Searches for moderated room sessions with the oculus online subsystem
UFUNCTION(BlueprintCallable, Category = "Oculus|Session", meta = (BlueprintInternalUseOnly = "true"))
static UOculusFindSessionsCallbackProxy* FindModeratedSessions(int32 MaxResults);
// UOnlineBlueprintCallProxyBase interface
virtual void Activate() override;
// End of UOnlineBlueprintCallProxyBase interface
private:
// Internal callback when the session search completes, calls out to the public success/failure callbacks
void OnCompleted(bool bSuccess);
private:
// The delegate executed by the online subsystem
FOnFindSessionsCompleteDelegate Delegate;//デリゲート宣言
// Handle to the registered OnFindSessionsComplete delegate
FDelegateHandle DelegateHandle;//デリゲートハンドル宣言
// Object to track search results
TSharedPtr<FOnlineSessionSearch> SearchObject;
// Maximum number of results to return
int MaxResults;
// Optional: if searching within a matchmaking pool
FString OculusPool;
bool bSearchModeratedRoomsOnly;
};
CPP
D:\Program Files\Epic Games\UE_5.3\Engine\Plugins\Online\OnlineSubsystemOculus\Source\Private\OculusFindSessionsCallbackProxy.cpp では
デリゲートにOnComplitedをバインドしてる
Super(ObjectInitializer) のあと
Delegate(FOnFindSessionsCompleteDelegate::CreateUObject(this, &ThisClass::OnCompleted))
デリゲートハンドルにDelegateを渡してる。(コールしてる)
if (OculusSessionInterface.IsValid()) のタイミングで
DelegateHandle = OculusSessionInterface->AddOnFindSessionsCompleteDelegate_Handle(Delegate);
// Copyright Epic Games, Inc. All Rights Reserved.
#include "OculusFindSessionsCallbackProxy.h"
#include "OnlineSubsystemOculusPrivate.h"
#include "Online.h"
#include "OnlineSessionInterfaceOculus.h"
#include "OnlineSubsystemOculusPrivate.h"
UOculusFindSessionsCallbackProxy::UOculusFindSessionsCallbackProxy(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, Delegate(FOnFindSessionsCompleteDelegate::CreateUObject(this, &ThisClass::OnCompleted))
, MaxResults(0)
, bSearchModeratedRoomsOnly(false)
{
//デリゲートにOnComplitedをバインド
}
UOculusFindSessionsCallbackProxy* UOculusFindSessionsCallbackProxy::FindMatchmakingSessions(int32 MaxResults, FString OculusMatchmakingPool)
{
UOculusFindSessionsCallbackProxy* Proxy = NewObject<UOculusFindSessionsCallbackProxy>();
Proxy->SetFlags(RF_StrongRefOnFrame);
Proxy->MaxResults = MaxResults;
Proxy->OculusPool = MoveTemp(OculusMatchmakingPool);
Proxy->bSearchModeratedRoomsOnly = false;
return Proxy;
}
UOculusFindSessionsCallbackProxy* UOculusFindSessionsCallbackProxy::FindModeratedSessions(int32 MaxResults)
{
UOculusFindSessionsCallbackProxy* Proxy = NewObject<UOculusFindSessionsCallbackProxy>();
Proxy->SetFlags(RF_StrongRefOnFrame);
Proxy->MaxResults = MaxResults;
Proxy->bSearchModeratedRoomsOnly = true;
return Proxy;
}
void UOculusFindSessionsCallbackProxy::Activate()
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
auto OculusSessionInterface = Online::GetSessionInterface(OCULUS_SUBSYSTEM);
PRAGMA_ENABLE_DEPRECATION_WARNINGS
if (OculusSessionInterface.IsValid())
{
//デリゲートハンドルにDelegateを渡してる。(コールしてる)
DelegateHandle = OculusSessionInterface->AddOnFindSessionsCompleteDelegate_Handle(Delegate);
SearchObject = MakeShareable(new FOnlineSessionSearch);
SearchObject->MaxSearchResults = MaxResults;
SearchObject->QuerySettings.Set(SEARCH_OCULUS_MODERATED_ROOMS_ONLY, bSearchModeratedRoomsOnly, EOnlineComparisonOp::Equals);
if (!OculusPool.IsEmpty())
{
SearchObject->QuerySettings.Set(SETTING_OCULUS_POOL, OculusPool, EOnlineComparisonOp::Equals);
}
OculusSessionInterface->FindSessions(0, SearchObject.ToSharedRef());
}
else
{
UE_LOG_ONLINE_SESSION(Error, TEXT("Oculus platform service not available. Skipping FindSessions."));
TArray<FBlueprintSessionResult> Results;
OnFailure.Broadcast(Results);
}
}
void UOculusFindSessionsCallbackProxy::OnCompleted(bool bSuccess)
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
auto OculusSessionInterface = Online::GetSessionInterface(OCULUS_SUBSYSTEM);
PRAGMA_ENABLE_DEPRECATION_WARNINGS
if (OculusSessionInterface.IsValid())
{
OculusSessionInterface->ClearOnFindSessionsCompleteDelegate_Handle(DelegateHandle);
}
TArray<FBlueprintSessionResult> Results;
if (bSuccess && SearchObject.IsValid())
{
for (auto& Result : SearchObject->SearchResults)
{
FBlueprintSessionResult BPResult;
BPResult.OnlineResult = Result;
Results.Add(BPResult);
}
OnSuccess.Broadcast(Results);
}
else
{
OnFailure.Broadcast(Results);
}
}
ちょっと複雑すぎてちょと何言ってるかわからない感じもする。が
まとめ4つを同じように見つけることができた。
1、デリゲート宣言
FOnFindSessionsCompleteDelegate Delegate;
2、ハンドル初期化
FDelegateHandle DelegateHandle;
3,バインド
Delegate(FOnFindSessionsCompleteDelegate::CreateUObject(this, &ThisClass::OnCompleted))
4タイミングでコール呼び出し
DelegateHandle = OculusSessionInterface->AddOnFindSessionsCompleteDelegate_Handle(Delegate);
自信がないので間違っていたら連絡してほしいです。