You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
+ added activityTags in slot + added unit test for tag filtering and fixed unit tests messages + preview mesh and actor class are no longer exposed to the user in the definition asset (they should only be used by the editor for preview) + misc API cleanup and simplifications #rnx #rb mikko.mononen #preflight 621e6a9dca28c5563431e601 #ROBOMERGE-OWNER: yoan.stamant #ROBOMERGE-AUTHOR: yoan.stamant #ROBOMERGE-SOURCE: CL 19204358 via CL 19212259 via CL 19212264 via CL 19212779 #ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v921-19075845) [CL 19224407 by yoan stamant in ue5-main branch]
116 lines
3.7 KiB
C++
116 lines
3.7 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "SmartObjectDefinition.h"
|
|
|
|
#include "SmartObjectSettings.h"
|
|
#include "SmartObjectTypes.h"
|
|
|
|
namespace UE::SmartObject
|
|
{
|
|
const FVector DefaultSlotSize(40, 40, 90);
|
|
}
|
|
|
|
USmartObjectDefinition::USmartObjectDefinition(const FObjectInitializer& ObjectInitializer): UDataAsset(ObjectInitializer)
|
|
{
|
|
TagFilteringPolicy = GetDefault<USmartObjectSettings>()->DefaultTagFilteringPolicy;
|
|
}
|
|
|
|
bool USmartObjectDefinition::Validate() const
|
|
{
|
|
bValid = false;
|
|
if (Slots.Num() == 0)
|
|
{
|
|
UE_LOG(LogSmartObject, Error, TEXT("Need to provide at least one slot definition"));
|
|
return false;
|
|
}
|
|
|
|
// Detect null entries in default definitions
|
|
int32 NullEntryIndex;
|
|
if (DefaultBehaviorDefinitions.Find(nullptr, NullEntryIndex))
|
|
{
|
|
UE_LOG(LogSmartObject, Error, TEXT("Null entry found at index %d in default behavior definition list"), NullEntryIndex);
|
|
return false;
|
|
}
|
|
|
|
// Detect null entries in slot definitions
|
|
for (int i = 0; i < Slots.Num(); ++i)
|
|
{
|
|
const FSmartObjectSlotDefinition& Slot = Slots[i];
|
|
if (Slot.BehaviorDefinitions.Find(nullptr, NullEntryIndex))
|
|
{
|
|
UE_LOG(LogSmartObject, Error, TEXT("Null definition entry found at index %d in behavior list of slot %d"), i, NullEntryIndex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Detect missing definitions in slots if no default one are provided
|
|
if (DefaultBehaviorDefinitions.Num() == 0)
|
|
{
|
|
for (int i = 0; i < Slots.Num(); ++i)
|
|
{
|
|
const FSmartObjectSlotDefinition& Slot = Slots[i];
|
|
if (Slot.BehaviorDefinitions.Num() == 0)
|
|
{
|
|
UE_LOG(LogSmartObject, Error, TEXT("Slot at index %d needs to provide a behavior definition since there is no default one in the SmartObject definition"), i);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
bValid = true;
|
|
return true;
|
|
}
|
|
|
|
const USmartObjectBehaviorDefinition* USmartObjectDefinition::GetBehaviorDefinition(const FSmartObjectSlotIndex& SlotIndex,
|
|
const TSubclassOf<USmartObjectBehaviorDefinition>& DefinitionClass) const
|
|
{
|
|
const USmartObjectBehaviorDefinition* Definition = nullptr;
|
|
if (Slots.IsValidIndex(SlotIndex))
|
|
{
|
|
Definition = GetBehaviorDefinitionByType(Slots[SlotIndex].BehaviorDefinitions, DefinitionClass);
|
|
}
|
|
|
|
if (Definition == nullptr)
|
|
{
|
|
Definition = GetBehaviorDefinitionByType(DefaultBehaviorDefinitions, DefinitionClass);
|
|
}
|
|
|
|
return Definition;
|
|
}
|
|
|
|
FBox USmartObjectDefinition::GetBounds() const
|
|
{
|
|
FBox BoundingBox(ForceInitToZero);
|
|
for (const FSmartObjectSlotDefinition& Slot : GetSlots())
|
|
{
|
|
BoundingBox += Slot.Offset + UE::SmartObject::DefaultSlotSize;
|
|
BoundingBox += Slot.Offset - UE::SmartObject::DefaultSlotSize;
|
|
}
|
|
return BoundingBox;
|
|
}
|
|
|
|
TOptional<FTransform> USmartObjectDefinition::GetSlotTransform(const FTransform& OwnerTransform, const FSmartObjectSlotIndex SlotIndex) const
|
|
{
|
|
TOptional<FTransform> Transform;
|
|
|
|
if (ensureMsgf(Slots.IsValidIndex(SlotIndex), TEXT("Requesting slot transform for an out of range index: %s"), *LexToString(SlotIndex)))
|
|
{
|
|
const FSmartObjectSlotDefinition& Slot = Slots[SlotIndex];
|
|
Transform = FTransform(Slot.Rotation, Slot.Offset) * OwnerTransform;
|
|
}
|
|
|
|
return Transform;
|
|
}
|
|
|
|
const USmartObjectBehaviorDefinition* USmartObjectDefinition::GetBehaviorDefinitionByType(const TArray<USmartObjectBehaviorDefinition*>& BehaviorDefinitions,
|
|
const TSubclassOf<USmartObjectBehaviorDefinition>& DefinitionClass)
|
|
{
|
|
USmartObjectBehaviorDefinition* const* BehaviorDefinition = BehaviorDefinitions.FindByPredicate([&DefinitionClass](USmartObjectBehaviorDefinition* SlotBehaviorDefinition)
|
|
{
|
|
return SlotBehaviorDefinition != nullptr && SlotBehaviorDefinition->GetClass()->IsChildOf(*DefinitionClass);
|
|
});
|
|
|
|
return BehaviorDefinition != nullptr ? *BehaviorDefinition : nullptr;
|
|
}
|
|
|