Prototype of triggers and interaction
This commit is contained in:
parent
e77e2ee56f
commit
eb2e75f127
BIN
Pawn_Unreal/Content/Characters/BP_Judy.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Characters/BP_Judy.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Developers/maxim/BP_TriggerTest.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Developers/maxim/BP_TriggerTest.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/Editor/EditorResources/CameraModule.png
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Editor/EditorResources/CameraModule.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.png
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Editor/EditorResources/CameraTransitionModule.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/Editor/EditorResources/S_CameraModule.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Editor/EditorResources/S_CameraModule.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Editor/EditorResources/S_CameraTransition.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Editor/EditorResources/S_CameraTransition.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Editor/EditorResources/S_Trigger.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Editor/EditorResources/S_Trigger.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/Editor/EditorResources/Trigger.png
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Editor/EditorResources/Trigger.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Input/BP_MainPlayerController.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Input/IA_Interact.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/Input/IA_Interact.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/Input/IMC_Judy.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Input/IMC_Judy.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Systems/Camera/BP_CameraModule.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Systems/Camera/BP_CameraModule.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Systems/Camera/BP_CameraTransitionModule.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Systems/Camera/BP_CameraTransitionModule.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_01.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_01.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_02.uasset
(Stored with Git LFS)
BIN
Pawn_Unreal/Content/Template/Characters/Mannequins/Materials/Instances/Manny/MI_Manny_02.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/NQ/Z9R3R8MQW9G5EO9PP83XSR.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/4/NQ/Z9R3R8MQW9G5EO9PP83XSR.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/8/7W/AQ4UC1OCF6KAZ3S39U9JUS.uasset
(Stored with Git LFS)
Normal file
BIN
Pawn_Unreal/Content/__ExternalActors__/Maps/Dev/MAP_ControllerGym/8/7W/AQ4UC1OCF6KAZ3S39U9JUS.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
47
Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTrigger.cpp
Normal file
47
Pawn_Unreal/Source/Pawn/Private/Interaction/PwnTrigger.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include "Pawn/Public/Interaction/PwnTrigger.h"
|
||||
|
||||
#include "Components/ShapeComponent.h"
|
||||
#include "Pawn/Public/Interaction/PwnTriggerRegister.h"
|
||||
|
||||
UPwnTrigger::UPwnTrigger() {
|
||||
PrimaryComponentTick.bCanEverTick = false;
|
||||
}
|
||||
|
||||
void UPwnTrigger::BeginPlay() {
|
||||
Super::BeginPlay();
|
||||
VolumeComponent = Cast<UShapeComponent>(TriggerVolume.GetComponent(GetOwner()));
|
||||
if (ensure(VolumeComponent)) {
|
||||
VolumeComponent->OnComponentBeginOverlap.AddDynamic(this, &UPwnTrigger::OnOverlapBegin);
|
||||
VolumeComponent->OnComponentEndOverlap.AddDynamic(this, &UPwnTrigger::OnOverlapEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void UPwnTrigger::EndPlay(const EEndPlayReason::Type EndPlayReason) {
|
||||
Super::EndPlay(EndPlayReason);
|
||||
if (VolumeComponent) {
|
||||
VolumeComponent->OnComponentBeginOverlap.RemoveDynamic(this, &UPwnTrigger::OnOverlapBegin);
|
||||
VolumeComponent->OnComponentEndOverlap.RemoveDynamic(this, &UPwnTrigger::OnOverlapEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void UPwnTrigger::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult) {
|
||||
if (UPwnTriggerRegister* Register = OtherActor->GetComponentByClass<UPwnTriggerRegister>()) {
|
||||
Register->RegisterTrigger(this);
|
||||
}
|
||||
}
|
||||
|
||||
void UPwnTrigger::OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) {
|
||||
if (UPwnTriggerRegister* Register = OtherActor->GetComponentByClass<UPwnTriggerRegister>()) {
|
||||
Register->UnregisterTrigger(this);
|
||||
}
|
||||
}
|
||||
|
||||
FVector UPwnTrigger::GetVolumeCenter() const {
|
||||
if (ensure(VolumeComponent)) {
|
||||
VolumeComponent->Bounds.Origin;
|
||||
}
|
||||
return FVector::ZeroVector;
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
#include "Pawn/Public/Interaction/PwnTriggerRegister.h"
|
||||
|
||||
#include "Pawn/Public/Interaction/PwnTrigger.h"
|
||||
|
||||
UPwnTriggerRegister::UPwnTriggerRegister() {
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
PrimaryComponentTick.bStartWithTickEnabled = false;
|
||||
}
|
||||
|
||||
void UPwnTriggerRegister::BeginPlay() {
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void UPwnTriggerRegister::RegisterTrigger(UPwnTrigger* Trigger) {
|
||||
Triggers.AddUnique(Trigger);
|
||||
if (!Triggers.IsEmpty()) {
|
||||
SetComponentTickEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void UPwnTriggerRegister::UnregisterTrigger(UPwnTrigger* Trigger) {
|
||||
Triggers.Remove(Trigger);
|
||||
if (Triggers.IsEmpty()) {
|
||||
SetComponentTickEnabled(false);
|
||||
OnRelevantTriggerChanged.Broadcast(RelevantTrigger, nullptr);
|
||||
RelevantTrigger = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void UPwnTriggerRegister::TickComponent(float DeltaTime, ELevelTick TickType,
|
||||
FActorComponentTickFunction* ThisTickFunction) {
|
||||
UPwnTrigger* ClosestTrigger = nullptr;
|
||||
float ClosestDistance = TNumericLimits<float>::Max();
|
||||
for (UPwnTrigger* PwnTrigger : Triggers) {
|
||||
const float Distance = FVector::DistSquared2D(GetOwner()->GetActorLocation(), PwnTrigger->GetVolumeCenter());
|
||||
if (Distance < ClosestDistance) {
|
||||
ClosestDistance = Distance;
|
||||
ClosestTrigger = PwnTrigger;
|
||||
}
|
||||
}
|
||||
|
||||
if (ClosestTrigger != RelevantTrigger) {
|
||||
OnRelevantTriggerChanged.Broadcast(RelevantTrigger, ClosestTrigger);
|
||||
RelevantTrigger = ClosestTrigger;
|
||||
}
|
||||
}
|
||||
40
Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTrigger.h
Normal file
40
Pawn_Unreal/Source/Pawn/Public/Interaction/PwnTrigger.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "PwnTrigger.generated.h"
|
||||
|
||||
UCLASS(ClassGroup="Interaction",
|
||||
HideCategories=("Activation", "Cooking", "Replication", "Collision"),
|
||||
meta=(BlueprintSpawnableComponent, DisplayName="Trigger"))
|
||||
class PAWN_API UPwnTrigger : public UActorComponent {
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPwnTrigger();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
||||
|
||||
UFUNCTION()
|
||||
void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
||||
|
||||
UFUNCTION()
|
||||
void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
int32 OtherBodyIndex);
|
||||
|
||||
public:
|
||||
UFUNCTION()
|
||||
FVector GetVolumeCenter() const;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditAnywhere, meta=(UseComponentPicker, AllowedClasses="ShapeComponent"))
|
||||
FComponentReference TriggerVolume;
|
||||
|
||||
private:
|
||||
UPROPERTY(Transient)
|
||||
UShapeComponent* VolumeComponent;
|
||||
};
|
||||
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "PwnTriggerRegister.generated.h"
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FRelevantTriggerChanged, UPwnTrigger*, OldTrigger, UPwnTrigger*, NewTrigger);
|
||||
|
||||
class UPwnTrigger;
|
||||
|
||||
UCLASS(ClassGroup="Interaction",
|
||||
HideCategories=("Activation", "Cooking", "Replication", "Collision"),
|
||||
meta=(BlueprintSpawnableComponent, DisplayName="Trigger Register"))
|
||||
class PAWN_API UPwnTriggerRegister : public UActorComponent {
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPwnTriggerRegister();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
UFUNCTION()
|
||||
void RegisterTrigger(UPwnTrigger* Trigger);
|
||||
|
||||
UFUNCTION()
|
||||
void UnregisterTrigger(UPwnTrigger* Trigger);
|
||||
|
||||
public:
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
|
||||
FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FRelevantTriggerChanged OnRelevantTriggerChanged;
|
||||
|
||||
UPROPERTY(Transient)
|
||||
TArray<TObjectPtr<UPwnTrigger>> Triggers;
|
||||
|
||||
UPROPERTY(Transient, BlueprintReadOnly)
|
||||
UPwnTrigger* RelevantTrigger;
|
||||
};
|
||||
@ -1,9 +1,14 @@
|
||||
#include "PawnEditorModule.h"
|
||||
|
||||
#include "PwnStyle.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
IMPLEMENT_MODULE(FPawnEditorModule, PawnEditor)
|
||||
|
||||
void FPawnEditorModule::StartupModule() {}
|
||||
void FPawnEditorModule::StartupModule() {
|
||||
FPwnStyle::Initialize();
|
||||
}
|
||||
|
||||
void FPawnEditorModule::ShutdownModule() {}
|
||||
void FPawnEditorModule::ShutdownModule() {
|
||||
FPwnStyle::Shutdown();
|
||||
}
|
||||
59
Pawn_Unreal/Source/PawnEditor/PwnStyle.cpp
Normal file
59
Pawn_Unreal/Source/PawnEditor/PwnStyle.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "PwnStyle.h"
|
||||
|
||||
#include "Brushes/SlateImageBrush.h"
|
||||
#include "Misc/Paths.h"
|
||||
#include "Styling/SlateStyle.h"
|
||||
#include "Styling/SlateStyleRegistry.h"
|
||||
|
||||
TSharedPtr<FSlateStyleSet> FPwnStyle::StyleInstance = nullptr;
|
||||
|
||||
const FVector2D Icon16x16(16.0f, 16.0f);
|
||||
const FVector2D Icon20x20(20.0f, 20.0f);
|
||||
const FVector2D Icon40x40(40.0f, 40.0f);
|
||||
const FVector2D Icon64x64(64.0f, 64.0f);
|
||||
|
||||
void FPwnStyle::Initialize() {
|
||||
if (!StyleInstance.IsValid()) {
|
||||
StyleInstance = Create();
|
||||
FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance);
|
||||
}
|
||||
}
|
||||
|
||||
void FPwnStyle::Shutdown() {
|
||||
FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
|
||||
ensure(StyleInstance.IsUnique());
|
||||
StyleInstance.Reset();
|
||||
}
|
||||
|
||||
FName FPwnStyle::GetStyleSetName() {
|
||||
static FName StyleSetName(TEXT("PwnStyle"));
|
||||
return StyleSetName;
|
||||
}
|
||||
|
||||
#define IMAGE_BRUSH(RelativePath, ...) FSlateImageBrush(StyleRef->GetContentRootDir() / RelativePath + TEXT(".png"), __VA_ARGS__ )
|
||||
|
||||
#define SET_CPP_CLASS_ICON(ClassName, IconName) Style.Set("ClassIcon.##ClassName##", new IMAGE_BRUSH(IconName, Icon20x20));
|
||||
#define SET_BLUEPRINT_CLASS_ICON(ClassName, IconName) Style.Set("ClassIcon.BP_##ClassName##_C", new IMAGE_BRUSH(IconName, Icon20x20));
|
||||
|
||||
TSharedRef<FSlateStyleSet> FPwnStyle::Create() {
|
||||
TSharedRef<FSlateStyleSet> StyleRef = MakeShareable(new FSlateStyleSet(GetStyleSetName()));
|
||||
StyleRef->SetContentRoot(FPaths::ProjectContentDir() / TEXT("Editor/EditorResources"));
|
||||
StyleRef->SetCoreContentRoot(FPaths::ProjectContentDir() / TEXT("Editor/EditorResources"));
|
||||
|
||||
FSlateStyleSet& Style = StyleRef.Get();
|
||||
|
||||
SET_CPP_CLASS_ICON(PwnTrigger, "Trigger");
|
||||
|
||||
SET_BLUEPRINT_CLASS_ICON(CameraModule, "CameraModule");
|
||||
SET_BLUEPRINT_CLASS_ICON(CameraTransitionModule, "CameraTransitionModule");
|
||||
|
||||
return StyleRef;
|
||||
}
|
||||
|
||||
#undef IMAGE_BRUSH
|
||||
#undef BOX_BRUSH
|
||||
#undef BORDER_BRUSH
|
||||
|
||||
const ISlateStyle& FPwnStyle::Get() {
|
||||
return *StyleInstance;
|
||||
}
|
||||
22
Pawn_Unreal/Source/PawnEditor/PwnStyle.h
Normal file
22
Pawn_Unreal/Source/PawnEditor/PwnStyle.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "Templates/SharedPointer.h"
|
||||
|
||||
class ISlateStyle;
|
||||
|
||||
class FPwnStyle {
|
||||
public:
|
||||
static void Initialize();
|
||||
|
||||
static void Shutdown();
|
||||
|
||||
static const ISlateStyle& Get();
|
||||
|
||||
static FName GetStyleSetName();
|
||||
|
||||
private:
|
||||
static TSharedRef<FSlateStyleSet> Create();
|
||||
|
||||
private:
|
||||
static TSharedPtr<FSlateStyleSet> StyleInstance;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user