diff --git a/Source/CommonLoadingScreen/Private/LoadingScreenWidget.cpp b/Source/CommonLoadingScreen/Private/LoadingScreenWidget.cpp index 458f649..55003ef 100644 --- a/Source/CommonLoadingScreen/Private/LoadingScreenWidget.cpp +++ b/Source/CommonLoadingScreen/Private/LoadingScreenWidget.cpp @@ -3,15 +3,33 @@ #include "LoadingScreenWidget.h" +void ULoadingScreenWidget::NativePreConstruct() +{ + FWidgetAnimationDynamicEvent LoadScreenOpened; + LoadScreenOpened.BindUFunction(this, TEXT("LoadScreenOpened")); + this->BindToAnimationFinished(this->Fade, LoadScreenOpened); + + this->PlayAnimationForward(this->Fade); +} void ULoadingScreenWidget::LoadScreenOpened() { + this->UnbindAllFromAnimationFinished(this->Fade); #if !WITH_EDITOR this->OnLoadScreenOpened.ExecuteIfBound(); #endif } +void ULoadingScreenWidget::BeginFadeOut_Implementation() +{ + FWidgetAnimationDynamicEvent LoadScreenClosed; + LoadScreenClosed.BindUFunction(this, TEXT("LoadScreenClosed")); + this->BindToAnimationFinished(this->Fade, LoadScreenClosed); + + this->PlayAnimationReverse(this->Fade); +} void ULoadingScreenWidget::LoadScreenClosed() { + this->UnbindAllFromAnimationFinished(this->Fade); #if !WITH_EDITOR this->OnLoadScreenClosed.ExecuteIfBound(); #endif diff --git a/Source/CommonLoadingScreen/Public/LoadingScreenWidget.h b/Source/CommonLoadingScreen/Public/LoadingScreenWidget.h index 5eedef6..98a57bf 100644 --- a/Source/CommonLoadingScreen/Public/LoadingScreenWidget.h +++ b/Source/CommonLoadingScreen/Public/LoadingScreenWidget.h @@ -18,15 +18,21 @@ class COMMONLOADINGSCREEN_API ULoadingScreenWidget : public UUserWidget GENERATED_BODY() public: + virtual void NativePreConstruct() override; + UFUNCTION(BlueprintCallable) void LoadScreenOpened(); UFUNCTION(BlueprintCallable) void LoadScreenClosed(); - UFUNCTION(BlueprintImplementableEvent) + UFUNCTION(BlueprintNativeEvent) void BeginFadeOut(); DECLARE_DELEGATE(FOnLoadScreenEvent) FOnLoadScreenEvent OnLoadScreenOpened; FOnLoadScreenEvent OnLoadScreenClosed; + +protected: + UPROPERTY(Transient, BlueprintReadOnly, meta=(BindWidgetAnim)) + TObjectPtr Fade; };