A hell of a lot of work just happened here. Don't even ask.

This commit is contained in:
Jamie Greunbaum
2023-03-18 18:44:42 -04:00
parent 39d05a6435
commit 0313ff4f7f
27 changed files with 233 additions and 6 deletions
@@ -0,0 +1,6 @@
// ©2022 Batty Bovine Productions, LLC. All Rights Reserved.
#include "BugMarkerActor.h"
+112 -1
View File
@@ -2,6 +2,10 @@
#include "BugPlacerPawn.h"
#include "BugMarkerActor.h"
#include "UnrealzillaGlobalSettings.h"
#include "Components/MaterialBillboardComponent.h"
#include "Components/SphereComponent.h"
#include "GameFramework/Character.h"
#include "GameFramework/FloatingPawnMovement.h"
@@ -12,14 +16,26 @@ ABugPlacerPawn::ABugPlacerPawn()
{
this->PrimaryActorTick.bCanEverTick = true;
this->bArbitraryPlacement = false;
this->bCurrentTraceHit = false;
this->SphereComponent = CreateDefaultSubobject<USphereComponent>("SphereCollision");
this->SphereComponent->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName);
this->SphereComponent->CanCharacterStepUpOn = ECanBeCharacterBase::ECB_No;
this->SphereComponent->SetShouldUpdatePhysicsVolume(true);
this->SphereComponent->SetCanEverAffectNavigation(false);
this->SphereComponent->bDynamicObstacle = true;
this->SphereComponent->bDynamicObstacle = false;
this->RootComponent = this->SphereComponent;
this->PlacementMarkerRoot = CreateDefaultSubobject<USceneComponent>("PlacementMarkerRoot");
this->PlacementMarkerRoot->AttachToComponent(this->RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
this->LaserGlow = CreateDefaultSubobject<UMaterialBillboardComponent>("LaserGlow");
this->LaserGlow->AttachToComponent(this->PlacementMarkerRoot, FAttachmentTransformRules::KeepRelativeTransform);
this->TraceOriginComponent = CreateDefaultSubobject<USceneComponent>("TraceOrigin");
this->TraceOriginComponent->AttachToComponent(this->RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
this->PawnMovement = CreateDefaultSubobject<UFloatingPawnMovement>("MovementComponent");
if (this->PawnMovement)
{
@@ -34,6 +50,17 @@ void ABugPlacerPawn::BeginPlay()
this->OriginalPlayer = UGameplayStatics::GetPlayerCharacter(this, 0);
// Create the bug marker we will be placing.
if (this->BugPlacerBlueprintClass.IsValid())
{
FActorSpawnParameters SpawnParams;
SpawnParams.Name = TEXT("BugMarker");
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
SpawnParams.bHideFromSceneOutliner = true;
this->BugMarker = this->GetWorld()->SpawnActor<ABugMarkerActor>(this->BugPlacerBlueprintClass.Get(), this->SphereComponent->GetComponentTransform(), SpawnParams);
this->BugMarker->AttachToComponent(this->PlacementMarkerRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
}
this->Activate();
Super::BeginPlay();
@@ -47,6 +74,90 @@ void ABugPlacerPawn::EndPlay(const EEndPlayReason::Type EndPlayReason)
Super::EndPlay(EndPlayReason);
}
void ABugPlacerPawn::Tick(float DeltaSeconds)
{
const UWorld *World = this->GetWorld();
if (this->bArbitraryPlacement)
{
this->TraceOriginComponent->SetVisibility(false, true);
this->PlacementMarkerRoot->SetVisibility(true, true);
this->LaserGlow->SetVisibility(false, true);
// If the debugger requests arbitrary placement, put the marker a set distance away from the camera.
this->PlacementMarkerRoot->SetRelativeLocationAndRotation(FVector(GetDefault<UUnrealzillaGlobalSettings>()->ArbitraryBugPlacementDistance, 0.0f, 0.0f), FRotator::ZeroRotator);
}
else
{
// Under normal circumstances, we place the marker at the point where a laser hits a surface.
this->TraceOriginComponent->SetVisibility(true, true);
this->LaserGlow->SetVisibility(true, true);
FCollisionQueryParams Params;
Params.bTraceComplex = false;
Params.AddIgnoredActor(this);
FHitResult TraceHit;
const FVector TraceStart = this->TraceOriginComponent->GetComponentLocation();
const FVector TraceEnd = TraceStart + (this->TraceOriginComponent->GetForwardVector() * GetDefault<UUnrealzillaGlobalSettings>()->BugPlacementTraceDistance);
this->bCurrentTraceHit = World->LineTraceSingleByChannel(TraceHit, TraceStart, TraceEnd, ECollisionChannel::ECC_Visibility, Params);
// Move bug marker to the current pointer position, or behind
// the camera if the pointer is not currently hitting a surface.
if (this->bCurrentTraceHit)
{
this->PlacementMarkerRoot->SetWorldLocationAndRotation(TraceHit.ImpactPoint, FRotationMatrix::MakeFromZ(TraceHit.ImpactNormal).ToQuat());
this->PlacementMarkerRoot->SetVisibility(true, true);
this->TraceOriginComponent->SetRelativeScale3D(FVector(1.0f, 1.0f, (TraceHit.ImpactPoint - TraceStart).Length()));
}
else
{
this->PlacementMarkerRoot->SetRelativeLocationAndRotation(FVector::ZeroVector, FRotator::ZeroRotator);
this->PlacementMarkerRoot->SetVisibility(false, true);
this->TraceOriginComponent->SetRelativeScale3D(FVector(1.0f, 1.0f, (TraceEnd - TraceStart).Length()));
}
//#if ENABLE_DRAW_DEBUG
// if (bTraceHit && TraceHit.bBlockingHit)
// {
// // Line trace and impact point
// DrawDebugLine(World, TraceStart, TraceHit.ImpactPoint, FColor::Red, false);
// DrawDebugLine(World, TraceHit.ImpactPoint, TraceEnd, FColor::Green, false);
// DrawDebugPoint(World, TraceHit.ImpactPoint, 10.0f, FColor::Red, false);
//
// // Impact normal
// DrawDebugLine(World, TraceHit.ImpactPoint, TraceHit.ImpactPoint + (TraceHit.ImpactNormal * 50.0f), FColor(0, 100, 255, 255), false);
// }
// else
// {
// // Line trace, no impact
// DrawDebugLine(World, TraceStart, TraceEnd, FColor::Red, false);
// }
//#endif
}
}
void ABugPlacerPawn::SetArbitraryPlacement(bool bSet)
{
this->bArbitraryPlacement = bSet;
}
void ABugPlacerPawn::PlaceBugMarker()
{
// If there is a surface onto which to place a bug actor, then do so here.
if (this->bArbitraryPlacement || this->bCurrentTraceHit)
{
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
SpawnParams.bHideFromSceneOutliner = true;
this->GetWorld()->SpawnActor<ABugMarkerActor>(this->BugPlacerBlueprintClass.Get(), this->PlacementMarkerRoot->GetComponentTransform(), SpawnParams);
}
}
void ABugPlacerPawn::Activate()
{
@@ -0,0 +1,26 @@
// ©2022 Batty Bovine Productions, LLC. All Rights Reserved.
#include "UnrealzillaGlobalSettings.h"
void UUnrealzillaGlobalSettings::PostInitProperties()
{
Super::PostInitProperties();
}
FName UUnrealzillaGlobalSettings::GetCategoryName() const
{
return FName(TEXT("Plugins"));
}
#if WITH_EDITOR
void UUnrealzillaGlobalSettings::PostEditChangeProperty(FPropertyChangedEvent &PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if (PropertyChangedEvent.Property)
{
this->ExportValuesToConsoleVariables(PropertyChangedEvent.Property);
}
}
#endif
@@ -0,0 +1,19 @@
// ©2022 Batty Bovine Productions, LLC. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "BugMarkerActor.generated.h"
UCLASS()
class UNREALZILLA_API ABugMarkerActor : public AActor
{
GENERATED_BODY()
public:
DECLARE_DELEGATE(FMarkerResponse)
FMarkerResponse OnFormSubmit;
FMarkerResponse OnFormCancelled;
};
+37 -4
View File
@@ -19,6 +19,8 @@ public:
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void Tick(float DeltaSeconds) override;
UFUNCTION(BlueprintCallable)
void Activate();
@@ -26,15 +28,46 @@ public:
void Deactivate();
protected:
UFUNCTION(BlueprintCallable)
void SetArbitraryPlacement(bool bSet);
UFUNCTION(BlueprintCallable)
void PlaceBugMarker();
// Collision sphere, and root component
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
TObjectPtr<class USphereComponent> SphereComponent;
// Follows the collision point of a line trace, and indicates where the bug marker will be placed.
UPROPERTY(BlueprintReadOnly, EditAnywhere)
TObjectPtr<class USceneComponent> PlacementMarkerRoot;
// The glowing end point of the laser, to indicate a surface where a marker can be placed.
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly)
TObjectPtr<class UMaterialBillboardComponent> LaserGlow;
// The origin of our line trace; line extends from this origin position along the component's
// forward vector a set distance to check for surfaces where a bug marker can be placed.
UPROPERTY(BlueprintReadOnly, EditAnywhere)
TObjectPtr<class USceneComponent> TraceOriginComponent;
// Basic movement component to allow the bug placer to fly through a level.
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
TObjectPtr<class UFloatingPawnMovement> PawnMovement;
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly)
TSoftClassPtr<class ABugMarkerActor> BugPlacerBlueprintClass;
UPROPERTY(BlueprintReadWrite)
float SavedMaxSpeed = 0.0f;
private:
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta=(AllowPrivateAccess="true"))
TObjectPtr<class USphereComponent> SphereComponent;
uint8 bArbitraryPlacement : 1;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta=(AllowPrivateAccess="true"))
TObjectPtr<class UFloatingPawnMovement> PawnMovement;
uint8 bCurrentTraceHit : 1;
TObjectPtr<class ACharacter> OriginalPlayer;
TObjectPtr<class ABugMarkerActor> BugMarker;
};
@@ -0,0 +1,31 @@
// ©2022 Batty Bovine Productions, LLC. All Rights Reserved.
#pragma once
#include "Engine/DeveloperSettingsBackedByCVars.h"
#include "UnrealzillaGlobalSettings.generated.h"
/**
* Global settings for Unrealzilla classes
*/
UCLASS(Config=Game, defaultconfig, meta = (DisplayName="Unrealzilla"))
class UNREALZILLA_API UUnrealzillaGlobalSettings : public UDeveloperSettingsBackedByCVars
{
GENERATED_BODY()
public:
UPROPERTY(Config, BlueprintReadOnly, EditDefaultsOnly, Category="Unrealzilla")
float BugPlacementTraceDistance = 1000.0f;
UPROPERTY(Config, BlueprintReadOnly, EditDefaultsOnly, Category="Unrealzilla")
float ArbitraryBugPlacementDistance = 250.0f;
public:
virtual void PostInitProperties() override;
virtual FName GetCategoryName() const override;
#if WITH_EDITOR
virtual void PostEditChangeProperty(struct FPropertyChangedEvent &PropertyChangedEvent) override;
#endif
};
+2 -1
View File
@@ -31,7 +31,8 @@ namespace UnrealBuildTool.Rules
"CoreUObject",
"Engine",
"InputCore",
}
"DeveloperSettings"
}
);
PrivateDependencyModuleNames.AddRange(