Download LyraStarterGame/Plugins/PocketWorlds/Source/Private/PocketLevelInstance.cpp from Alexhas2/unitysamples: direct link, hf CLI and curl.
- Browser
- Download file 3.63 kB
-
https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Plugins/PocketWorlds/Source/Private/PocketLevelInstance.cpp
- Command line
-
hf download hf://datasets/Alexhas2/unitysamples/LyraStarterGame/Plugins/PocketWorlds/Source/Private/PocketLevelInstance.cpp
-
curl -L -o PocketLevelInstance.cpp https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Plugins/PocketWorlds/Source/Private/PocketLevelInstance.cpp
3.63 kB
| // Copyright Epic Games, Inc. All Rights Reserved. | |
| UPocketLevelInstance::UPocketLevelInstance() | |
| { | |
| } | |
| bool UPocketLevelInstance::Initialize(ULocalPlayer* InLocalPlayer, UPocketLevel* InPocketLevel, FVector InSpawnPoint) | |
| { | |
| LocalPlayer = InLocalPlayer; | |
| World = LocalPlayer->GetWorld(); | |
| PocketLevel = InPocketLevel; | |
| Bounds = FBoxSphereBounds(FSphere(InSpawnPoint, PocketLevel->Bounds.GetAbsMax())); | |
| if (ensure(StreamingPocketLevel == nullptr)) | |
| { | |
| if (ensure(!PocketLevel->Level.IsNull())) | |
| { | |
| bool bSuccess = false; | |
| StreamingPocketLevel = ULevelStreamingDynamic::LoadLevelInstanceBySoftObjectPtr(LocalPlayer, PocketLevel->Level, Bounds.Origin, FRotator::ZeroRotator, bSuccess); | |
| if (ensure(bSuccess && StreamingPocketLevel)) | |
| { | |
| StreamingPocketLevel->OnLevelLoaded.AddUniqueDynamic(this, &ThisClass::HandlePocketLevelLoaded); | |
| StreamingPocketLevel->OnLevelShown.AddUniqueDynamic(this, &ThisClass::HandlePocketLevelShown); | |
| } | |
| return bSuccess; | |
| } | |
| } | |
| return false; | |
| } | |
| void UPocketLevelInstance::StreamIn() | |
| { | |
| if (StreamingPocketLevel) | |
| { | |
| StreamingPocketLevel->SetShouldBeVisible(true); | |
| StreamingPocketLevel->SetShouldBeLoaded(true); | |
| } | |
| } | |
| void UPocketLevelInstance::StreamOut() | |
| { | |
| if (StreamingPocketLevel) | |
| { | |
| StreamingPocketLevel->SetShouldBeVisible(false); | |
| StreamingPocketLevel->SetShouldBeLoaded(false); | |
| } | |
| } | |
| FDelegateHandle UPocketLevelInstance::AddReadyCallback(FPocketLevelInstanceEvent::FDelegate Callback) | |
| { | |
| if (StreamingPocketLevel->GetLevelStreamingState() == ELevelStreamingState::LoadedVisible) | |
| { | |
| Callback.ExecuteIfBound(this); | |
| } | |
| return OnReadyEvent.Add(Callback); | |
| } | |
| void UPocketLevelInstance::RemoveReadyCallback(FDelegateHandle CallbackToRemove) | |
| { | |
| OnReadyEvent.Remove(CallbackToRemove); | |
| } | |
| void UPocketLevelInstance::BeginDestroy() | |
| { | |
| Super::BeginDestroy(); | |
| if (StreamingPocketLevel) | |
| { | |
| StreamingPocketLevel->bShouldBlockOnUnload = false; | |
| StreamingPocketLevel->SetShouldBeLoaded(false); | |
| StreamingPocketLevel->OnLevelShown.RemoveAll(this); | |
| StreamingPocketLevel->OnLevelLoaded.RemoveAll(this); | |
| StreamingPocketLevel = nullptr; | |
| } | |
| } | |
| void UPocketLevelInstance::HandlePocketLevelLoaded() | |
| { | |
| if (StreamingPocketLevel) | |
| { | |
| // Make everything in the level setup so that it's setup on the client, and we treat | |
| // everything as locally spawned, rather than bExchangedRoles = true, where it's spawned | |
| // on the client, but the expectation is the server said do it, and the server is going to | |
| // be telling us about them later. | |
| if (ULevel* LoadedLevel = StreamingPocketLevel->GetLoadedLevel()) | |
| { | |
| LoadedLevel->bClientOnlyVisible = true; | |
| for (AActor* Actor : LoadedLevel->Actors) | |
| { | |
| if (Actor) | |
| { | |
| Actor->bExchangedRoles = true; // HACK, Remove when bClientOnlyVisible is all we need. | |
| } | |
| } | |
| // TODO: Don't put ownership over shared pocket spaces. | |
| if (LocalPlayer) | |
| { | |
| if (APlayerController* PC = LocalPlayer->GetPlayerController(GetWorld())) | |
| { | |
| for (AActor* Actor : LoadedLevel->Actors) | |
| { | |
| if (Actor) | |
| { | |
| Actor->SetOwner(PC); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| void UPocketLevelInstance::HandlePocketLevelShown() | |
| { | |
| OnReadyEvent.Broadcast(this); | |
| } | |