Advertisement
Guest User

TutSeePeePee

a guest
Feb 28th, 2017
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #pragma once
  4.  
  5. #include "GameFramework/Actor.h"
  6. #include "TutorialProject.h"
  7. #include "InteractableActor.generated.h"
  8.  
  9. UCLASS()
  10. class TUTORIALPROJECT_API AInteractableActor : public AActor
  11. {
  12. GENERATED_BODY()
  13.  
  14. public:
  15. // Sets default values for this actor's properties
  16. AInteractableActor();
  17.  
  18. UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Interaction);
  19. void OnInteract(AActor* Caller);
  20.  
  21.  
  22. virtual void OnInteract_Implementation(AActor* Caller);
  23.  
  24. void OnBeginFocus();
  25. void OnEndFocus();
  26.  
  27. protected:
  28. // Called when the game starts or when spawned
  29. virtual void BeginPlay() override;
  30.  
  31. public:
  32.  
  33. // Called every frame
  34. virtual void Tick(float DeltaTime) override;
  35.  
  36. private:
  37. uint32 bCanInteract : 1;
  38. TArray<class UMeshComponent*> Meshes;
  39. EStencilColor Color = EStencilColor::SC_Blue;
  40. };
  41.  
  42.  
  43. // Fill out your copyright notice in the Description page of Project Settings.
  44.  
  45. #include "TutorialProject.h"
  46. #include "InteractableActor.h"
  47. #include "Avatar.h"
  48.  
  49. // Sets default values
  50. AInteractableActor::AInteractableActor()
  51. {
  52. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
  53. PrimaryActorTick.bCanEverTick = true;
  54.  
  55. }
  56.  
  57. // Called when the game starts or when spawned
  58. void AInteractableActor::BeginPlay()
  59. {
  60. Super::BeginPlay();
  61.  
  62. for (UActorComponent* Mesh: GetComponentsByClass(UMeshComponent::StaticClass()))
  63. {
  64. UMeshComponent* thisMesh = Cast<UMeshComponent>(Mesh);
  65. if (thisMesh)
  66. {
  67. Meshes.Push(thisMesh);
  68. }
  69. }
  70. }
  71.  
  72.  
  73. // Called every frame
  74. void AInteractableActor::Tick(float DeltaTime)
  75. {
  76. Super::Tick(DeltaTime);
  77.  
  78. }
  79.  
  80. void AInteractableActor::OnInteract_Implementation(AActor* Caller) {
  81.  
  82. AAvatar* Player = Cast<AAvatar>(Caller);
  83. if (Player)
  84. {
  85. UE_LOG(LogTemp, Warning, TEXT("Now Interacting"));
  86. Destroy();
  87. }
  88.  
  89. }
  90.  
  91. void AInteractableActor::OnBeginFocus()
  92. {
  93. if (bCanInteract)
  94. {
  95. for (UMeshComponent* Mesh : Meshes)
  96. {
  97. Mesh->SetRenderCustomDepth(true);
  98. Mesh->SetCustomDepthStencilValue((uint8)Color);
  99. }
  100. }
  101.  
  102. }
  103.  
  104. void AInteractableActor::OnEndFocus()
  105. {
  106. for (UMeshComponent* Mesh : Meshes)
  107. {
  108. Mesh->SetRenderCustomDepth(false);
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement