Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // FunctionInterface.h ///////////////////////////////////////////////
- #pragma once
- #include "FunctionInterface.generated.h"
- UINTERFACE(Blueprintable, MinimalAPI)
- class UFunctionInterface : public UInterface
- {
- GENERATED_UINTERFACE_BODY()
- };
- class IFunctionInterface
- {
- GENERATED_IINTERFACE_BODY()
- public:
- UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Functions")
- float FunctionFloat01();
- UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Functions")
- void Interfacable();
- };
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // FunctionInterface.cpp ////////////////////////////////////////////////
- #pragma once
- #include "Thesis_Test_002.h"
- #include "FunctionInterface.h"
- UFunctionInterface::UFunctionInterface(const FObjectInitializer& ObjectInitializer)
- :Super(ObjectInitializer)
- {
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // BaseTest.h ////////////////////////////////////////////////
- #pragma once
- #include "GameFramework/Actor.h"
- #include "FunctionInterface.h"
- #include "BaseTest.generated.h"
- UCLASS()
- class ABaseTest : public AActor, public IFunctionInterface
- {
- GENERATED_BODY()
- public:
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Functions")
- float InterfaceFloat;
- ABaseTest();
- virtual void BeginPlay() override;
- virtual void Tick( float DeltaSeconds ) override;
- virtual float FunctionFloat01_Implementation() override;
- virtual void Interfacable_Implementation() override;
- };
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // BaseTest.cpp ////////////////////////////////////////////////
- #include "Thesis_Test_002.h"
- #include "BaseTest.h"
- ABaseTest::ABaseTest()
- {
- PrimaryActorTick.bCanEverTick = true;
- InterfaceFloat = 2;
- }
- void ABaseTest::BeginPlay()
- {
- Super::BeginPlay();
- }
- void ABaseTest::Tick( float DeltaTime )
- {
- Super::Tick( DeltaTime );
- }
- float ABaseTest::FunctionFloat01_Implementation()
- {
- return InterfaceFloat;
- }
- void ABaseTest::Interfacable_Implementation()
- {
- GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Interface working"));
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // MasterCube.h ////////////////////////////////////////////////
- #pragma once
- #include "GameFramework/Actor.h"
- #include "MasterTrail.h"
- #include "BaseTest.h"
- #include "MasterCube.generated.h"
- UCLASS()
- class THESIS_TEST_002_API AMasterCube : public AActor
- {
- GENERATED_BODY()
- public:
- // Sets default values for this actor's properties
- AMasterCube();
- // Called when the game starts or when spawned
- virtual void BeginPlay() override;
- // Called every frame
- virtual void Tick( float DeltaSeconds ) override;
- IFunctionInterface* Functions = NewObject<ABaseTest>(StaticClass());
- ABaseTest* BaseTestptr = Cast<ABaseTest>(Functions);
- UPROPERTY(EditAnywhere, Category = Spawn)
- USphereComponent* RootNull;
- };
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // MasterCube.cpp ////////////////////////////////////////////////
- #include "Thesis_Test_002.h"
- #include "MasterTrail.h"
- #include "BaseTest.h"
- #include "Engine.h"
- #include "MasterCube.h"
- // Sets default values
- AMasterCube::AMasterCube()
- {
- // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
- PrimaryActorTick.bCanEverTick = true;
- RootComponent = RootNull;
- if (Functions != NULL)
- {
- //Functions = GetWorld()->SpawnActor<ABaseTest>(StaticClass());
- GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("valid"));
- }
- else
- {
- GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("invalid"));
- }
- }
- // Called when the game starts or when spawned
- void AMasterCube::BeginPlay()
- {
- Super::BeginPlay();
- //Functions->Interfacable_Implementation();
- }
- // Called every frame
- void AMasterCube::Tick( float DeltaTime )
- {
- Super::Tick( DeltaTime );
- }
Advertisement
Add Comment
Please, Sign In to add comment