145 - Weapon Outline Effect

This commit is contained in:
Kingsmedia 2022-05-21 01:58:19 +02:00
parent 6fdfeef596
commit b225f72e46
12 changed files with 27 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@ -26,6 +26,10 @@ AWeapon::AWeapon()
WeaponMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Ignore);
WeaponMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
WeaponMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_BLUE);
WeaponMesh->MarkRenderStateDirty();
EnableCustomDepth(true);
AreaSphere = CreateDefaultSubobject<USphereComponent>(TEXT("AreaSphere"));
AreaSphere->SetupAttachment(RootComponent);
AreaSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
@ -43,6 +47,14 @@ void AWeapon::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeP
DOREPLIFETIME(AWeapon, Ammo);
}
void AWeapon::EnableCustomDepth(bool bEnabled)
{
if (WeaponMesh)
{
WeaponMesh->SetRenderCustomDepth(bEnabled);
}
}
void AWeapon::BeginPlay()
{
Super::BeginPlay();
@ -145,6 +157,7 @@ void AWeapon::SetWeaponState(EWeaponState State)
WeaponMesh->SetEnableGravity(true);
WeaponMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
}
EnableCustomDepth(false);
break;
case EWeaponState::EWS_Dropped:
if (HasAuthority())
@ -157,6 +170,9 @@ void AWeapon::SetWeaponState(EWeaponState State)
WeaponMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
WeaponMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Ignore);
WeaponMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore);
WeaponMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_BLUE);
WeaponMesh->MarkRenderStateDirty();
EnableCustomDepth(true);
break;
}
}
@ -186,6 +202,7 @@ void AWeapon::OnRep_WeaponState()
WeaponMesh->SetEnableGravity(true);
WeaponMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
}
EnableCustomDepth(false);
break;
case EWeaponState::EWS_Dropped:
WeaponMesh->SetSimulatePhysics(true);
@ -194,6 +211,9 @@ void AWeapon::OnRep_WeaponState()
WeaponMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
WeaponMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Ignore);
WeaponMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore);
WeaponMesh->SetCustomDepthStencilValue(CUSTOM_DEPTH_BLUE);
WeaponMesh->MarkRenderStateDirty();
EnableCustomDepth(true);
break;
}
}

View File

@ -67,6 +67,9 @@ public:
UPROPERTY(EditAnywhere, Category = Combat)
float FireDelay = .15f;
// Enable or disable custom depth
void EnableCustomDepth(bool bEnabled);
protected:
virtual void BeginPlay() override;

View File

@ -2,6 +2,10 @@
#define TRACE_LENGTH 80000
#define CUSTOM_DEPTH_PURPLE 250
#define CUSTOM_DEPTH_BLUE 251
#define CUSTOM_DEPTH_TAN 252
UENUM(BlueprintType)
enum class EWeaponType: uint8
{