KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UHitStopSystem.cpp
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
2
8#include "UHitStopSystem.h"
9
10#include "GameFramework/Character.h"
11#include "UBroadcastManager.h"
12#include "UGameDataManager.h"
13#include "GameFramework/CharacterMovementComponent.h"
14
15UHitStopSystem::UHitStopSystem()
16{
17 PrimaryComponentTick.bCanEverTick = true;
18 PrimaryComponentTick.bTickEvenWhenPaused = true;
19}
20
21void UHitStopSystem::BeginPlay()
22{
23 Super::BeginPlay();
24}
25
26void UHitStopSystem::InitSystem(ACharacter* InOwner )
27{
28 this->Owner = InOwner;
29
30 MeshComp = Owner->GetMesh();
31 MoveComp = Owner->GetCharacterMovement();
32
33 if (auto EventManager = UBroadcastManager::Get(this))
34 {
35 EventManager->OnHitStop.AddDynamic(this, &UHitStopSystem::OnHitStop);
36 }
37}
38
39void UHitStopSystem::TickComponent(float DeltaTime, ELevelTick TickType,
40 FActorComponentTickFunction* ThisTickFunction)
41{
42 Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
43
44 if ( !bActive )
45 return;
46
47 const double Now = GetWorld()->GetRealTimeSeconds();
48 if (Now >= EndRealTimeSeconds)
49 EndFreeze();
50}
51
52void UHitStopSystem::OnHitStop(AActor* Target, const EDamageType Type)
53{
54 if (Target != Owner)
55 return;
56
57 ApplyHitStop(Type);
58}
59
60void UHitStopSystem::ApplyHitStop(const EDamageType Type)
61{
62 const double Now = GetWorld()->GetRealTimeSeconds();
63
64 FHitStopData Params;
65 if ( UGameDataManager::Get(GetWorld())->GetHitStopData(Type, Params) == false )
66 return;
67
68 if (!bActive)
69 {
70 BeginFreeze(Params);
71 EndRealTimeSeconds = Now + Params.Duration;
72 LastParams = Params;
73 return;
74 }
75
76 const bool Stronger = Params.TimeDilation < LastParams.TimeDilation;
77 const bool Longer = (Now + Params.Duration) > EndRealTimeSeconds;
78
79 if (Params.bRefreshIfStronger ? (Stronger || Longer) : Longer)
80 {
81 if (Stronger)
82 Owner->CustomTimeDilation = FMath::Clamp(Params.TimeDilation, 0.001f, 1.0f);
83
84 EndRealTimeSeconds = Now + Params.Duration;
85 LastParams = Params;
86 }
87}
88
89void UHitStopSystem::BeginFreeze(const FHitStopData& Params)
90{
91 bActive = true;
92
93 SavedCustomTimeDilation = Owner->CustomTimeDilation;
94
95 Owner->CustomTimeDilation = FMath::Clamp(Params.TimeDilation, 0.001f, 1.0f);
96 MoveComp->StopMovementImmediately();
97}
98
99void UHitStopSystem::EndFreeze()
100{
101 Owner->CustomTimeDilation = SavedCustomTimeDilation;
102 bActive = false;
103}
EDamageType
Definition EDamageType.h:9
UGameDataManager 클래스를 선언합니다.
UHitStopSystem 클래스를 선언합니다.
float TimeDilation
bool bRefreshIfStronger