Init
This commit is contained in:
15
Source/TerraformingAnubis.Target.cs
Normal file
15
Source/TerraformingAnubis.Target.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class TerraformingAnubisTarget : TargetRules
|
||||
{
|
||||
public TerraformingAnubisTarget(TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Game;
|
||||
DefaultBuildSettings = BuildSettingsVersion.V4;
|
||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_3;
|
||||
ExtraModuleNames.Add("TerraformingAnubis");
|
||||
}
|
||||
}
|
||||
27
Source/TerraformingAnubis/InteractiveObject.cpp
Normal file
27
Source/TerraformingAnubis/InteractiveObject.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "InteractiveObject.h"
|
||||
|
||||
// Sets default values
|
||||
AInteractiveObject::AInteractiveObject()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void AInteractiveObject::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void AInteractiveObject::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
}
|
||||
|
||||
44
Source/TerraformingAnubis/InteractiveObject.h
Normal file
44
Source/TerraformingAnubis/InteractiveObject.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "Components/StaticMeshComponent.h"
|
||||
#include "InteractiveObject.generated.h"
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum EObjectType
|
||||
{
|
||||
Building UMETA(DisplayName = "Building"),
|
||||
Item UMETA(DisplayName = "Item"),
|
||||
Device UMETA(DisplayName = "Device")
|
||||
};
|
||||
|
||||
UCLASS()
|
||||
class TERRAFORMINGANUBIS_API AInteractiveObject : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
AInteractiveObject();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UStaticMeshComponent* StaticMesh = nullptr;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FText Name;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TEnumAsByte<EObjectType> ObjectType = Building;
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
};
|
||||
13
Source/TerraformingAnubis/TerraformingAnubis.Build.cs
Normal file
13
Source/TerraformingAnubis/TerraformingAnubis.Build.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class TerraformingAnubis : ModuleRules
|
||||
{
|
||||
public TerraformingAnubis(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "NavigationSystem", "AIModule", "Niagara", "EnhancedInput" });
|
||||
}
|
||||
}
|
||||
9
Source/TerraformingAnubis/TerraformingAnubis.cpp
Normal file
9
Source/TerraformingAnubis/TerraformingAnubis.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "TerraformingAnubis.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, TerraformingAnubis, "TerraformingAnubis" );
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogTerraformingAnubis)
|
||||
|
||||
7
Source/TerraformingAnubis/TerraformingAnubis.h
Normal file
7
Source/TerraformingAnubis/TerraformingAnubis.h
Normal file
@@ -0,0 +1,7 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogTerraformingAnubis, Log, All);
|
||||
51
Source/TerraformingAnubis/TerraformingAnubisCharacter.cpp
Normal file
51
Source/TerraformingAnubis/TerraformingAnubisCharacter.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "TerraformingAnubisCharacter.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"
|
||||
|
||||
ATerraformingAnubisCharacter::ATerraformingAnubisCharacter()
|
||||
{
|
||||
// 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 ATerraformingAnubisCharacter::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
}
|
||||
34
Source/TerraformingAnubis/TerraformingAnubisCharacter.h
Normal file
34
Source/TerraformingAnubis/TerraformingAnubisCharacter.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "TerraformingAnubisCharacter.generated.h"
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
class ATerraformingAnubisCharacter : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ATerraformingAnubisCharacter();
|
||||
|
||||
// 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/TerraformingAnubis/TerraformingAnubisGameMode.cpp
Normal file
26
Source/TerraformingAnubis/TerraformingAnubisGameMode.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "TerraformingAnubisGameMode.h"
|
||||
#include "TerraformingAnubisPlayerController.h"
|
||||
#include "TerraformingAnubisCharacter.h"
|
||||
#include "UObject/ConstructorHelpers.h"
|
||||
|
||||
ATerraformingAnubisGameMode::ATerraformingAnubisGameMode()
|
||||
{
|
||||
// use our custom PlayerController class
|
||||
PlayerControllerClass = ATerraformingAnubisPlayerController::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/TerraformingAnubis/TerraformingAnubisGameMode.h
Normal file
19
Source/TerraformingAnubis/TerraformingAnubisGameMode.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "TerraformingAnubisGameMode.generated.h"
|
||||
|
||||
UCLASS(minimalapi)
|
||||
class ATerraformingAnubisGameMode : public AGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ATerraformingAnubisGameMode();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "TerraformingAnubisPlayerController.h"
|
||||
#include "GameFramework/Pawn.h"
|
||||
#include "Blueprint/AIBlueprintHelperLibrary.h"
|
||||
#include "NiagaraSystem.h"
|
||||
#include "NiagaraFunctionLibrary.h"
|
||||
#include "TerraformingAnubisCharacter.h"
|
||||
#include "Engine/World.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "InputActionValue.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "Engine/LocalPlayer.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogTemplateCharacter);
|
||||
|
||||
ATerraformingAnubisPlayerController::ATerraformingAnubisPlayerController()
|
||||
{
|
||||
bShowMouseCursor = true;
|
||||
DefaultMouseCursor = EMouseCursor::Default;
|
||||
CachedDestination = FVector::ZeroVector;
|
||||
FollowTime = 0.f;
|
||||
}
|
||||
|
||||
void ATerraformingAnubisPlayerController::BeginPlay()
|
||||
{
|
||||
// Call the base class
|
||||
Super::BeginPlay();
|
||||
|
||||
//Add Input Mapping Context
|
||||
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
|
||||
{
|
||||
Subsystem->AddMappingContext(DefaultMappingContext, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void ATerraformingAnubisPlayerController::SetupInputComponent()
|
||||
{
|
||||
// set up gameplay key bindings
|
||||
Super::SetupInputComponent();
|
||||
|
||||
// Set up action bindings
|
||||
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent))
|
||||
{
|
||||
// Setup mouse input events
|
||||
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Started, this, &ATerraformingAnubisPlayerController::OnInputStarted);
|
||||
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Triggered, this, &ATerraformingAnubisPlayerController::OnSetDestinationTriggered);
|
||||
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Completed, this, &ATerraformingAnubisPlayerController::OnSetDestinationReleased);
|
||||
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Canceled, this, &ATerraformingAnubisPlayerController::OnSetDestinationReleased);
|
||||
}
|
||||
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 ATerraformingAnubisPlayerController::OnInputStarted()
|
||||
{
|
||||
StopMovement();
|
||||
}
|
||||
|
||||
// Triggered every frame when the input is held down
|
||||
void ATerraformingAnubisPlayerController::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;
|
||||
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 ATerraformingAnubisPlayerController::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;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Templates/SubclassOf.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "TerraformingAnubisPlayerController.generated.h"
|
||||
|
||||
/** Forward declaration to improve compiling times */
|
||||
class UNiagaraSystem;
|
||||
class UInputMappingContext;
|
||||
class UInputAction;
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogTemplateCharacter, Log, All);
|
||||
|
||||
UCLASS()
|
||||
class ATerraformingAnubisPlayerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ATerraformingAnubisPlayerController();
|
||||
|
||||
/** 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;
|
||||
|
||||
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();
|
||||
|
||||
private:
|
||||
FVector CachedDestination;
|
||||
|
||||
float FollowTime; // For how long it has been pressed
|
||||
};
|
||||
|
||||
|
||||
15
Source/TerraformingAnubisEditor.Target.cs
Normal file
15
Source/TerraformingAnubisEditor.Target.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class TerraformingAnubisEditorTarget : TargetRules
|
||||
{
|
||||
public TerraformingAnubisEditorTarget(TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Editor;
|
||||
DefaultBuildSettings = BuildSettingsVersion.V4;
|
||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_3;
|
||||
ExtraModuleNames.Add("TerraformingAnubis");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user