101 lines
3.0 KiB
C++
101 lines
3.0 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Ammo.h"
|
|
#include "Components/BoxComponent.h"
|
|
#include "Components/WidgetComponent.h"
|
|
#include "Components/SphereComponent.h"
|
|
#include "ShooterCharacter.h"
|
|
|
|
AAmmo::AAmmo()
|
|
{
|
|
// Construct the AmmoMesh component and set it as root
|
|
AmmoMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("AmmoMesh"));
|
|
SetRootComponent(AmmoMesh);
|
|
|
|
CollisionBox->SetupAttachment(GetRootComponent());
|
|
PickupWidget->SetupAttachment(GetRootComponent());
|
|
AreaSphere->SetupAttachment(GetRootComponent());
|
|
|
|
AmmoCollisionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("AmmoCollisionSphere"));
|
|
AmmoCollisionSphere->SetupAttachment(GetRootComponent());
|
|
AmmoCollisionSphere->SetSphereRadius(50.f);
|
|
}
|
|
|
|
void AAmmo::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
}
|
|
|
|
void AAmmo::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
AmmoCollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &AAmmo::OnAmmoSphereOverlap);
|
|
}
|
|
|
|
void AAmmo::SetItemProperties(EItemState State)
|
|
{
|
|
Super::SetItemProperties(State);
|
|
|
|
switch (State)
|
|
{
|
|
case EItemState::EIS_Pickup:
|
|
// Set Mesh properties
|
|
AmmoMesh->SetSimulatePhysics(false);
|
|
AmmoMesh->SetEnableGravity(false);
|
|
AmmoMesh->SetVisibility(true);
|
|
AmmoMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
|
|
AmmoMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
break;
|
|
case EItemState::EIS_Equipped:
|
|
// Set Mesh properties
|
|
AmmoMesh->SetSimulatePhysics(false);
|
|
AmmoMesh->SetEnableGravity(false);
|
|
AmmoMesh->SetVisibility(true);
|
|
AmmoMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
|
|
AmmoMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
break;
|
|
case EItemState::EIS_Falling:
|
|
// Set Mesh properties
|
|
AmmoMesh->SetSimulatePhysics(true);
|
|
AmmoMesh->SetEnableGravity(true);
|
|
AmmoMesh->SetVisibility(true);
|
|
AmmoMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
|
|
AmmoMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block);
|
|
AmmoMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
|
break;
|
|
case EItemState::EIS_EquipInterping:
|
|
// Set Mesh properties
|
|
AmmoMesh->SetSimulatePhysics(false);
|
|
AmmoMesh->SetEnableGravity(false);
|
|
AmmoMesh->SetVisibility(true);
|
|
AmmoMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
|
|
AmmoMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void AAmmo::OnAmmoSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
|
|
{
|
|
if (OtherActor)
|
|
{
|
|
auto OverlappedCharacter = Cast<AShooterCharacter>(OtherActor);
|
|
if (OverlappedCharacter)
|
|
{
|
|
StartItemCurve(OverlappedCharacter);
|
|
AmmoCollisionSphere->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
}
|
|
}
|
|
}
|
|
|
|
void AAmmo::EnableCustomDepth()
|
|
{
|
|
AmmoMesh->SetRenderCustomDepth(true);
|
|
}
|
|
|
|
void AAmmo::DisableCustomDepth()
|
|
{
|
|
AmmoMesh->SetRenderCustomDepth(false);
|
|
}
|