RealtimeStyleTransferRuntime/Source/LyraGame/Teams/LyraTeamInfoBase.cpp

80 lines
1.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraTeamInfoBase.h"
#include "Containers/Array.h"
#include "CoreTypes.h"
#include "Engine/World.h"
#include "Misc/AssertionMacros.h"
#include "Net/UnrealNetwork.h"
#include "Teams/LyraTeamSubsystem.h"
#include "UObject/CoreNetTypes.h"
class FLifetimeProperty;
ALyraTeamInfoBase::ALyraTeamInfoBase(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, TeamId(INDEX_NONE)
{
bReplicates = true;
bAlwaysRelevant = true;
NetPriority = 3.0f;
SetReplicatingMovement(false);
}
void ALyraTeamInfoBase::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(ThisClass, TeamTags);
DOREPLIFETIME_CONDITION(ThisClass, TeamId, COND_InitialOnly);
}
void ALyraTeamInfoBase::BeginPlay()
{
Super::BeginPlay();
TryRegisterWithTeamSubsystem();
}
void ALyraTeamInfoBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
if (TeamId != INDEX_NONE)
{
ULyraTeamSubsystem* TeamSubsystem = GetWorld()->GetSubsystem<ULyraTeamSubsystem>();
TeamSubsystem->UnregisterTeamInfo(this);
}
Super::EndPlay(EndPlayReason);
}
void ALyraTeamInfoBase::RegisterWithTeamSubsystem(ULyraTeamSubsystem* Subsystem)
{
Subsystem->RegisterTeamInfo(this);
}
void ALyraTeamInfoBase::TryRegisterWithTeamSubsystem()
{
if (TeamId != INDEX_NONE)
{
ULyraTeamSubsystem* TeamSubsystem = GetWorld()->GetSubsystem<ULyraTeamSubsystem>();
RegisterWithTeamSubsystem(TeamSubsystem);
}
}
void ALyraTeamInfoBase::SetTeamId(int32 NewTeamId)
{
check(HasAuthority());
check(TeamId == INDEX_NONE);
check(NewTeamId != INDEX_NONE);
TeamId = NewTeamId;
TryRegisterWithTeamSubsystem();
}
void ALyraTeamInfoBase::OnRep_TeamId()
{
TryRegisterWithTeamSubsystem();
}