Download LyraStarterGame/Source/LyraGame/Player/LyraLocalPlayer.cpp from Alexhas2/unitysamples: direct link, hf CLI and curl.
- Browser
- Download file 5.08 kB
-
https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/Player/LyraLocalPlayer.cpp
- Command line
-
hf download hf://datasets/Alexhas2/unitysamples/LyraStarterGame/Source/LyraGame/Player/LyraLocalPlayer.cpp
-
curl -L -o LyraLocalPlayer.cpp https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/Player/LyraLocalPlayer.cpp
5.08 kB
| // Copyright Epic Games, Inc. All Rights Reserved. | |
| class UObject; | |
| ULyraLocalPlayer::ULyraLocalPlayer() | |
| { | |
| } | |
| void ULyraLocalPlayer::PostInitProperties() | |
| { | |
| Super::PostInitProperties(); | |
| if (ULyraSettingsLocal* LocalSettings = GetLocalSettings()) | |
| { | |
| LocalSettings->OnAudioOutputDeviceChanged.AddUObject(this, &ULyraLocalPlayer::OnAudioOutputDeviceChanged); | |
| } | |
| } | |
| void ULyraLocalPlayer::SwitchController(class APlayerController* PC) | |
| { | |
| Super::SwitchController(PC); | |
| OnPlayerControllerChanged(PlayerController); | |
| } | |
| bool ULyraLocalPlayer::SpawnPlayActor(const FString& URL, FString& OutError, UWorld* InWorld) | |
| { | |
| const bool bResult = Super::SpawnPlayActor(URL, OutError, InWorld); | |
| OnPlayerControllerChanged(PlayerController); | |
| return bResult; | |
| } | |
| void ULyraLocalPlayer::InitOnlineSession() | |
| { | |
| OnPlayerControllerChanged(PlayerController); | |
| Super::InitOnlineSession(); | |
| } | |
| void ULyraLocalPlayer::OnPlayerControllerChanged(APlayerController* NewController) | |
| { | |
| // Stop listening for changes from the old controller | |
| FGenericTeamId OldTeamID = FGenericTeamId::NoTeam; | |
| if (ILyraTeamAgentInterface* ControllerAsTeamProvider = Cast<ILyraTeamAgentInterface>(LastBoundPC.Get())) | |
| { | |
| OldTeamID = ControllerAsTeamProvider->GetGenericTeamId(); | |
| ControllerAsTeamProvider->GetTeamChangedDelegateChecked().RemoveAll(this); | |
| } | |
| // Grab the current team ID and listen for future changes | |
| FGenericTeamId NewTeamID = FGenericTeamId::NoTeam; | |
| if (ILyraTeamAgentInterface* ControllerAsTeamProvider = Cast<ILyraTeamAgentInterface>(NewController)) | |
| { | |
| NewTeamID = ControllerAsTeamProvider->GetGenericTeamId(); | |
| ControllerAsTeamProvider->GetTeamChangedDelegateChecked().AddDynamic(this, &ThisClass::OnControllerChangedTeam); | |
| LastBoundPC = NewController; | |
| } | |
| ConditionalBroadcastTeamChanged(this, OldTeamID, NewTeamID); | |
| } | |
| void ULyraLocalPlayer::SetGenericTeamId(const FGenericTeamId& NewTeamID) | |
| { | |
| // Do nothing, we merely observe the team of our associated player controller | |
| } | |
| FGenericTeamId ULyraLocalPlayer::GetGenericTeamId() const | |
| { | |
| if (ILyraTeamAgentInterface* ControllerAsTeamProvider = Cast<ILyraTeamAgentInterface>(PlayerController)) | |
| { | |
| return ControllerAsTeamProvider->GetGenericTeamId(); | |
| } | |
| else | |
| { | |
| return FGenericTeamId::NoTeam; | |
| } | |
| } | |
| FOnLyraTeamIndexChangedDelegate* ULyraLocalPlayer::GetOnTeamIndexChangedDelegate() | |
| { | |
| return &OnTeamChangedDelegate; | |
| } | |
| ULyraSettingsLocal* ULyraLocalPlayer::GetLocalSettings() const | |
| { | |
| return ULyraSettingsLocal::Get(); | |
| } | |
| ULyraSettingsShared* ULyraLocalPlayer::GetSharedSettings() const | |
| { | |
| if (!SharedSettings) | |
| { | |
| // On PC it's okay to use the sync load because it only checks the disk | |
| // This could use a platform tag to check for proper save support instead | |
| bool bCanLoadBeforeLogin = PLATFORM_DESKTOP; | |
| if (bCanLoadBeforeLogin) | |
| { | |
| SharedSettings = ULyraSettingsShared::LoadOrCreateSettings(this); | |
| } | |
| else | |
| { | |
| // We need to wait for user login to get the real settings so return temp ones | |
| SharedSettings = ULyraSettingsShared::CreateTemporarySettings(this); | |
| } | |
| } | |
| return SharedSettings; | |
| } | |
| void ULyraLocalPlayer::LoadSharedSettingsFromDisk(bool bForceLoad) | |
| { | |
| FUniqueNetIdRepl CurrentNetId = GetCachedUniqueNetId(); | |
| if (!bForceLoad && SharedSettings && CurrentNetId == NetIdForSharedSettings) | |
| { | |
| // Already loaded once, don't reload | |
| return; | |
| } | |
| ensure(ULyraSettingsShared::AsyncLoadOrCreateSettings(this, ULyraSettingsShared::FOnSettingsLoadedEvent::CreateUObject(this, &ULyraLocalPlayer::OnSharedSettingsLoaded))); | |
| } | |
| void ULyraLocalPlayer::OnSharedSettingsLoaded(ULyraSettingsShared* LoadedOrCreatedSettings) | |
| { | |
| // The settings are applied before it gets here | |
| if (ensure(LoadedOrCreatedSettings)) | |
| { | |
| // This will replace the temporary or previously loaded object which will GC out normally | |
| SharedSettings = LoadedOrCreatedSettings; | |
| NetIdForSharedSettings = GetCachedUniqueNetId(); | |
| } | |
| } | |
| void ULyraLocalPlayer::OnAudioOutputDeviceChanged(const FString& InAudioOutputDeviceId) | |
| { | |
| FOnCompletedDeviceSwap DevicesSwappedCallback; | |
| DevicesSwappedCallback.BindUFunction(this, FName("OnCompletedAudioDeviceSwap")); | |
| UAudioMixerBlueprintLibrary::SwapAudioOutputDevice(GetWorld(), InAudioOutputDeviceId, DevicesSwappedCallback); | |
| } | |
| void ULyraLocalPlayer::OnCompletedAudioDeviceSwap(const FSwapAudioOutputResult& SwapResult) | |
| { | |
| if (SwapResult.Result == ESwapAudioOutputDeviceResultState::Failure) | |
| { | |
| } | |
| } | |
| void ULyraLocalPlayer::OnControllerChangedTeam(UObject* TeamAgent, int32 OldTeam, int32 NewTeam) | |
| { | |
| ConditionalBroadcastTeamChanged(this, IntegerToGenericTeamId(OldTeam), IntegerToGenericTeamId(NewTeam)); | |
| } | |