赞
踩
网上有很多文章介绍,例如在游戏中只有一个实例,换关卡不会丢失等。暂时省略。
UWebSocketGameInstance.h里的定义
- UCLASS()
- class MYUE521_API UUWebSocketGameInstance : public UGameInstance
- {
-
- GENERATED_BODY()
-
-
- public:
- virtual void Init() override;
- virtual void Shutdown() override;
- void OnPlayerCreated(ULocalPlayer* player);
- }
说明:
下面来看一下实现UWebSocketGameInstance.cpp里
- void UUWebSocketGameInstance::Init() {
- Super::Init();
-
- OnLocalPlayerAddedEvent.AddUObject(this,&UUWebSocketGameInstance::OnPlayerCreated);
-
- }
-
- void UUWebSocketGameInstance::Shutdown() {
-
- //先写自定义的清理工作
-
- Super::Shutdown();
- }
-
- void UUWebSocketGameInstance::OnPlayerCreated(ULocalPlayer* player) {
-
- UE_LOG(LogTemp, Warning, TEXT("%s plaer is created"), *FString(__FUNCTION__));
- }
说明:
- ACharacter* character = UGameplayStatics::GetPlayerCharacter(this->GetWorld(), 0);
- Amyue521Character* character2 = Cast<Amyue521Character>(character);
- if (character2 == nullptr) {
- UE_LOG(LogTemp, Warning, TEXT("%s 1强制类型转换成Amyue521Character失败"), *FString(__FUNCTION__));
- }
- else {
-
- UE_LOG(LogTemp, Warning, TEXT("%s 1强制类型转换成Amyue521Character成功"), *FString(__FUNCTION__));
- }
- /** Returns number of fully registered local players */
- int32 GetNumLocalPlayers() const;
-
- /** Returns the local player at a certain index, or null if not found */
- ULocalPlayer* GetLocalPlayerByIndex(const int32 Index) const;
-
- /** Returns the first local player, will not be null during normal gameplay */
- ULocalPlayer* GetFirstGamePlayer() const;
-
- /** Returns the player controller assigned to the first local player. If World is specified it will search within that specific world */
- APlayerController* GetFirstLocalPlayerController(const UWorld* World = nullptr) const;
-
- /** Returns the local player assigned to a physical Controller Id, or null if not found */
- ULocalPlayer* FindLocalPlayerFromControllerId(const int32 ControllerId) const;
-
- /** Returns the local player assigned to this platform user id, or null if not found */
- ULocalPlayer* FindLocalPlayerFromPlatformUserId(const FPlatformUserId UserId) const;
-
- /** Returns the local player that has been assigned the specific unique net id */
- ULocalPlayer* FindLocalPlayerFromUniqueNetId(FUniqueNetIdPtr UniqueNetId) const;
- ULocalPlayer* FindLocalPlayerFromUniqueNetId(const FUniqueNetId& UniqueNetId) const;
- ULocalPlayer* FindLocalPlayerFromUniqueNetId(const FUniqueNetIdRepl& UniqueNetId) const;
-
- /** Returns const iterator for searching list of local players */
- TArray<ULocalPlayer*>::TConstIterator GetLocalPlayerIterator() const;
-
- /** Returns reference to entire local player list */
- const TArray<ULocalPlayer*> & GetLocalPlayers() const;
待补充
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。