Download LyraStarterGame/Source/LyraGame/Equipment/LyraEquipmentInstance.cpp from Alexhas2/unitysamples: direct link, hf CLI and curl.
- Browser
- Download file 3.02 kB
-
https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/Equipment/LyraEquipmentInstance.cpp
- Command line
-
hf download hf://datasets/Alexhas2/unitysamples/LyraStarterGame/Source/LyraGame/Equipment/LyraEquipmentInstance.cpp
-
curl -L -o LyraEquipmentInstance.cpp https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/Equipment/LyraEquipmentInstance.cpp
3.02 kB
| // Copyright Epic Games, Inc. All Rights Reserved. | |
| 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); | |
| } | |
| void ULyraEquipmentInstance::RegisterReplicationFragments(UE::Net::FFragmentRegistrationContext& Context, UE::Net::EFragmentRegistrationFlags RegistrationFlags) | |
| { | |
| using namespace UE::Net; | |
| // Build descriptors and allocate PropertyReplicationFragments for this object | |
| FReplicationFragmentUtil::CreateAndRegisterFragmentsForObject(this, Context, RegistrationFlags); | |
| } | |
| 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, /*bIsDefaultTransform=*/ 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() | |
| { | |
| } | |