217 - Setting Team Colors

This commit is contained in:
Kingsmedia 2022-05-30 19:04:30 +02:00
parent 36c39f1c69
commit 19b84ff30f
7 changed files with 68 additions and 4 deletions

Binary file not shown.

View File

@ -316,6 +316,29 @@ void ABlasterCharacter::MulticastLostTheLead_Implementation()
} }
} }
void ABlasterCharacter::SetTeamColor(ETeam Team)
{
if (GetMesh() == nullptr) return;
switch (Team)
{
case ETeam::ET_RedTeam:
if (RedMaterial == nullptr) return;
GetMesh()->SetMaterial(0, RedMaterial);
DissolveMaterialInstance = RedDissolveMatInst;
break;
case ETeam::ET_BlueTeam:
if (BlueMaterial == nullptr) return;
GetMesh()->SetMaterial(0, BlueMaterial);
DissolveMaterialInstance = BlueDissolveMatInst;
break;
case ETeam::ET_NoTeam:
if (OriginalMaterial == nullptr) return;
GetMesh()->SetMaterial(0, OriginalMaterial);
DissolveMaterialInstance = BlueDissolveMatInst;
break;
}
}
void ABlasterCharacter::BeginPlay() void ABlasterCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
@ -903,6 +926,7 @@ void ABlasterCharacter::PollInit()
// Initialize Score now we have the PlayerState // Initialize Score now we have the PlayerState
BlasterPlayerState->IncreaseScore(0.f); BlasterPlayerState->IncreaseScore(0.f);
BlasterPlayerState->IncreaseDefeats(0); BlasterPlayerState->IncreaseDefeats(0);
SetTeamColor(BlasterPlayerState->GetTeam());
const ABlasterGameState* BlasterGameState = Cast<ABlasterGameState>(UGameplayStatics::GetGameState(this)); const ABlasterGameState* BlasterGameState = Cast<ABlasterGameState>(UGameplayStatics::GetGameState(this));
if (BlasterGameState && BlasterGameState->TopScoringPlayers.Contains(BlasterPlayerState)) if (BlasterGameState && BlasterGameState->TopScoringPlayers.Contains(BlasterPlayerState))

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Blaster/Interfaces/InteractWithCrosshairInterface.h" #include "Blaster/Interfaces/InteractWithCrosshairInterface.h"
#include "Blaster/Types/CombatState.h" #include "Blaster/Types/CombatState.h"
#include "Blaster/Types/Team.h"
#include "Blaster/Types/TurningInPlace.h" #include "Blaster/Types/TurningInPlace.h"
#include "Components/TimelineComponent.h" #include "Components/TimelineComponent.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
@ -67,6 +68,8 @@ public:
UFUNCTION(NetMulticast, Reliable) UFUNCTION(NetMulticast, Reliable)
void MulticastLostTheLead(); void MulticastLostTheLead();
void SetTeamColor(ETeam Team);
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
@ -277,9 +280,25 @@ private:
UMaterialInstanceDynamic* DynamicDissolveMaterialInstance; UMaterialInstanceDynamic* DynamicDissolveMaterialInstance;
// Material instance set on the Blueprint, used with the dynamic material instance // Material instance set on the Blueprint, used with the dynamic material instance
UPROPERTY(EditAnywhere, Category = Elimination) UPROPERTY(VisibleAnywhere, Category = Elimination)
UMaterialInstance* DissolveMaterialInstance; UMaterialInstance* DissolveMaterialInstance;
// Team colors
UPROPERTY(EditAnywhere, Category = Elimination)
UMaterialInstance* RedDissolveMatInst;
UPROPERTY(EditAnywhere, Category = Elimination)
UMaterialInstance* RedMaterial;
UPROPERTY(EditAnywhere, Category = Elimination)
UMaterialInstance* BlueDissolveMatInst;
UPROPERTY(EditAnywhere, Category = Elimination)
UMaterialInstance* BlueMaterial;
UPROPERTY(EditAnywhere, Category = Elimination)
UMaterialInstance* OriginalMaterial;
// Elimination effects // Elimination effects
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
UParticleSystem* EliminationBotEffect; UParticleSystem* EliminationBotEffect;

View File

@ -70,3 +70,22 @@ void ABlasterPlayerState::OnRep_Defeats()
} }
} }
} }
void ABlasterPlayerState::SetTeam(ETeam TeamToSet)
{
Team = TeamToSet;
ABlasterCharacter* BCharacter = Cast<ABlasterCharacter>(GetPawn());
if (BCharacter)
{
BCharacter->SetTeamColor(Team);
}
}
void ABlasterPlayerState::OnRep_Team()
{
ABlasterCharacter* BCharacter = Cast<ABlasterCharacter>(GetPawn());
if (BCharacter)
{
BCharacter->SetTeamColor(Team);
}
}

View File

@ -33,11 +33,13 @@ private:
UPROPERTY(ReplicatedUsing = OnRep_Defeats) UPROPERTY(ReplicatedUsing = OnRep_Defeats)
int32 Defeats; int32 Defeats;
UPROPERTY(Replicated) UPROPERTY(ReplicatedUsing = OnRep_Team)
ETeam Team = ETeam::ET_NoTeam; ETeam Team = ETeam::ET_NoTeam;
UFUNCTION()
void OnRep_Team();
public: public:
FORCEINLINE ETeam GetTeam() const { return Team; } FORCEINLINE ETeam GetTeam() const { return Team; }
FORCEINLINE void SetTeam(ETeam TeamToSet) { Team = TeamToSet; } void SetTeam(ETeam TeamToSet);
}; };