LEAP Documentation 40220
Documentation for the LEAP project
OwnedInterface.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "ProjectX.h"
7#include "GameFramework/PlayerState.h"
8#include "UObject/Interface.h"
9#include "Kismet/GameplayStatics.h"
10#include "OwnedInterface.generated.h"
11
12/* THIS INTERFACE SHOULD NEVER BE A BLUEPRINT TYPE (templated getting will become unusable!) */
13UINTERFACE(meta=(CannotImplementInterfaceInBlueprint))
14class PROJECTX_API UOwnedInterface : public UInterface
15{
16 GENERATED_UINTERFACE_BODY()
17};
18
19class PROJECTX_API IOwnedInterface
20{
21 GENERATED_IINTERFACE_BODY()
22
23public:
24 template <class T>
26 {
27 return Cast<T>(GetOwnedPlayerState());
28 }
29
30 UFUNCTION(BlueprintCallable, Category = PlayerOwnedInterface)
31 virtual APlayerState* GetOwnedPlayerState() const;
32
33 template <class T>
35 {
36 return Cast<T>(GetOwningController());
37 }
38
39 /* You only need to override this if you don't want this to return the owner of result of GetPlayerState() */
40 UFUNCTION(BlueprintCallable, Category = PlayerOwnedInterface)
41 virtual AController* GetOwningController() const;
42
43 UFUNCTION()
44 virtual void OnOwnerLeave() {}
45 UFUNCTION()
46 virtual void OnOwnerDied() {}
47};
48
49UCLASS()
50class PROJECTX_API UOwnedInterfaceHelper : public UObject
51{
52 GENERATED_BODY()
53
54public:
55 /* Returns all actors in the world that implement IPlayerOwnedInterface. */
56 static void GetPlayerOwnedActorList(const UObject* WorldContextObject, TArray<IOwnedInterface*>& ActorList);
57
58 /* Returns a PlayerState given an actor that implements the IPlayerOwnedInterface. */
59 UFUNCTION(BlueprintPure, Category = PlayerOwnedInterface)
60 static APlayerState* GetPlayerStateFromActor(const AActor* Actor);
61};
Definition: OwnedInterface.h:20
T * GetOwningController() const
Definition: OwnedInterface.h:34
T * GetOwnedPlayerState() const
Definition: OwnedInterface.h:25
Definition: OwnedInterface.h:51
Definition: OwnedInterface.h:15