KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UCircularProgressBar.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
3
5
6#include "Components/Image.h"
7
9{
10 Super::NativePreConstruct();
11 ApplyStyle();
12}
13
14void UCircularProgressBar::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
15{
16 Super::NativeTick(MyGeometry, InDeltaTime);
17
18 // 애니메이션 업데이트
19 if (bIsAnimating)
20 {
21 AnimElapsedTime += InDeltaTime;
22
23 // 진행률 계산 (0.0 ~ 1.0)
24 float Progress = FMath::Clamp(AnimElapsedTime / AnimDuration, 0.0f, 1.0f);
25
26 // EaseOutSine 적용
27 float EasedProgress = easeOutSine(Progress);
28
29 // Start에서 Target으로 Lerp
30 Percent = FMath::Lerp(AnimStartPercent, AnimTargetPercent, EasedProgress);
31
32 // 스타일 적용
33 ApplyStyle();
34
35 // 애니메이션 완료
36 if (Progress >= 1.0f)
37 {
38 bIsAnimating = false;
39 Percent = AnimTargetPercent; // 정확한 값으로 설정
40 ApplyStyle();
41 }
42 }
43}
44
45void UCircularProgressBar::SetPercent(const float InPercent)
46{
47 // 애니메이션 중단
48 bIsAnimating = false;
49
50 Percent = FMath::Clamp(InPercent, 0.0f, 1.0f);
51 ApplyStyle();
52}
53
54void UCircularProgressBar::StartProgress(const float Start, const float End, const float Duration)
55{
56 // 애니메이션 설정
57 AnimStartPercent = FMath::Clamp(Start, 0.0f, 1.0f);
58 AnimTargetPercent = FMath::Clamp(End, 0.0f, 1.0f);
59 AnimDuration = FMath::Max(Duration, 0.01f); // 최소 0.01초
60 AnimElapsedTime = 0.0f;
61
62 // 시작 값으로 설정
64 ApplyStyle();
65
66 // 애니메이션 시작
67 bIsAnimating = true;
68}
69
74
76{
77 if (!Img_CircularBar)
78 return;
79
80 auto DynamicMaterial = Img_CircularBar->GetDynamicMaterial();
81 if (DynamicMaterial)
82 {
83 // Percent 값 설정
84 DynamicMaterial->SetScalarParameterValue(TEXT("Percent"), Percent);
85
86 // Percent에 따라 색상 Lerp
87 FLinearColor FilledColor;
88 if (Percent <= 0.5f)
89 {
90 // 0% ~ 50%: LowColor → MidColor
91 float Alpha = Percent * 2.0f; // 0.0 ~ 1.0으로 정규화
92 FilledColor = FLinearColor::LerpUsingHSV(LowColor, MidColor, Alpha);
93 }
94 else
95 {
96 // 50% ~ 100%: MidColor → HighColor
97 float Alpha = (Percent - 0.5f) * 2.0f; // 0.0 ~ 1.0으로 정규화
98 FilledColor = FLinearColor::LerpUsingHSV(MidColor, HighColor, Alpha);
99 }
100
101 // FilledColor 파라미터 설정
102 DynamicMaterial->SetVectorParameterValue(TEXT("FilledColor"), FilledColor);
103 }
104}
float Percent
진행률 (0.0 ~ 1.0)
virtual void NativeTick(const FGeometry &MyGeometry, float InDeltaTime) override
FLinearColor MidColor
중간 진행률 색상 (50%)
void SetPercent(const float InPercent)
FLinearColor HighColor
높은 진행률 색상 (50% ~ 100%)
FORCEINLINE double easeOutSine(const double Value)
FLinearColor LowColor
낮은 진행률 색상 (0% ~ 50%)
virtual void NativePreConstruct() override
void StartProgress(const float Start, const float End, const float Duration=1.0f)
Start에서 End까지 부드럽게 애니메이션
void StopProgress()
애니메이션 중단