修复bug

This commit is contained in:
997146918 2025-11-25 14:21:55 +08:00
parent 1a5c391707
commit a83eeacbc5
7 changed files with 43 additions and 8 deletions

View File

@ -514,5 +514,8 @@ public:
//引导task //引导task
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Tutorial Asset") UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Tutorial Asset")
TSubclassOf<class UTutorialTask_Base> TutorialTaskClass; TSubclassOf<class UTutorialTask_Base> TutorialTaskClass;
UPROPERTY()
UTutorialTask_Base* TutorialTaskObject;
}; };

View File

@ -52,7 +52,8 @@ void UTutorialManagerSubsystem::ApplyCurrentTutorialStep()
} }
if (IsValid(CurrentStep.TutorialTaskClass)) if (IsValid(CurrentStep.TutorialTaskClass))
{ {
TutorialTaskObject = NewObject< UTutorialTask_Base>(this);
TutorialTaskObject->Execute(GetWorld()->GetAuthGameMode());
} }
} }
else else
@ -66,10 +67,15 @@ void UTutorialManagerSubsystem::CompleteTutorialStep()
{ {
if (bTutorialing) if (bTutorialing)
{ {
if (TutorialTask) if (TutorialTaskObject)
{ {
TutorialTask->ConditionalBeginDestroy(); TutorialTaskObject->ConditionalBeginDestroy();
TutorialTask = nullptr; TutorialTaskObject = nullptr;
}
if (TutorialWidget)
{
TutorialWidget->RemoveFromViewport();
TutorialWidget = nullptr;
} }
UE_LOG(LogTemp, Warning, TEXT("教程进行下一步 currentstep = %d"), CurrentTutorialStep); UE_LOG(LogTemp, Warning, TEXT("教程进行下一步 currentstep = %d"), CurrentTutorialStep);
OnStepComplete.Broadcast(CurrentTutorialStep); OnStepComplete.Broadcast(CurrentTutorialStep);
@ -138,7 +144,7 @@ void UTutorialManagerSubsystem::AccepAndFollowQuest()
void UTutorialManagerSubsystem::ShowTutorialUI() void UTutorialManagerSubsystem::ShowTutorialUI()
{ {
FTutorialStep CurrentStep = TutorialSteps[CurrentTutorialStep]; FTutorialStep CurrentStep = TutorialSteps[CurrentTutorialStep];
UUserWidget* TutorialWidget = CreateWidget<UUserWidget>(GetWorld(), CurrentStep.TutorialUI); TutorialWidget = CreateWidget<UUserWidget>(GetWorld(), CurrentStep.TutorialUI);
TutorialWidget->AddToViewport(99); TutorialWidget->AddToViewport(99);
} }

View File

@ -61,5 +61,8 @@ private:
class UDialogueWidget_Base* DialogueWidget; class UDialogueWidget_Base* DialogueWidget;
UPROPERTY() UPROPERTY()
class UTutorialTask_Base* TutorialTask; UUserWidget* TutorialWidget;
UPROPERTY()
class UTutorialTask_Base* TutorialTaskObject;
}; };

View File

@ -8,7 +8,11 @@
void UTutorialTask_GamePause::Execute_Implementation(class AGameModeBase* GameMode) void UTutorialTask_GamePause::Execute_Implementation(class AGameModeBase* GameMode)
{ {
Super::Execute_Implementation(GameMode); Super::Execute_Implementation(GameMode);
UGameplayStatics::SetGamePaused(this, true); LevelLoadedDelegateHandle = FCoreUObjectDelegates::PostLoadMapWithWorld.AddUObject(
this,
&UTutorialTask_GamePause::OnLevelLoaded
);
} }
void UTutorialTask_GamePause::BeforTutorialComplete_Implementation() void UTutorialTask_GamePause::BeforTutorialComplete_Implementation()
@ -16,3 +20,18 @@ void UTutorialTask_GamePause::BeforTutorialComplete_Implementation()
Super::BeforTutorialComplete_Implementation(); Super::BeforTutorialComplete_Implementation();
UGameplayStatics::SetGamePaused(this, false); UGameplayStatics::SetGamePaused(this, false);
} }
void UTutorialTask_GamePause::OnLevelLoaded(UWorld* World)
{
FCoreUObjectDelegates::PostLoadMapWithWorld.Remove(LevelLoadedDelegateHandle);
FTimerHandle LambdaTimerHandle;
GetWorld()->GetTimerManager().SetTimer(
LambdaTimerHandle,
[this]()
{
UGameplayStatics::SetGamePaused(this, true);
},
1.5f,
false
);
}

View File

@ -18,4 +18,8 @@ public:
virtual void Execute_Implementation(class AGameModeBase* GameMode) override; virtual void Execute_Implementation(class AGameModeBase* GameMode) override;
virtual void BeforTutorialComplete_Implementation() override; virtual void BeforTutorialComplete_Implementation() override;
void OnLevelLoaded(UWorld* World);
private:
FDelegateHandle LevelLoadedDelegateHandle;
}; };