2021-09-28 13:33:17 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "SmartObjectBlueprintFunctionLibrary.h"
|
|
|
|
|
#include "SmartObjectSubsystem.h"
|
2021-11-22 16:32:17 -05:00
|
|
|
#include "BlackboardKeyType_SOClaimHandle.h"
|
|
|
|
|
#include "BehaviorTree/BlackboardComponent.h"
|
2022-09-15 15:15:14 -04:00
|
|
|
#include "BehaviorTree/BTFunctionLibrary.h"
|
2021-09-28 13:33:17 -04:00
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
// USmartObjectBlueprintFunctionLibrary
|
|
|
|
|
//----------------------------------------------------------------------//
|
2021-11-22 16:32:17 -05:00
|
|
|
FSmartObjectClaimHandle USmartObjectBlueprintFunctionLibrary::GetValueAsSOClaimHandle(UBlackboardComponent* BlackboardComponent, const FName& KeyName)
|
|
|
|
|
{
|
|
|
|
|
if (BlackboardComponent == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
return BlackboardComponent->GetValue<UBlackboardKeyType_SOClaimHandle>(KeyName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void USmartObjectBlueprintFunctionLibrary::SetValueAsSOClaimHandle(UBlackboardComponent* BlackboardComponent, const FName& KeyName, const FSmartObjectClaimHandle Value)
|
|
|
|
|
{
|
|
|
|
|
if (BlackboardComponent == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const FBlackboard::FKey KeyID = BlackboardComponent->GetKeyID(KeyName);
|
|
|
|
|
BlackboardComponent->SetValue<UBlackboardKeyType_SOClaimHandle>(KeyID, Value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 13:33:17 -04:00
|
|
|
bool USmartObjectBlueprintFunctionLibrary::K2_SetSmartObjectEnabled(AActor* SmartObject, const bool bEnabled)
|
|
|
|
|
{
|
|
|
|
|
if (SmartObject == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UWorld* World = SmartObject->GetWorld();
|
|
|
|
|
if (World == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
USmartObjectSubsystem* Subsystem = USmartObjectSubsystem::GetCurrent(World);
|
|
|
|
|
if (Subsystem == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bEnabled ? Subsystem->RegisterSmartObjectActor(*SmartObject)
|
|
|
|
|
: Subsystem->UnregisterSmartObjectActor(*SmartObject);
|
|
|
|
|
}
|
2022-09-15 15:15:14 -04:00
|
|
|
|
|
|
|
|
void USmartObjectBlueprintFunctionLibrary::SetBlackboardValueAsSOClaimHandle(UBTNode* NodeOwner, const FBlackboardKeySelector& Key, const FSmartObjectClaimHandle& Value)
|
|
|
|
|
{
|
|
|
|
|
if (UBlackboardComponent* BlackboardComp = UBTFunctionLibrary::GetOwnersBlackboard(NodeOwner))
|
|
|
|
|
{
|
|
|
|
|
BlackboardComp->SetValue<UBlackboardKeyType_SOClaimHandle>(Key.SelectedKeyName, Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FSmartObjectClaimHandle USmartObjectBlueprintFunctionLibrary::GetBlackboardValueAsSOClaimHandle(UBTNode* NodeOwner, const FBlackboardKeySelector& Key)
|
|
|
|
|
{
|
|
|
|
|
UBlackboardComponent* BlackboardComp = UBTFunctionLibrary::GetOwnersBlackboard(NodeOwner);
|
|
|
|
|
return BlackboardComp ? BlackboardComp->GetValue<UBlackboardKeyType_SOClaimHandle>(Key.SelectedKeyName) : FSmartObjectClaimHandle::InvalidHandle;
|
|
|
|
|
}
|