A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
FadeManager.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
8#include "Kismet/GameplayStatics.h"
9
11
13{
17
19 {
20 bNewLevelFadeOut = false;
21
22 EventLogService::NewEvent<UFadeOutEvent>(nullptr, nullptr, 0.25f);
23 }
24}
25
27{
28 if (BlockFade)
29 {
30 return;
31 }
32
33 FadeInCallback = Event->GetFadeInCallbackFunction();
34 FadeOutCallback = Event->GetFadeOutCallbackFunction();
35
36 GetWorld()->GetTimerManager().ClearTimer(FadeTimerHandler);
37
38 FadeInDuration = Event->GetFadeInDuration();
39 FadeDelay = Event->GetFadeDelay();
40 FadeOutDuration = Event->GetFadeOutDuration();
41
42 bAutoFadeOut = true;
44}
45
47{
48 FadeInCallback = Event->GetCallbackFunction();
49
50 GetWorld()->GetTimerManager().ClearTimer(FadeTimerHandler);
51
52 FadeInDuration = Event->GetFadeInDuration();
53 bAutoFadeOut = false;
55}
56
58{
59 FadeOutCallback = Event->GetCallbackFunction();
60
61 GetWorld()->GetTimerManager().ClearTimer(FadeTimerHandler);
62
63 FadeOutDuration = Event->GetFadeOutDuration();
65}
66
68{
69 BlockFade = true;
70 auto FadeInFinishedEvent = [this, LevelName]()
71 {
72 UGameplayStatics::OpenLevel(GetWorld(), LevelName);
73 bNewLevelFadeOut = true;
74 };
75
76 EventLogService::NewEvent<UFadeInEvent>(nullptr, FadeInFinishedEvent, 0.25f);
77}
78
79void UFadeManager::ShowFade(bool FadeIn, float Duration)
80{
81 if (FadeIn)
82 {
83 auto FadeInFinishedEvent = [this]()
84 {
85 OnFadeInFinished.Broadcast();
86 };
87 EventLogService::NewEvent<UFadeInEvent>(nullptr, FadeInFinishedEvent, Duration);
88 }
89 else
90 {
91 auto FadeOutFinishedEvent = [](){};
92 EventLogService::NewEvent<UFadeOutEvent>(nullptr, FadeOutFinishedEvent, Duration);
93 }
94}
95
97{
98 float FadeDuration = FadeInDuration >= MinFadeTime ? FadeInDuration : MinFadeTime;
99
100 GetWorld()->GetTimerManager().SetTimer(FadeTimerHandler, this, &UFadeManager::FadeInFinished, FadeDuration);
101
102 for (auto It = GetWorld()->GetPlayerControllerIterator(); It; ++It)
103 {
104 if (APixoVRPlayerController* PlayerController = Cast<APixoVRPlayerController>(It->Get()))
105 {
106 PlayerController->ClientFadeIn(FadeDuration);
107 }
108 }
109}
110
112{
113 if (FadeInCallback)
114 {
116 }
117
118 if (!bAutoFadeOut)
119 {
120 return;
121 }
122
123 if (FadeDelay > 0.0f)
124 {
125 GetWorld()->GetTimerManager().SetTimer(FadeTimerHandler, this, &UFadeManager::StartFadeOut, FadeDelay);
126 }
127 else
128 {
129 StartFadeOut();
130 }
131}
132
134{
135 float FadeDuration = FadeOutDuration >= MinFadeTime ? FadeOutDuration : MinFadeTime;
136
137 GetWorld()->GetTimerManager().SetTimer(FadeTimerHandler, this, &UFadeManager::FadeOutFinished, FadeDuration);
138
139 for (auto It = GetWorld()->GetPlayerControllerIterator(); It; ++It)
140 {
141 if (APixoVRPlayerController* PlayerController = Cast<APixoVRPlayerController>(It->Get()))
142 {
143 PlayerController->ClientFadeOut(FadeDuration);
144 }
145 }
146}
147
149{
150 if (FadeOutCallback)
151 {
153 }
154}
#define DEFINE_EVENT_HANDLER(TEventType)
Definition BaseManager.h:13
@ FadeIn
A custom player controller class for PixoVR.
void HandleEvent_Impl(class UBaseEvent *Event)
Event used to call fade-in with auto fade-out.
Event used to call fade-in.
Definition FadeInEvent.h:16
static bool bNewLevelFadeOut
Flag indicating whether we need to do fade-out after loading new level.
Definition FadeManager.h:86
float MinFadeTime
Definition FadeManager.h:88
float FadeInDuration
Definition FadeManager.h:81
void StartFadeIn()
UFUNCTION()
void FadeInFinished()
UFUNCTION()
bool BlockFade
UPROPERTY(BlueprintReadWrite, Category = "FadeManager|Parameters")
Definition FadeManager.h:59
FOnFadeInFinished OnFadeInFinished
UPROPERTY(BlueprintAssignable)
Definition FadeManager.h:53
bool bAutoFadeOut
Flag indicating whether automatic fade-out after fade-in is enabled.
Definition FadeManager.h:84
void FadeOutFinished() const
UFUNCTION()
TFunction< void()> FadeOutCallback
Definition FadeManager.h:92
FTimerHandle FadeTimerHandler
Definition FadeManager.h:80
void OpenLevelWithFade(FName LevelName)
UFUNCTION(BlueprintCallable)
TFunction< void()> FadeInCallback
Definition FadeManager.h:91
float FadeDelay
Definition FadeManager.h:82
float FadeOutDuration
Definition FadeManager.h:83
void StartFadeOut()
UFUNCTION()
void ShowFade(bool FadeIn, float Duration)
Shows a fade effect.
Event used to call fade-out.