38,关卡管理器初始化改为c++
整体方案总结AMyLevelManager架构目标BeginPlay在 C 完成初始化逻辑获取 GameInstance、PostProcessVolume、播放背景音乐、开启定时器。TimeCount 是纯 C 普通成员函数不暴露给蓝图定时器触发 TimeCount。TimeCountC 内部调用子函数TimerSubLogic仅子函数支持蓝图重写C 提供默认实现。背景音乐资源StageLevelSound暴露到蓝图细节面板编辑器直接选音效无需改代码。UPROPERTY(EditAnywhere, BlueprintReadWrite, Category “Audio”)USoundBase* StageLevelSound nullptr;UPROPERTY(BlueprintReadWrite, Category “LevelManager”)UMyGameInstance* gameIns nullptr;UPROPERTY(BlueprintReadWrite, Category “LevelManager”)APostProcessVolume* pp nullptr;FTimerHandle TimerHandle_level;void TimeCount();// 扩展入口蓝图 / C 均可重写UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category “LevelManager”)void TimerSubLogic();virtual void TimerSubLogic_Implementation() {}// Called when the game starts or when spawnedvoid AMyLevelManager::BeginPlay(){Super::BeginPlay();gameIns CastUMyGameInstance(UGameplayStatics::GetGameInstance(GetWorld())); if (!gameIns) { return; } pp CastAPostProcessVolume(UGameplayStatics::GetActorOfClass(GetWorld(), APostProcessVolume::StaticClass())); SoundManagement(StageLevelSound); GetWorldTimerManager().SetTimer(TimerHandle_level, this, AMyLevelManager::TimeCount, 1.0f, true);}// Called every framevoid AMyLevelManager::Tick(float DeltaTime){Super::Tick(DeltaTime);}void AMyLevelManager::TimeCount(){TimerSubLogic();}