2021-09-28 13:33:00 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "Components/SceneComponent.h"
|
|
|
|
|
#include "SmartObjectTypes.h"
|
2021-11-26 12:55:06 -05:00
|
|
|
#include "SmartObjectDefinition.h"
|
2021-09-28 13:33:00 -04:00
|
|
|
#include "SmartObjectComponent.generated.h"
|
|
|
|
|
|
2023-01-25 02:42:36 -05:00
|
|
|
namespace EEndPlayReason { enum Type : int; }
|
|
|
|
|
|
2022-03-16 03:47:02 -04:00
|
|
|
class UAbilitySystemComponent;
|
|
|
|
|
struct FSmartObjectRuntime;
|
2023-02-02 18:43:13 -05:00
|
|
|
struct FSmartObjectComponentInstanceData;
|
|
|
|
|
|
|
|
|
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FSmartObjectComponentEventSignature, const FSmartObjectEventData&, EventData, const AActor*, Interactor);
|
2023-02-24 14:59:17 -05:00
|
|
|
DECLARE_MULTICAST_DELEGATE_TwoParams(FSmartObjectComponentEventNativeSignature, const FSmartObjectEventData& EventData, const AActor* Interactor);
|
2022-03-16 03:47:02 -04:00
|
|
|
|
2022-12-05 08:19:29 -05:00
|
|
|
enum class ESmartObjectRegistrationType : uint8
|
|
|
|
|
{
|
|
|
|
|
None, // corresponds to "not registered"
|
|
|
|
|
WithCollection,
|
|
|
|
|
Dynamic
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-19 17:32:09 -04:00
|
|
|
enum class ESmartObjectUnregistrationType : uint8
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Component registered by a collection (WithCollection) will be unbound from the simulation but its associated runtime data will persist.
|
|
|
|
|
* Otherwise (Dynamic), runtime data will also be destroyed.
|
|
|
|
|
*/
|
|
|
|
|
RegularProcess,
|
|
|
|
|
/** Component will be unbound from the simulation and its runtime data will be destroyed regardless of the registration type */
|
|
|
|
|
ForceRemove
|
|
|
|
|
};
|
2022-12-05 08:19:29 -05:00
|
|
|
|
2021-11-02 11:09:09 -04:00
|
|
|
UCLASS(Blueprintable, ClassGroup = Gameplay, meta = (BlueprintSpawnableComponent), config = Game, HideCategories = (Activation, AssetUserData, Collision, Cooking, HLOD, Lighting, LOD, Mobile, Mobility, Navigation, Physics, RayTracing, Rendering, Tags, TextureStreaming))
|
2021-09-28 13:33:00 -04:00
|
|
|
class SMARTOBJECTSMODULE_API USmartObjectComponent : public USceneComponent
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
2022-11-24 14:53:52 -05:00
|
|
|
DECLARE_MULTICAST_DELEGATE_OneParam(FOnSmartObjectChanged, const USmartObjectComponent& /*Instance*/);
|
|
|
|
|
|
2021-11-02 11:09:09 -04:00
|
|
|
explicit USmartObjectComponent(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
|
2021-09-28 13:33:00 -04:00
|
|
|
|
|
|
|
|
FBox GetSmartObjectBounds() const;
|
|
|
|
|
|
2021-11-26 09:52:13 -05:00
|
|
|
const USmartObjectDefinition* GetDefinition() const { return DefinitionAsset; }
|
|
|
|
|
void SetDefinition(USmartObjectDefinition* Definition) { DefinitionAsset = Definition; }
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2022-11-24 14:53:52 -05:00
|
|
|
bool GetCanBePartOfCollection() const { return bCanBePartOfCollection; }
|
|
|
|
|
|
2023-01-23 18:47:59 -05:00
|
|
|
ESmartObjectRegistrationType GetRegistrationType() const { return RegistrationType; }
|
2022-01-19 14:16:16 -05:00
|
|
|
FSmartObjectHandle GetRegisteredHandle() const { return RegisteredHandle; }
|
2022-12-05 08:19:29 -05:00
|
|
|
void SetRegisteredHandle(const FSmartObjectHandle Value, const ESmartObjectRegistrationType InRegistrationType);
|
|
|
|
|
void InvalidateRegisteredHandle();
|
2021-11-02 11:09:09 -04:00
|
|
|
|
2023-02-02 18:43:13 -05:00
|
|
|
void OnRuntimeInstanceBound(FSmartObjectRuntime& RuntimeInstance);
|
|
|
|
|
void OnRuntimeInstanceUnbound(FSmartObjectRuntime& RuntimeInstance);
|
|
|
|
|
|
2023-02-24 14:59:17 -05:00
|
|
|
FSmartObjectComponentEventNativeSignature& GetOnSmartObjectEventNative() { return OnSmartObjectEventNative; }
|
2023-05-26 12:48:38 -04:00
|
|
|
bool IsBoundToSimulation() const { return EventDelegateHandle.IsValid(); }
|
2023-02-24 14:59:17 -05:00
|
|
|
|
2022-11-24 14:53:52 -05:00
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
static FOnSmartObjectChanged& GetOnSmartObjectChanged() { return OnSmartObjectChanged; }
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
|
|
|
|
|
2021-09-28 13:33:00 -04:00
|
|
|
protected:
|
2023-02-02 18:43:13 -05:00
|
|
|
friend FSmartObjectComponentInstanceData;
|
2022-02-03 13:28:03 -05:00
|
|
|
virtual TStructOnScope<FActorComponentInstanceData> GetComponentInstanceData() const override;
|
|
|
|
|
|
2023-02-02 18:43:13 -05:00
|
|
|
void OnRuntimeEventReceived(const FSmartObjectEventData& Event);
|
|
|
|
|
|
|
|
|
|
UPROPERTY(BlueprintAssignable, Category = SmartObject, meta=(DisplayName = "OnSmartObjectEvent"))
|
|
|
|
|
FSmartObjectComponentEventSignature OnSmartObjectEvent;
|
|
|
|
|
|
2023-02-24 14:59:17 -05:00
|
|
|
/** Native version of OnSmartObjectEvent. */
|
|
|
|
|
FSmartObjectComponentEventNativeSignature OnSmartObjectEventNative;
|
|
|
|
|
|
2023-02-02 18:43:13 -05:00
|
|
|
UFUNCTION(BlueprintImplementableEvent, Category = SmartObject, meta=(DisplayName = "OnSmartObjectEventReceived"))
|
|
|
|
|
void ReceiveOnEvent(const FSmartObjectEventData& EventData, const AActor* Interactor);
|
|
|
|
|
|
2022-11-24 14:53:52 -05:00
|
|
|
virtual void PostInitProperties() override;
|
|
|
|
|
|
2023-04-19 17:32:09 -04:00
|
|
|
virtual void BeginPlay() override;
|
|
|
|
|
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
|
|
|
|
|
|
|
|
|
protected:
|
2022-11-24 14:53:52 -05:00
|
|
|
#if WITH_EDITOR
|
2023-04-19 17:32:09 -04:00
|
|
|
virtual void OnRegister() override;
|
|
|
|
|
virtual void OnUnregister() override;
|
|
|
|
|
|
2022-11-24 14:53:52 -05:00
|
|
|
virtual void PostEditUndo() override;
|
|
|
|
|
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
|
|
|
|
|
#endif // WITH_EDITOR
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2022-02-03 13:28:03 -05:00
|
|
|
void RegisterToSubsystem();
|
2023-04-19 17:32:09 -04:00
|
|
|
void UnregisterFromSubsystem(const ESmartObjectUnregistrationType UnregistrationType);
|
2022-02-03 13:28:03 -05:00
|
|
|
|
2022-01-31 18:38:28 -05:00
|
|
|
UPROPERTY(EditAnywhere, Category = SmartObject, BlueprintReadWrite)
|
2021-11-26 09:52:13 -05:00
|
|
|
TObjectPtr<USmartObjectDefinition> DefinitionAsset;
|
2021-09-28 13:33:00 -04:00
|
|
|
|
2022-01-19 14:16:16 -05:00
|
|
|
/** RegisteredHandle != FSmartObjectHandle::Invalid when registered into a collection by SmartObjectSubsystem */
|
2021-09-28 13:33:00 -04:00
|
|
|
UPROPERTY(Transient, VisibleAnywhere, Category = SmartObject)
|
2022-01-19 14:16:16 -05:00
|
|
|
FSmartObjectHandle RegisteredHandle;
|
2022-03-16 03:47:02 -04:00
|
|
|
|
2022-12-05 08:19:29 -05:00
|
|
|
ESmartObjectRegistrationType RegistrationType = ESmartObjectRegistrationType::None;
|
|
|
|
|
|
2023-02-02 18:43:13 -05:00
|
|
|
FDelegateHandle EventDelegateHandle;
|
|
|
|
|
|
2022-11-24 14:53:52 -05:00
|
|
|
/**
|
|
|
|
|
* Controls whether a given SmartObject can be aggregated in SmartObjectPersistentCollections. SOs in collections
|
|
|
|
|
* can be queried and reasoned about even while the actual Actor and its components are not streamed in.
|
|
|
|
|
* By default SmartObjects are not placed in collections and are active only as long as the owner-actor remains
|
|
|
|
|
* loaded and active (i.e. not streamed out).
|
|
|
|
|
*/
|
|
|
|
|
UPROPERTY(config, EditAnywhere, Category = SmartObject, AdvancedDisplay)
|
|
|
|
|
bool bCanBePartOfCollection = false;
|
|
|
|
|
|
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
|
|
|
static FOnSmartObjectChanged OnSmartObjectChanged;
|
|
|
|
|
#endif // WITH_EDITORONLY_DATA
|
2021-09-28 13:33:00 -04:00
|
|
|
};
|
2022-02-03 13:28:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Used to store SmartObjectComponent data during RerunConstructionScripts */
|
|
|
|
|
USTRUCT()
|
|
|
|
|
struct FSmartObjectComponentInstanceData : public FActorComponentInstanceData
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FSmartObjectComponentInstanceData() = default;
|
|
|
|
|
|
|
|
|
|
explicit FSmartObjectComponentInstanceData(const USmartObjectComponent* SourceComponent, USmartObjectDefinition* Asset)
|
|
|
|
|
: FActorComponentInstanceData(SourceComponent)
|
|
|
|
|
, DefinitionAsset(Asset)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
USmartObjectDefinition* GetDefinitionAsset() const { return DefinitionAsset; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual bool ContainsData() const override;
|
|
|
|
|
virtual void ApplyToComponent(UActorComponent* Component, const ECacheApplyPhase CacheApplyPhase) override;
|
|
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
TObjectPtr<USmartObjectDefinition> DefinitionAsset = nullptr;
|
2023-01-25 02:42:36 -05:00
|
|
|
};
|