|
|
|
|
| #include "LyraEquipmentInstance.h"
|
|
|
| #include "Components/SkeletalMeshComponent.h"
|
| #include "GameFramework/Character.h"
|
| #include "LyraEquipmentDefinition.h"
|
| #include "Net/UnrealNetwork.h"
|
|
|
| #if UE_WITH_IRIS
|
| #include "Iris/ReplicationSystem/ReplicationFragmentUtil.h"
|
| #endif
|
|
|
| #include UE_INLINE_GENERATED_CPP_BY_NAME(LyraEquipmentInstance)
|
|
|
| class FLifetimeProperty;
|
| class UClass;
|
| class USceneComponent;
|
|
|
| ULyraEquipmentInstance::ULyraEquipmentInstance(const FObjectInitializer& ObjectInitializer)
|
| : Super(ObjectInitializer)
|
| {
|
| }
|
|
|
| UWorld* ULyraEquipmentInstance::GetWorld() const
|
| {
|
| if (APawn* OwningPawn = GetPawn())
|
| {
|
| return OwningPawn->GetWorld();
|
| }
|
| else
|
| {
|
| return nullptr;
|
| }
|
| }
|
|
|
| void ULyraEquipmentInstance::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
| {
|
| Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
|
| DOREPLIFETIME(ThisClass, Instigator);
|
| DOREPLIFETIME(ThisClass, SpawnedActors);
|
| }
|
|
|
| #if UE_WITH_IRIS
|
| void ULyraEquipmentInstance::RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags)
|
| {
|
| using namespace UE::Net;
|
|
|
|
|
| FReplicationFragmentUtil::CreateAndRegisterFragmentsForObject(this, Context, RegistrationFlags);
|
| }
|
| #endif
|
|
|
| APawn* ULyraEquipmentInstance::GetPawn() const
|
| {
|
| return Cast<APawn>(GetOuter());
|
| }
|
|
|
| APawn* ULyraEquipmentInstance::GetTypedPawn(TSubclassOf<APawn> PawnType) const
|
| {
|
| APawn* Result = nullptr;
|
| if (UClass* ActualPawnType = PawnType)
|
| {
|
| if (GetOuter()->IsA(ActualPawnType))
|
| {
|
| Result = Cast<APawn>(GetOuter());
|
| }
|
| }
|
| return Result;
|
| }
|
|
|
| void ULyraEquipmentInstance::SpawnEquipmentActors(const TArray<FLyraEquipmentActorToSpawn>& ActorsToSpawn)
|
| {
|
| if (APawn* OwningPawn = GetPawn())
|
| {
|
| USceneComponent* AttachTarget = OwningPawn->GetRootComponent();
|
| if (ACharacter* Char = Cast<ACharacter>(OwningPawn))
|
| {
|
| AttachTarget = Char->GetMesh();
|
| }
|
|
|
| for (const FLyraEquipmentActorToSpawn& SpawnInfo : ActorsToSpawn)
|
| {
|
| AActor* NewActor = GetWorld()->SpawnActorDeferred<AActor>(SpawnInfo.ActorToSpawn, FTransform::Identity, OwningPawn);
|
| NewActor->FinishSpawning(FTransform::Identity, true);
|
| NewActor->SetActorRelativeTransform(SpawnInfo.AttachTransform);
|
| NewActor->AttachToComponent(AttachTarget, FAttachmentTransformRules::KeepRelativeTransform, SpawnInfo.AttachSocket);
|
|
|
| SpawnedActors.Add(NewActor);
|
| }
|
| }
|
| }
|
|
|
| void ULyraEquipmentInstance::DestroyEquipmentActors()
|
| {
|
| for (AActor* Actor : SpawnedActors)
|
| {
|
| if (Actor)
|
| {
|
| Actor->Destroy();
|
| }
|
| }
|
| }
|
|
|
| void ULyraEquipmentInstance::OnEquipped()
|
| {
|
| K2_OnEquipped();
|
| }
|
|
|
| void ULyraEquipmentInstance::OnUnequipped()
|
| {
|
| K2_OnUnequipped();
|
| }
|
|
|
| void ULyraEquipmentInstance::OnRep_Instigator()
|
| {
|
| }
|
|
|
|
|