Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--- Controller.h
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "GameFramework/PlayerController.h"
- #include "BaseUnit.h"
- #include "StrategyPlayerController.generated.h"
- /**
- *
- */
- UCLASS()
- class THROWAWAY_API AStrategyPlayerController : public APlayerController
- {
- GENERATED_BODY()
- public:
- UPROPERTY(EditAnywhere, BlueprintReadWrite)
- TSet<ACharacter*> SelectedUnits;
- void AddSelectedUnit(ABaseUnit* unit);
- void LogAllSelectedUnits();
- };
- //--- Controller cpp
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "ThrowAway.h"
- #include "StrategyPlayerController.h"
- #include "BaseUnit.h"
- void AStrategyPlayerController::AddSelectedUnit(ABaseUnit* unit)
- {
- bool inSet;
- SelectedUnits.Add(unit, &inSet);
- LogAllSelectedUnits();
- }
- void AStrategyPlayerController::LogAllSelectedUnits()
- {
- for (auto* u : SelectedUnits)
- {
- UE_LOG(LogTemp, Warning, TEXT("%s"), *u->GetName());
- }
- }
- //--- BaseUnit .h
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "GameFramework/Character.h"
- #include "BaseUnit.generated.h"
- UCLASS()
- class THROWAWAY_API ABaseUnit : public ACharacter
- {
- GENERATED_BODY()
- public:
- // Sets default values for this character's properties
- ABaseUnit();
- protected:
- // Called when the game starts or when spawned
- virtual void BeginPlay() override;
- public:
- // Called every frame
- virtual void Tick(float DeltaTime) override;
- // Called to bind functionality to input
- virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
- };
- //--- BaseUnit .cpp
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "ThrowAway.h"
- #include "BaseUnit.h"
- #include "StrategyPlayerController.h"
- // Sets default values
- ABaseUnit::ABaseUnit()
- {
- // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
- PrimaryActorTick.bCanEverTick = true;
- }
- // Called when the game starts or when spawned
- void ABaseUnit::BeginPlay()
- {
- Super::BeginPlay();
- if (GetWorld())
- {
- APlayerController* p = GetWorld()->GetFirstPlayerController();
- if (p)
- {
- AStrategyPlayerController* spc = Cast<AStrategyPlayerController>(p);
- spc->AddSelectedUnit(this);
- }
- }
- }
- // Called every frame
- void ABaseUnit::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- }
- // Called to bind functionality to input
- void ABaseUnit::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
- {
- Super::SetupPlayerInputComponent(PlayerInputComponent);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement