Advertisement
Guest User

Untitled

a guest
May 26th, 2017
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //--- Controller.h
  2. // Fill out your copyright notice in the Description page of Project Settings.
  3.  
  4. #pragma once
  5.  
  6. #include "GameFramework/PlayerController.h"
  7. #include "BaseUnit.h"
  8. #include "StrategyPlayerController.generated.h"
  9.  
  10. /**
  11.  *
  12.  */
  13. UCLASS()
  14. class THROWAWAY_API AStrategyPlayerController : public APlayerController
  15. {
  16.     GENERATED_BODY()
  17.    
  18. public:
  19.     UPROPERTY(EditAnywhere, BlueprintReadWrite)
  20.         TSet<ACharacter*> SelectedUnits;
  21.    
  22.     void AddSelectedUnit(ABaseUnit* unit);
  23.  
  24.     void LogAllSelectedUnits();
  25.  
  26. };
  27.  
  28.  
  29.  
  30. //--- Controller cpp
  31. // Fill out your copyright notice in the Description page of Project Settings.
  32.  
  33. #include "ThrowAway.h"
  34. #include "StrategyPlayerController.h"
  35. #include "BaseUnit.h"
  36.  
  37.  
  38.  
  39.  
  40. void AStrategyPlayerController::AddSelectedUnit(ABaseUnit* unit)
  41. {
  42.     bool inSet;
  43.     SelectedUnits.Add(unit, &inSet);
  44.     LogAllSelectedUnits();
  45. }
  46.  
  47. void AStrategyPlayerController::LogAllSelectedUnits()
  48. {
  49.     for (auto* u : SelectedUnits)
  50.     {
  51.         UE_LOG(LogTemp, Warning, TEXT("%s"), *u->GetName());
  52.     }
  53. }
  54.  
  55.  
  56. //--- BaseUnit .h
  57.  
  58. // Fill out your copyright notice in the Description page of Project Settings.
  59.  
  60. #pragma once
  61.  
  62. #include "GameFramework/Character.h"
  63. #include "BaseUnit.generated.h"
  64.  
  65. UCLASS()
  66. class THROWAWAY_API ABaseUnit : public ACharacter
  67. {
  68.     GENERATED_BODY()
  69.  
  70. public:
  71.     // Sets default values for this character's properties
  72.     ABaseUnit();
  73.  
  74. protected:
  75.     // Called when the game starts or when spawned
  76.     virtual void BeginPlay() override;
  77.  
  78. public:
  79.     // Called every frame
  80.     virtual void Tick(float DeltaTime) override;
  81.  
  82.     // Called to bind functionality to input
  83.     virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
  84.  
  85.    
  86.    
  87. };
  88.  
  89.  
  90. //--- BaseUnit .cpp
  91.  
  92. // Fill out your copyright notice in the Description page of Project Settings.
  93.  
  94. #include "ThrowAway.h"
  95. #include "BaseUnit.h"
  96. #include "StrategyPlayerController.h"
  97.  
  98.  
  99. // Sets default values
  100. ABaseUnit::ABaseUnit()
  101. {
  102.     // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  103.     PrimaryActorTick.bCanEverTick = true;
  104.  
  105. }
  106.  
  107. // Called when the game starts or when spawned
  108. void ABaseUnit::BeginPlay()
  109. {
  110.     Super::BeginPlay();
  111.     if (GetWorld())
  112.     {
  113.         APlayerController* p = GetWorld()->GetFirstPlayerController();
  114.         if (p)
  115.         {
  116.             AStrategyPlayerController* spc = Cast<AStrategyPlayerController>(p);
  117.             spc->AddSelectedUnit(this);
  118.         }
  119.     }
  120. }
  121.  
  122. // Called every frame
  123. void ABaseUnit::Tick(float DeltaTime)
  124. {
  125.     Super::Tick(DeltaTime);
  126.  
  127. }
  128.  
  129. // Called to bind functionality to input
  130. void ABaseUnit::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
  131. {
  132.     Super::SetupPlayerInputComponent(PlayerInputComponent);
  133.  
  134. }
Advertisement
RAW Paste Data Copied
Advertisement