feat: initial commit
This commit is contained in:
		
							
								
								
									
										15
									
								
								Source/UTAD_UI.Target.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Source/UTAD_UI.Target.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| using UnrealBuildTool; | ||||
| using System.Collections.Generic; | ||||
|  | ||||
| public class UTAD_UITarget : TargetRules | ||||
| { | ||||
| 	public UTAD_UITarget(TargetInfo Target) : base(Target) | ||||
| 	{ | ||||
| 		Type = TargetType.Game; | ||||
| 		DefaultBuildSettings = BuildSettingsVersion.V5; | ||||
| 		IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_5; | ||||
| 		ExtraModuleNames.Add("UTAD_UI"); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										13
									
								
								Source/UTAD_UI/UTAD_UI.Build.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Source/UTAD_UI/UTAD_UI.Build.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| using UnrealBuildTool; | ||||
|  | ||||
| public class UTAD_UI : ModuleRules | ||||
| { | ||||
| 	public UTAD_UI(ReadOnlyTargetRules Target) : base(Target) | ||||
| 	{ | ||||
| 		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; | ||||
|  | ||||
|         PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "NavigationSystem", "AIModule", "Niagara", "EnhancedInput" }); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										9
									
								
								Source/UTAD_UI/UTAD_UI.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								Source/UTAD_UI/UTAD_UI.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #include "UTAD_UI.h" | ||||
| #include "Modules/ModuleManager.h" | ||||
|  | ||||
| IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, UTAD_UI, "UTAD_UI" ); | ||||
|  | ||||
| DEFINE_LOG_CATEGORY(LogUTAD_UI) | ||||
|   | ||||
							
								
								
									
										7
									
								
								Source/UTAD_UI/UTAD_UI.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Source/UTAD_UI/UTAD_UI.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
|  | ||||
| DECLARE_LOG_CATEGORY_EXTERN(LogUTAD_UI, Log, All); | ||||
							
								
								
									
										51
									
								
								Source/UTAD_UI/UTAD_UICharacter.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								Source/UTAD_UI/UTAD_UICharacter.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #include "UTAD_UICharacter.h" | ||||
| #include "UObject/ConstructorHelpers.h" | ||||
| #include "Camera/CameraComponent.h" | ||||
| #include "Components/DecalComponent.h" | ||||
| #include "Components/CapsuleComponent.h" | ||||
| #include "GameFramework/CharacterMovementComponent.h" | ||||
| #include "GameFramework/PlayerController.h" | ||||
| #include "GameFramework/SpringArmComponent.h" | ||||
| #include "Materials/Material.h" | ||||
| #include "Engine/World.h" | ||||
|  | ||||
| AUTAD_UICharacter::AUTAD_UICharacter() | ||||
| { | ||||
| 	// Set size for player capsule | ||||
| 	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); | ||||
|  | ||||
| 	// Don't rotate character to camera direction | ||||
| 	bUseControllerRotationPitch = false; | ||||
| 	bUseControllerRotationYaw = false; | ||||
| 	bUseControllerRotationRoll = false; | ||||
|  | ||||
| 	// Configure character movement | ||||
| 	GetCharacterMovement()->bOrientRotationToMovement = true; // Rotate character to moving direction | ||||
| 	GetCharacterMovement()->RotationRate = FRotator(0.f, 640.f, 0.f); | ||||
| 	GetCharacterMovement()->bConstrainToPlane = true; | ||||
| 	GetCharacterMovement()->bSnapToPlaneAtStart = true; | ||||
|  | ||||
| 	// Create a camera boom... | ||||
| 	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); | ||||
| 	CameraBoom->SetupAttachment(RootComponent); | ||||
| 	CameraBoom->SetUsingAbsoluteRotation(true); // Don't want arm to rotate when character does | ||||
| 	CameraBoom->TargetArmLength = 800.f; | ||||
| 	CameraBoom->SetRelativeRotation(FRotator(-60.f, 0.f, 0.f)); | ||||
| 	CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level | ||||
|  | ||||
| 	// Create a camera... | ||||
| 	TopDownCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera")); | ||||
| 	TopDownCameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); | ||||
| 	TopDownCameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm | ||||
|  | ||||
| 	// Activate ticking in order to update the cursor every frame. | ||||
| 	PrimaryActorTick.bCanEverTick = true; | ||||
| 	PrimaryActorTick.bStartWithTickEnabled = true; | ||||
| } | ||||
|  | ||||
| void AUTAD_UICharacter::Tick(float DeltaSeconds) | ||||
| { | ||||
|     Super::Tick(DeltaSeconds); | ||||
| } | ||||
							
								
								
									
										34
									
								
								Source/UTAD_UI/UTAD_UICharacter.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Source/UTAD_UI/UTAD_UICharacter.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "GameFramework/Character.h" | ||||
| #include "UTAD_UICharacter.generated.h" | ||||
|  | ||||
| UCLASS(Blueprintable) | ||||
| class AUTAD_UICharacter : public ACharacter | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| public: | ||||
| 	AUTAD_UICharacter(); | ||||
|  | ||||
| 	// Called every frame. | ||||
| 	virtual void Tick(float DeltaSeconds) override; | ||||
|  | ||||
| 	/** Returns TopDownCameraComponent subobject **/ | ||||
| 	FORCEINLINE class UCameraComponent* GetTopDownCameraComponent() const { return TopDownCameraComponent; } | ||||
| 	/** Returns CameraBoom subobject **/ | ||||
| 	FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; } | ||||
|  | ||||
| private: | ||||
| 	/** Top down camera */ | ||||
| 	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) | ||||
| 	class UCameraComponent* TopDownCameraComponent; | ||||
|  | ||||
| 	/** Camera boom positioning the camera above the character */ | ||||
| 	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) | ||||
| 	class USpringArmComponent* CameraBoom; | ||||
| }; | ||||
|  | ||||
							
								
								
									
										26
									
								
								Source/UTAD_UI/UTAD_UIGameMode.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Source/UTAD_UI/UTAD_UIGameMode.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #include "UTAD_UIGameMode.h" | ||||
| #include "UTAD_UIPlayerController.h" | ||||
| #include "UTAD_UICharacter.h" | ||||
| #include "UObject/ConstructorHelpers.h" | ||||
|  | ||||
| AUTAD_UIGameMode::AUTAD_UIGameMode() | ||||
| { | ||||
| 	// use our custom PlayerController class | ||||
| 	PlayerControllerClass = AUTAD_UIPlayerController::StaticClass(); | ||||
|  | ||||
| 	// set default pawn class to our Blueprinted character | ||||
| 	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/TopDown/Blueprints/BP_TopDownCharacter")); | ||||
| 	if (PlayerPawnBPClass.Class != nullptr) | ||||
| 	{ | ||||
| 		DefaultPawnClass = PlayerPawnBPClass.Class; | ||||
| 	} | ||||
|  | ||||
| 	// set default controller to our Blueprinted controller | ||||
| 	static ConstructorHelpers::FClassFinder<APlayerController> PlayerControllerBPClass(TEXT("/Game/TopDown/Blueprints/BP_TopDownPlayerController")); | ||||
| 	if(PlayerControllerBPClass.Class != NULL) | ||||
| 	{ | ||||
| 		PlayerControllerClass = PlayerControllerBPClass.Class; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										19
									
								
								Source/UTAD_UI/UTAD_UIGameMode.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Source/UTAD_UI/UTAD_UIGameMode.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "GameFramework/GameModeBase.h" | ||||
| #include "UTAD_UIGameMode.generated.h" | ||||
|  | ||||
| UCLASS(minimalapi) | ||||
| class AUTAD_UIGameMode : public AGameModeBase | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| public: | ||||
| 	AUTAD_UIGameMode(); | ||||
| }; | ||||
|  | ||||
|  | ||||
|  | ||||
							
								
								
									
										125
									
								
								Source/UTAD_UI/UTAD_UIPlayerController.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								Source/UTAD_UI/UTAD_UIPlayerController.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,125 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #include "UTAD_UIPlayerController.h" | ||||
| #include "GameFramework/Pawn.h" | ||||
| #include "Blueprint/AIBlueprintHelperLibrary.h" | ||||
| #include "NiagaraSystem.h" | ||||
| #include "NiagaraFunctionLibrary.h" | ||||
| #include "UTAD_UICharacter.h" | ||||
| #include "Engine/World.h" | ||||
| #include "EnhancedInputComponent.h" | ||||
| #include "InputActionValue.h" | ||||
| #include "EnhancedInputSubsystems.h" | ||||
| #include "Engine/LocalPlayer.h" | ||||
|  | ||||
| DEFINE_LOG_CATEGORY(LogTemplateCharacter); | ||||
|  | ||||
| AUTAD_UIPlayerController::AUTAD_UIPlayerController() | ||||
| { | ||||
| 	bShowMouseCursor = true; | ||||
| 	DefaultMouseCursor = EMouseCursor::Default; | ||||
| 	CachedDestination = FVector::ZeroVector; | ||||
| 	FollowTime = 0.f; | ||||
| } | ||||
|  | ||||
| void AUTAD_UIPlayerController::BeginPlay() | ||||
| { | ||||
| 	// Call the base class   | ||||
| 	Super::BeginPlay(); | ||||
| } | ||||
|  | ||||
| void AUTAD_UIPlayerController::SetupInputComponent() | ||||
| { | ||||
| 	// set up gameplay key bindings | ||||
| 	Super::SetupInputComponent(); | ||||
|  | ||||
| 	// Add Input Mapping Context | ||||
| 	if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer())) | ||||
| 	{ | ||||
| 		Subsystem->AddMappingContext(DefaultMappingContext, 0); | ||||
| 	} | ||||
|  | ||||
| 	// Set up action bindings | ||||
| 	if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent)) | ||||
| 	{ | ||||
| 		// Setup mouse input events | ||||
| 		EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Started, this, &AUTAD_UIPlayerController::OnInputStarted); | ||||
| 		EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Triggered, this, &AUTAD_UIPlayerController::OnSetDestinationTriggered); | ||||
| 		EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Completed, this, &AUTAD_UIPlayerController::OnSetDestinationReleased); | ||||
| 		EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Canceled, this, &AUTAD_UIPlayerController::OnSetDestinationReleased); | ||||
|  | ||||
| 		// Setup touch input events | ||||
| 		EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Started, this, &AUTAD_UIPlayerController::OnInputStarted); | ||||
| 		EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Triggered, this, &AUTAD_UIPlayerController::OnTouchTriggered); | ||||
| 		EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Completed, this, &AUTAD_UIPlayerController::OnTouchReleased); | ||||
| 		EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Canceled, this, &AUTAD_UIPlayerController::OnTouchReleased); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		UE_LOG(LogTemplateCharacter, Error, TEXT("'%s' Failed to find an Enhanced Input Component! This template is built to use the Enhanced Input system. If you intend to use the legacy system, then you will need to update this C++ file."), *GetNameSafe(this)); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void AUTAD_UIPlayerController::OnInputStarted() | ||||
| { | ||||
| 	StopMovement(); | ||||
| } | ||||
|  | ||||
| // Triggered every frame when the input is held down | ||||
| void AUTAD_UIPlayerController::OnSetDestinationTriggered() | ||||
| { | ||||
| 	// We flag that the input is being pressed | ||||
| 	FollowTime += GetWorld()->GetDeltaSeconds(); | ||||
| 	 | ||||
| 	// We look for the location in the world where the player has pressed the input | ||||
| 	FHitResult Hit; | ||||
| 	bool bHitSuccessful = false; | ||||
| 	if (bIsTouch) | ||||
| 	{ | ||||
| 		bHitSuccessful = GetHitResultUnderFinger(ETouchIndex::Touch1, ECollisionChannel::ECC_Visibility, true, Hit); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		bHitSuccessful = GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, true, Hit); | ||||
| 	} | ||||
|  | ||||
| 	// If we hit a surface, cache the location | ||||
| 	if (bHitSuccessful) | ||||
| 	{ | ||||
| 		CachedDestination = Hit.Location; | ||||
| 	} | ||||
| 	 | ||||
| 	// Move towards mouse pointer or touch | ||||
| 	APawn* ControlledPawn = GetPawn(); | ||||
| 	if (ControlledPawn != nullptr) | ||||
| 	{ | ||||
| 		FVector WorldDirection = (CachedDestination - ControlledPawn->GetActorLocation()).GetSafeNormal(); | ||||
| 		ControlledPawn->AddMovementInput(WorldDirection, 1.0, false); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void AUTAD_UIPlayerController::OnSetDestinationReleased() | ||||
| { | ||||
| 	// If it was a short press | ||||
| 	if (FollowTime <= ShortPressThreshold) | ||||
| 	{ | ||||
| 		// We move there and spawn some particles | ||||
| 		UAIBlueprintHelperLibrary::SimpleMoveToLocation(this, CachedDestination); | ||||
| 		UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, FXCursor, CachedDestination, FRotator::ZeroRotator, FVector(1.f, 1.f, 1.f), true, true, ENCPoolMethod::None, true); | ||||
| 	} | ||||
|  | ||||
| 	FollowTime = 0.f; | ||||
| } | ||||
|  | ||||
| // Triggered every frame when the input is held down | ||||
| void AUTAD_UIPlayerController::OnTouchTriggered() | ||||
| { | ||||
| 	bIsTouch = true; | ||||
| 	OnSetDestinationTriggered(); | ||||
| } | ||||
|  | ||||
| void AUTAD_UIPlayerController::OnTouchReleased() | ||||
| { | ||||
| 	bIsTouch = false; | ||||
| 	OnSetDestinationReleased(); | ||||
| } | ||||
							
								
								
									
										68
									
								
								Source/UTAD_UI/UTAD_UIPlayerController.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								Source/UTAD_UI/UTAD_UIPlayerController.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "CoreMinimal.h" | ||||
| #include "Templates/SubclassOf.h" | ||||
| #include "GameFramework/PlayerController.h" | ||||
| #include "UTAD_UIPlayerController.generated.h" | ||||
|  | ||||
| /** Forward declaration to improve compiling times */ | ||||
| class UNiagaraSystem; | ||||
| class UInputMappingContext; | ||||
| class UInputAction; | ||||
|  | ||||
| DECLARE_LOG_CATEGORY_EXTERN(LogTemplateCharacter, Log, All); | ||||
|  | ||||
| UCLASS() | ||||
| class AUTAD_UIPlayerController : public APlayerController | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
|  | ||||
| public: | ||||
| 	AUTAD_UIPlayerController(); | ||||
|  | ||||
| 	/** Time Threshold to know if it was a short press */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input) | ||||
| 	float ShortPressThreshold; | ||||
|  | ||||
| 	/** FX Class that we will spawn when clicking */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input) | ||||
| 	UNiagaraSystem* FXCursor; | ||||
|  | ||||
| 	/** MappingContext */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) | ||||
| 	UInputMappingContext* DefaultMappingContext; | ||||
| 	 | ||||
| 	/** Jump Input Action */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) | ||||
| 	UInputAction* SetDestinationClickAction; | ||||
|  | ||||
| 	/** Jump Input Action */ | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) | ||||
| 	UInputAction* SetDestinationTouchAction; | ||||
|  | ||||
| protected: | ||||
| 	/** True if the controlled character should navigate to the mouse cursor. */ | ||||
| 	uint32 bMoveToMouseCursor : 1; | ||||
|  | ||||
| 	virtual void SetupInputComponent() override; | ||||
| 	 | ||||
| 	// To add mapping context | ||||
| 	virtual void BeginPlay(); | ||||
|  | ||||
| 	/** Input handlers for SetDestination action. */ | ||||
| 	void OnInputStarted(); | ||||
| 	void OnSetDestinationTriggered(); | ||||
| 	void OnSetDestinationReleased(); | ||||
| 	void OnTouchTriggered(); | ||||
| 	void OnTouchReleased(); | ||||
|  | ||||
| private: | ||||
| 	FVector CachedDestination; | ||||
|  | ||||
| 	bool bIsTouch; // Is it a touch device | ||||
| 	float FollowTime; // For how long it has been pressed | ||||
| }; | ||||
|  | ||||
|  | ||||
							
								
								
									
										15
									
								
								Source/UTAD_UIEditor.Target.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Source/UTAD_UIEditor.Target.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| // Copyright Epic Games, Inc. All Rights Reserved. | ||||
|  | ||||
| using UnrealBuildTool; | ||||
| using System.Collections.Generic; | ||||
|  | ||||
| public class UTAD_UIEditorTarget : TargetRules | ||||
| { | ||||
| 	public UTAD_UIEditorTarget(TargetInfo Target) : base(Target) | ||||
| 	{ | ||||
| 		Type = TargetType.Editor; | ||||
| 		DefaultBuildSettings = BuildSettingsVersion.V5; | ||||
| 		IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_5; | ||||
| 		ExtraModuleNames.Add("UTAD_UI"); | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user