Guest User

Untitled

a guest
Oct 4th, 2016
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // FunctionInterface.h ///////////////////////////////////////////////
  4.  
  5. #pragma once
  6.  
  7. #include "FunctionInterface.generated.h"
  8.  
  9.  
  10. UINTERFACE(Blueprintable, MinimalAPI)
  11. class UFunctionInterface : public UInterface
  12. {
  13. GENERATED_UINTERFACE_BODY()
  14. };
  15.  
  16. class IFunctionInterface
  17. {
  18. GENERATED_IINTERFACE_BODY()
  19.  
  20. public:
  21.  
  22. UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Functions")
  23. float FunctionFloat01();
  24.  
  25. UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Functions")
  26. void Interfacable();
  27.  
  28. };
  29.  
  30. ////////////////////////////////////////////////////////////////////////////////////////////////
  31. //
  32. // FunctionInterface.cpp ////////////////////////////////////////////////
  33.  
  34. #pragma once
  35.  
  36. #include "Thesis_Test_002.h"
  37. #include "FunctionInterface.h"
  38.  
  39.  
  40. UFunctionInterface::UFunctionInterface(const FObjectInitializer& ObjectInitializer)
  41. :Super(ObjectInitializer)
  42. {
  43. }
  44.  
  45. ////////////////////////////////////////////////////////////////////////////////////////////////
  46. //
  47. // BaseTest.h ////////////////////////////////////////////////
  48.  
  49. #pragma once
  50.  
  51. #include "GameFramework/Actor.h"
  52. #include "FunctionInterface.h"
  53. #include "BaseTest.generated.h"
  54.  
  55. UCLASS()
  56. class ABaseTest : public AActor, public IFunctionInterface
  57. {
  58. GENERATED_BODY()
  59.  
  60. public:
  61. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Functions")
  62. float InterfaceFloat;
  63. ABaseTest();
  64. virtual void BeginPlay() override;
  65. virtual void Tick( float DeltaSeconds ) override;
  66.  
  67. virtual float FunctionFloat01_Implementation() override;
  68.  
  69. virtual void Interfacable_Implementation() override;
  70.  
  71. };
  72.  
  73. ////////////////////////////////////////////////////////////////////////////////////////////////
  74. //
  75. // BaseTest.cpp ////////////////////////////////////////////////
  76.  
  77. #include "Thesis_Test_002.h"
  78. #include "BaseTest.h"
  79.  
  80. ABaseTest::ABaseTest()
  81. {
  82. PrimaryActorTick.bCanEverTick = true;
  83.  
  84. InterfaceFloat = 2;
  85.  
  86. }
  87.  
  88. void ABaseTest::BeginPlay()
  89. {
  90. Super::BeginPlay();
  91.  
  92. }
  93.  
  94. void ABaseTest::Tick( float DeltaTime )
  95. {
  96. Super::Tick( DeltaTime );
  97.  
  98. }
  99.  
  100.  
  101. float ABaseTest::FunctionFloat01_Implementation()
  102. {
  103. return InterfaceFloat;
  104. }
  105.  
  106. void ABaseTest::Interfacable_Implementation()
  107. {
  108. GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Interface working"));
  109. }
  110.  
  111. ////////////////////////////////////////////////////////////////////////////////////////////////
  112. //
  113. // MasterCube.h ////////////////////////////////////////////////
  114.  
  115. #pragma once
  116.  
  117. #include "GameFramework/Actor.h"
  118. #include "MasterTrail.h"
  119. #include "BaseTest.h"
  120. #include "MasterCube.generated.h"
  121.  
  122.  
  123. UCLASS()
  124. class THESIS_TEST_002_API AMasterCube : public AActor
  125. {
  126. GENERATED_BODY()
  127.  
  128. public:
  129. // Sets default values for this actor's properties
  130. AMasterCube();
  131.  
  132. // Called when the game starts or when spawned
  133. virtual void BeginPlay() override;
  134.  
  135. // Called every frame
  136. virtual void Tick( float DeltaSeconds ) override;
  137.  
  138. IFunctionInterface* Functions = NewObject<ABaseTest>(StaticClass());
  139.  
  140. ABaseTest* BaseTestptr = Cast<ABaseTest>(Functions);
  141.  
  142. UPROPERTY(EditAnywhere, Category = Spawn)
  143. USphereComponent* RootNull;
  144.  
  145. };
  146.  
  147. ////////////////////////////////////////////////////////////////////////////////////////////////
  148. //
  149. // MasterCube.cpp ////////////////////////////////////////////////
  150.  
  151. #include "Thesis_Test_002.h"
  152. #include "MasterTrail.h"
  153. #include "BaseTest.h"
  154. #include "Engine.h"
  155. #include "MasterCube.h"
  156.  
  157.  
  158. // Sets default values
  159. AMasterCube::AMasterCube()
  160. {
  161. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
  162. PrimaryActorTick.bCanEverTick = true;
  163.  
  164. RootComponent = RootNull;
  165.  
  166. if (Functions != NULL)
  167. {
  168. //Functions = GetWorld()->SpawnActor<ABaseTest>(StaticClass());
  169. GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("valid"));
  170.  
  171. }
  172. else
  173. {
  174. GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("invalid"));
  175. }
  176.  
  177.  
  178. }
  179.  
  180. // Called when the game starts or when spawned
  181. void AMasterCube::BeginPlay()
  182. {
  183. Super::BeginPlay();
  184.  
  185. //Functions->Interfacable_Implementation();
  186.  
  187. }
  188.  
  189. // Called every frame
  190. void AMasterCube::Tick( float DeltaTime )
  191. {
  192. Super::Tick( DeltaTime );
  193. }
Advertisement
Add Comment
Please, Sign In to add comment