Skip to content

Commit f7a2fb5

Browse files
committed
feat: initial cutscene
1 parent a8f7b37 commit f7a2fb5

File tree

4 files changed

+286
-79
lines changed

4 files changed

+286
-79
lines changed

Assets/ProgressBar/Script/ProgressBar.cs

+76-9
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,106 @@
22
using UnityEngine.UI;
33
using TMPro;
44

5+
/// <summary>
6+
/// Manages the behavior of a progress bar, including updating the fill amount, color, and title.
7+
/// Can be used to visually represent a task's progress.
8+
/// </summary>
59
[ExecuteInEditMode]
610
public class ProgressBar : MonoBehaviour
711
{
812
[Header("UI Components")]
13+
[Tooltip("The background image of the progress bar.")]
914
[SerializeField] private Image barBackground;
15+
16+
[Tooltip("The image that represents the filled portion of the progress bar.")]
1017
[SerializeField] private Image bar;
18+
19+
[Tooltip("The text component that displays the progress title.")]
1120
[SerializeField] private TextMeshProUGUI title;
1221

1322
[Header("Settings")]
23+
[Tooltip("The current value of the progress bar (0 to 100).")]
1424
[Range(0f, 100f)]
1525
[SerializeField] private float barValue = 20f;
26+
27+
[Tooltip("The color of the filled portion of the progress bar.")]
1628
[SerializeField] private Color barColor = Color.green;
1729

30+
/// <summary>
31+
/// Initializes the progress bar and updates the UI components based on the current value.
32+
/// </summary>
1833
private void Start()
1934
{
20-
if (bar == null || title == null)
35+
ValidateComponents();
36+
UpdateProgressBar(barValue);
37+
}
38+
39+
/// <summary>
40+
/// Updates the progress bar's fill amount, color, and text based on the provided value.
41+
/// </summary>
42+
/// <param name="value">The current progress value (0 to 100).</param>
43+
private void UpdateProgressBar(float value)
44+
{
45+
// Ensure the value is clamped between 0 and 100.
46+
value = Mathf.Clamp(value, 0f, 100f);
47+
48+
if (bar != null)
49+
{
50+
// Update the bar's fill amount and color.
51+
bar.fillAmount = value / 100f;
52+
bar.color = barColor;
53+
}
54+
55+
if (title != null)
2156
{
22-
Debug.LogError("Bar or Title component is missing.");
23-
return;
57+
// Update the title text to reflect the current value.
58+
title.text = $"Fixing... ({value:F0}%)";
2459
}
60+
}
2561

62+
/// <summary>
63+
/// Called automatically by Unity whenever a serialized field is modified in the Inspector.
64+
/// Ensures that changes in the Inspector are immediately reflected in the UI.
65+
/// </summary>
66+
private void OnValidate()
67+
{
68+
ValidateComponents();
2669
UpdateProgressBar(barValue);
2770
}
2871

29-
private void UpdateProgressBar(float value)
72+
/// <summary>
73+
/// Validates that all required UI components (bar, title) are assigned, and logs an error if any are missing.
74+
/// </summary>
75+
private void ValidateComponents()
3076
{
31-
bar.fillAmount = value / 100f;
32-
bar.color = barColor;
33-
title.text = $"Fixing... ({value:F0}%)";
77+
if (bar == null)
78+
{
79+
Debug.LogError("Bar component is missing. Please assign a valid Image for the progress bar.");
80+
}
81+
82+
if (title == null)
83+
{
84+
Debug.LogError("Title component is missing. Please assign a valid TextMeshProUGUI for the title.");
85+
}
3486
}
3587

36-
private void OnValidate()
88+
/// <summary>
89+
/// Sets the value of the progress bar and updates the UI accordingly.
90+
/// </summary>
91+
/// <param name="newValue">The new progress value (0 to 100).</param>
92+
public void SetValue(float newValue)
93+
{
94+
barValue = newValue;
95+
UpdateProgressBar(barValue);
96+
}
97+
98+
/// <summary>
99+
/// Sets the color of the progress bar and updates the UI accordingly.
100+
/// </summary>
101+
/// <param name="newColor">The new color for the filled portion of the progress bar.</param>
102+
public void SetColor(Color newColor)
37103
{
104+
barColor = newColor;
38105
UpdateProgressBar(barValue);
39106
}
40-
}
107+
}

Assets/Scenes/Reparation.unity

+178-3
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,7 @@ PrefabInstance:
25502550
objectReference: {fileID: 1475119614}
25512551
- target: {fileID: 114769781544105922, guid: 5eefba205a58c8c4a937c97b87c185a3, type: 3}
25522552
propertyPath: barValue
2553-
value: 86.2
2553+
value: 46.4
25542554
objectReference: {fileID: 0}
25552555
- target: {fileID: 114769781544105922, guid: 5eefba205a58c8c4a937c97b87c185a3, type: 3}
25562556
propertyPath: m_Enabled
@@ -17905,6 +17905,9 @@ PrefabInstance:
1790517905
- targetCorrespondingSourceObject: {fileID: 4459864850019384750, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
1790617906
insertIndex: -1
1790717907
addedObject: {fileID: 1128651451}
17908+
- targetCorrespondingSourceObject: {fileID: 4459864850019384750, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
17909+
insertIndex: -1
17910+
addedObject: {fileID: 1128651459}
1790817911
- targetCorrespondingSourceObject: {fileID: 4459864851310106424, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
1790917912
insertIndex: -1
1791017913
addedObject: {fileID: 848670200}
@@ -17958,6 +17961,11 @@ MonoBehaviour:
1795817961
m_MipBias: 0
1795917962
m_VarianceClampScale: 0.9
1796017963
m_ContrastAdaptiveSharpening: 0
17964+
--- !u!20 &848670201 stripped
17965+
Camera:
17966+
m_CorrespondingSourceObject: {fileID: 4459864851310106426, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
17967+
m_PrefabInstance: {fileID: 848670198}
17968+
m_PrefabAsset: {fileID: 0}
1796117969
--- !u!1001 &849679832
1796217970
PrefabInstance:
1796317971
m_ObjectHideFlags: 0
@@ -24698,7 +24706,21 @@ MonoBehaviour:
2469824706
m_EditorClassIdentifier:
2469924707
welderPrefab: {fileID: 1071434719}
2470024708
rayDistance: 100
24701-
playerCamera: {fileID: 0}
24709+
playerCamera: {fileID: 848670201}
24710+
--- !u!114 &1128651459
24711+
MonoBehaviour:
24712+
m_ObjectHideFlags: 0
24713+
m_CorrespondingSourceObject: {fileID: 0}
24714+
m_PrefabInstance: {fileID: 0}
24715+
m_PrefabAsset: {fileID: 0}
24716+
m_GameObject: {fileID: 635657467}
24717+
m_Enabled: 1
24718+
m_EditorHideFlags: 0
24719+
m_Script: {fileID: 11500000, guid: 4a01d43f8d9f455193df9fb30c944807, type: 3}
24720+
m_Name:
24721+
m_EditorClassIdentifier:
24722+
splineParent: {fileID: 2055782988}
24723+
speed: 0.1
2470224724
--- !u!4 &1130256303 stripped
2470324725
Transform:
2470424726
m_CorrespondingSourceObject: {fileID: -5819118886272102141, guid: e0f672a015f8fee418afd70dfd718f0d, type: 3}
@@ -32515,7 +32537,7 @@ MonoBehaviour:
3251532537
m_OnCullStateChanged:
3251632538
m_PersistentCalls:
3251732539
m_Calls: []
32518-
m_text: Fixing... (86%)
32540+
m_text: Fixing... (46%)
3251932541
m_isRightToLeft: 0
3252032542
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
3252132543
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -33171,6 +33193,7 @@ Transform:
3317133193
- {fileID: 557190189}
3317233194
- {fileID: 1964668404}
3317333195
- {fileID: 2098095642}
33196+
- {fileID: 2055782988}
3317433197
m_Father: {fileID: 0}
3317533198
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
3317633199
--- !u!1 &1497520578
@@ -45694,6 +45717,158 @@ PrefabInstance:
4569445717
m_AddedGameObjects: []
4569545718
m_AddedComponents: []
4569645719
m_SourcePrefab: {fileID: 9199261849990390558, guid: 95d3d6bd77177bd4b978473257fc8079, type: 3}
45720+
--- !u!1 &2055782987
45721+
GameObject:
45722+
m_ObjectHideFlags: 0
45723+
m_CorrespondingSourceObject: {fileID: 0}
45724+
m_PrefabInstance: {fileID: 0}
45725+
m_PrefabAsset: {fileID: 0}
45726+
serializedVersion: 6
45727+
m_Component:
45728+
- component: {fileID: 2055782988}
45729+
- component: {fileID: 2055782989}
45730+
m_Layer: 0
45731+
m_Name: Camera Cutscene Spline
45732+
m_TagString: Untagged
45733+
m_Icon: {fileID: 0}
45734+
m_NavMeshLayer: 0
45735+
m_StaticEditorFlags: 0
45736+
m_IsActive: 1
45737+
--- !u!4 &2055782988
45738+
Transform:
45739+
m_ObjectHideFlags: 0
45740+
m_CorrespondingSourceObject: {fileID: 0}
45741+
m_PrefabInstance: {fileID: 0}
45742+
m_PrefabAsset: {fileID: 0}
45743+
m_GameObject: {fileID: 2055782987}
45744+
serializedVersion: 2
45745+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
45746+
m_LocalPosition: {x: 0, y: 3.1365824, z: 0}
45747+
m_LocalScale: {x: 1, y: 1, z: 1}
45748+
m_ConstrainProportionsScale: 0
45749+
m_Children: []
45750+
m_Father: {fileID: 1495273419}
45751+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
45752+
--- !u!114 &2055782989
45753+
MonoBehaviour:
45754+
m_ObjectHideFlags: 0
45755+
m_CorrespondingSourceObject: {fileID: 0}
45756+
m_PrefabInstance: {fileID: 0}
45757+
m_PrefabAsset: {fileID: 0}
45758+
m_GameObject: {fileID: 2055782987}
45759+
m_Enabled: 1
45760+
m_EditorHideFlags: 0
45761+
m_Script: {fileID: 11500000, guid: dab5c7d4c32e743048dfca98e2d5914f, type: 3}
45762+
m_Name:
45763+
m_EditorClassIdentifier:
45764+
m_Spline:
45765+
m_EditModeType: 1
45766+
m_Knots: []
45767+
m_MetaData: []
45768+
m_Closed: 0
45769+
m_IntData:
45770+
m_Data: []
45771+
m_FloatData:
45772+
m_Data: []
45773+
m_Float4Data:
45774+
m_Data: []
45775+
m_ObjectData:
45776+
m_Data: []
45777+
m_Splines:
45778+
- m_EditModeType: 1
45779+
m_Knots:
45780+
- Position:
45781+
x: 43.720047
45782+
y: -18.72
45783+
z: -79.8086
45784+
TangentIn:
45785+
x: 0
45786+
y: 0
45787+
z: -24.665
45788+
TangentOut:
45789+
x: 0
45790+
y: 0
45791+
z: 24.665
45792+
Rotation:
45793+
value:
45794+
x: 0
45795+
y: -0.3112445
45796+
z: -0
45797+
w: 0.95032984
45798+
- Position:
45799+
x: 14.590047
45800+
y: -20
45801+
z: 13.361394
45802+
TangentIn:
45803+
x: 0
45804+
y: 0
45805+
z: -16.995
45806+
TangentOut:
45807+
x: 0
45808+
y: 0
45809+
z: 16.995
45810+
Rotation:
45811+
value:
45812+
x: 0
45813+
y: 0.87226963
45814+
z: 0
45815+
w: -0.48902518
45816+
- Position:
45817+
x: -32.409954
45818+
y: -38.78
45819+
z: -23.638607
45820+
TangentIn:
45821+
x: 0
45822+
y: 0
45823+
z: -7.6307874
45824+
TangentOut:
45825+
x: 0
45826+
y: 0
45827+
z: 7.6307874
45828+
Rotation:
45829+
value:
45830+
x: 0
45831+
y: 0.965639
45832+
z: 0
45833+
w: -0.25988716
45834+
- Position:
45835+
x: -50.409954
45836+
y: -34.1
45837+
z: -92.6386
45838+
TangentIn:
45839+
x: 0
45840+
y: 0
45841+
z: -22.576
45842+
TangentOut:
45843+
x: 0
45844+
y: 0
45845+
z: 22.576
45846+
Rotation:
45847+
value:
45848+
x: 0
45849+
y: 0.9727732
45850+
z: 0
45851+
w: 0.23175892
45852+
m_MetaData:
45853+
- Mode: 2
45854+
Tension: 0.5
45855+
- Mode: 2
45856+
Tension: 0.5
45857+
- Mode: 2
45858+
Tension: 0.5
45859+
- Mode: 2
45860+
Tension: 0.5
45861+
m_Closed: 1
45862+
m_IntData:
45863+
m_Data: []
45864+
m_FloatData:
45865+
m_Data: []
45866+
m_Float4Data:
45867+
m_Data: []
45868+
m_ObjectData:
45869+
m_Data: []
45870+
m_Knots:
45871+
m_KnotsLink: []
4569745872
--- !u!1001 &2056055168
4569845873
PrefabInstance:
4569945874
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)