diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index c3266efb..8609bbc9 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -278,6 +278,7 @@ void ABaseWeaponClass::InteractPrompt() WeaponStatsPopUp(); } +//Called in weaponworkbench WBP void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh) { GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP SILENCER ATTACHMENTS")); @@ -290,11 +291,13 @@ void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh) { if (IsValid(WeaponSkeletonMesh)) { + //this handles giving the weapon the required component class/code SilencerAttachmentClass->AttachToComponent(WeaponSkeletonMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("SilencerMeshSocket"))); UE_LOG(LogTemp, Display, TEXT("All Attachment is valid")); //this makes it showup in editor for better debugging SilencerAttachmentClass->CreationMethod = EComponentCreationMethod::Instance; SilencerAttachmentClass->RegisterComponent(); + //below handles seeing the physical attachment you selected UStaticMeshComponent* StaticMeshComp = NewObject(SilencerAttachmentClass, UStaticMeshComponent::StaticClass()); if (IsValid(StaticMeshComp)) { @@ -309,3 +312,44 @@ void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh) } } } + +//Called in weaponworkbench WBP +void ABaseWeaponClass::SetupExtendedMagAttachment(UStaticMesh* ExtendedMagMesh) +{ + GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP EXTENDEDMAG ATTACHMENTS")); + FTransform EmptyTransform; + + USceneComponent* ExtendedMagAttachmentClass = Cast(AddComponentByClass(USilencerAttachmentClass::StaticClass(), false, EmptyTransform, false)); + ExtendedMagAttachmentClass->ComponentTags.Add(FName("AttachmentType")); + USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass(); + if (IsValid(ExtendedMagAttachmentClass)) + { + if (IsValid(WeaponSkeletonMesh)) + { + //this handles giving the weapon the required component class/code + ExtendedMagAttachmentClass->AttachToComponent(WeaponSkeletonMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("SilencerMeshSocket"))); + UE_LOG(LogTemp, Display, TEXT("All Attachment is valid")); + //this makes it showup in editor for better debugging + ExtendedMagAttachmentClass->CreationMethod = EComponentCreationMethod::Instance; + ExtendedMagAttachmentClass->RegisterComponent(); + //below handles seeing the physical attachment you selected + UStaticMeshComponent* StaticMeshComp = NewObject(ExtendedMagAttachmentClass, UStaticMeshComponent::StaticClass()); + if (IsValid(StaticMeshComp)) + { + StaticMeshComp->AttachToComponent(ExtendedMagAttachmentClass, FAttachmentTransformRules::SnapToTargetIncludingScale); + StaticMeshComp->SetStaticMesh(ExtendedMagMesh); + StaticMeshComp->SetRelativeRotation(FRotator(0, 90, 0)); + StaticMeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision); + //Making it show in editor for debugging + StaticMeshComp->CreationMethod = EComponentCreationMethod::Instance; + StaticMeshComp->RegisterComponent(); + } + } + } +} + +//Called in weaponworkbench WBP +void ABaseWeaponClass::SetupGripAttachment(UStaticMesh* GripMesh) +{ + +} diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h index d934ea9e..3d6a0635 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h @@ -175,6 +175,12 @@ public: UFUNCTION(BlueprintCallable) void SetupSilencerAttachment(UStaticMesh* SilencerMesh); + UFUNCTION(BlueprintCallable) + void SetupExtendedMagAttachment(UStaticMesh* ExtendedMagMesh); + + UFUNCTION(BlueprintCallable) + void SetupGripAttachment(UStaticMesh* GripMesh); + UFUNCTION(BlueprintImplementableEvent) void ShowReloadingWidget(); diff --git a/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.cpp b/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.cpp index 945c675a..ea2321ae 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.cpp @@ -1,11 +1,11 @@ -$COPYRIGHT_LINE$ +// Fill out your copyright notice in the Description page of Project Settings. -$MY_HEADER_INCLUDE_DIRECTIVE$ +#include "ExtendedMagAttachmentClass.h" // Sets default values for this component's properties -$PREFIX$$UNPREFIXED_CLASS_NAME$::$PREFIX$$UNPREFIXED_CLASS_NAME$() +UExtendedMagAttachmentClass::UExtendedMagAttachmentClass() { // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // off to improve performance if you don't need them. @@ -16,17 +16,17 @@ $PREFIX$$UNPREFIXED_CLASS_NAME$::$PREFIX$$UNPREFIXED_CLASS_NAME$() // Called when the game starts -void $PREFIX$$UNPREFIXED_CLASS_NAME$::BeginPlay() +void UExtendedMagAttachmentClass::BeginPlay() { Super::BeginPlay(); // ... - $END$ + } // Called every frame -void $PREFIX$$UNPREFIXED_CLASS_NAME$::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +void UExtendedMagAttachmentClass::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); diff --git a/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.h b/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.h index e69de29b..f2dddee9 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.h @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/SceneComponent.h" +#include "ExtendedMagAttachmentClass.generated.h" + + +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class ENDLESSVENDETTA_API UExtendedMagAttachmentClass : public USceneComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UExtendedMagAttachmentClass(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; +};