Skip to content

Commit 763868d

Browse files
committed
Small tweaks to UI Fader
Still not functional
1 parent 1249a44 commit 763868d

File tree

6 files changed

+45
-86
lines changed

6 files changed

+45
-86
lines changed

UOP1_Project/Assets/Prefabs/GameplayEssentials/SceneLoader.prefab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ MonoBehaviour:
5151
_ToggleLoadingScreen: {fileID: 11400000, guid: ce8db9fc090944349ba225edb81028d4,
5252
type: 2}
5353
_OnSceneReady: {fileID: 11400000, guid: b729e40fc41dd8b4ea7aaf5c857f7186, type: 2}
54+
_OnFade: {fileID: 11400000, guid: b40bb60f3ca40164e9d7acc6992bae10, type: 2}

UOP1_Project/Assets/Scenes/PersistentManagers.unity

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,11 @@ Transform:
519519
m_PrefabAsset: {fileID: 0}
520520
m_GameObject: {fileID: 1122701836}
521521
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
522-
m_LocalPosition: {x: -1184.9143, y: -540, z: 0}
523-
m_LocalScale: {x: 2.057143, y: 2.057143, z: 2.057143}
522+
m_LocalPosition: {x: 113.785706, y: 0, z: 0}
523+
m_LocalScale: {x: 0.85714287, y: 0.85714287, z: 0.85714287}
524524
m_Children: []
525-
m_Father: {fileID: 1387982343}
526-
m_RootOrder: 2
525+
m_Father: {fileID: 0}
526+
m_RootOrder: 4
527527
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
528528
--- !u!114 &1242953036 stripped
529529
MonoBehaviour:
@@ -850,7 +850,6 @@ RectTransform:
850850
m_Children:
851851
- {fileID: 624605539}
852852
- {fileID: 363619425}
853-
- {fileID: 1122701838}
854853
- {fileID: 565765817888297794}
855854
m_Father: {fileID: 0}
856855
m_RootOrder: 0
@@ -989,7 +988,7 @@ RectTransform:
989988
m_LocalScale: {x: 1, y: 1, z: 1}
990989
m_Children: []
991990
m_Father: {fileID: 1387982343}
992-
m_RootOrder: 3
991+
m_RootOrder: 2
993992
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
994993
m_AnchorMin: {x: 0, y: 0}
995994
m_AnchorMax: {x: 1, y: 1}
@@ -1003,6 +1002,11 @@ PrefabInstance:
10031002
m_Modification:
10041003
m_TransformParent: {fileID: 0}
10051004
m_Modifications:
1005+
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
1006+
type: 3}
1007+
propertyPath: m_RootOrder
1008+
value: 1
1009+
objectReference: {fileID: 0}
10061010
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
10071011
type: 3}
10081012
propertyPath: m_LocalPosition.x
@@ -1018,6 +1022,11 @@ PrefabInstance:
10181022
propertyPath: m_LocalPosition.z
10191023
value: 29.12
10201024
objectReference: {fileID: 0}
1025+
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
1026+
type: 3}
1027+
propertyPath: m_LocalRotation.w
1028+
value: 1
1029+
objectReference: {fileID: 0}
10211030
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
10221031
type: 3}
10231032
propertyPath: m_LocalRotation.x
@@ -1033,16 +1042,6 @@ PrefabInstance:
10331042
propertyPath: m_LocalRotation.z
10341043
value: 0
10351044
objectReference: {fileID: 0}
1036-
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
1037-
type: 3}
1038-
propertyPath: m_LocalRotation.w
1039-
value: 1
1040-
objectReference: {fileID: 0}
1041-
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
1042-
type: 3}
1043-
propertyPath: m_RootOrder
1044-
value: 1
1045-
objectReference: {fileID: 0}
10461045
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
10471046
type: 3}
10481047
propertyPath: m_LocalEulerAnglesHint.x
@@ -1079,8 +1078,8 @@ MonoBehaviour:
10791078
m_EditorClassIdentifier:
10801079
m_Material: {fileID: 0}
10811080
m_Color: {r: 0, g: 0, b: 0, a: 0}
1082-
m_RaycastTarget: 1
1083-
m_Maskable: 1
1081+
m_RaycastTarget: 0
1082+
m_Maskable: 0
10841083
m_OnCullStateChanged:
10851084
m_PersistentCalls:
10861085
m_Calls: []
@@ -1106,7 +1105,7 @@ GameObject:
11061105
- component: {fileID: 138035865882902116}
11071106
- component: {fileID: 6952518526949780777}
11081107
m_Layer: 5
1109-
m_Name: Fadeout Rectangle
1108+
m_Name: FadeoutRectangle
11101109
m_TagString: Untagged
11111110
m_Icon: {fileID: 0}
11121111
m_NavMeshLayer: 0

UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeChannelSO.asset renamed to UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeEventChannel.asset

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@ MonoBehaviour:
1010
m_Enabled: 1
1111
m_EditorHideFlags: 0
1212
m_Script: {fileID: 11500000, guid: 2f3f18ccb43e7594cb1a18cfbc24190e, type: 3}
13-
m_Name: FadeChannelSO
13+
m_Name: FadeEventChannel
1414
m_EditorClassIdentifier:
15-
_color: {r: 0, g: 0, b: 0, a: 0}
16-
_inDuration: 1
17-
_outDuration: 1
18-
_holdDuration: 1

UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
/// </summary>
99
public class SceneLoader : MonoBehaviour
1010
{
11-
[Header("Persistent Manager Scene")]
1211
[SerializeField] private GameSceneSO _persistentManagersScene = default;
13-
14-
[Header("Gameplay Scene")]
1512
[SerializeField] private GameSceneSO _gameplayScene = default;
1613

1714
[Header("Load Events")]
@@ -23,6 +20,7 @@ public class SceneLoader : MonoBehaviour
2320
[Header("Broadcasting on")]
2421
[SerializeField] private BoolEventChannelSO _ToggleLoadingScreen = default;
2522
[SerializeField] private VoidEventChannelSO _OnSceneReady = default;
23+
[SerializeField] private FadeChannelSO _OnFade = default;
2624

2725
private List<AsyncOperation> _scenesToLoadAsyncOperations = new List<AsyncOperation>();
2826
private List<Scene> _scenesToUnload = new List<Scene>();

UOP1_Project/Assets/Scripts/UI/FadeManager.cs

Lines changed: 24 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,55 @@
55

66
public class FadeManager : MonoBehaviour
77
{
8-
[Header("Fade Event")]
98
[SerializeField] private FadeChannelSO _fadeChannelSO;
10-
11-
[Header("Fade Image")]
129
[SerializeField] private Image _imageComponent;
1310

14-
private bool IsCurrentlyFading = false;
11+
private bool _isCurrentlyFading = false;
1512

16-
/// <summary>
17-
/// Enumerators that fades in the canvas's imageComponent to turn the screen to a flat color over time. Fadeins called simeutaneously will only fade in the earliest call and discard any others.
18-
/// </summary>
19-
/// <param name="duration">How long it takes to the image to fade in.</param>
20-
/// <param name="color">Target color for the image to reach.</param>
21-
/// <returns></returns>
22-
private IEnumerator FadeInEnum(float duration, Color color)
13+
private void OnEnable()
2314
{
24-
float totalTime = 0f; // Total amount of time this coroutine has taken. Determines when the fadein will end and what color the imageComponent should be at every frame.
25-
while (totalTime <= duration)
26-
{
27-
totalTime += Time.deltaTime;
28-
_imageComponent.color = Color.Lerp(new Color(0, 0, 0, 0), color, totalTime/duration); // Sets the image's color to a mixture between total transparency and the target color, and interpolates based on the amount of time to completion.
29-
yield return null;
30-
}
31-
_imageComponent.color = color; // Here to guarentee the image is exactly the requested color at the end of the loop.
32-
IsCurrentlyFading = false;
33-
yield return null;
15+
_fadeChannelSO.OnEventRaised += InitiateFade;
16+
}
17+
18+
private void OnDisable()
19+
{
20+
_fadeChannelSO.OnEventRaised -= InitiateFade;
3421
}
3522

3623
/// <summary>
37-
/// Enumerators that fades out the canvas's imageComponent to turn the screen to normal gameplay color over time. Fadeouts called simeutaneously will only fade out the earliest call and discard any others.
24+
/// Enumerator that fades in the canvas's imageComponent to turn the screen to a flat color over time. Fadeins called simeutaneously will only fade in the earliest call and discard any others.
3825
/// </summary>
39-
/// <param name="duration">How long it takes to the image to fade out.</param>
40-
/// <returns></returns>
41-
private IEnumerator FadeOutEnum(float duration, Color color = default)
26+
private IEnumerator FadeCoroutine(bool fadeIn, float duration, Color endColor = default)
4227
{
43-
if (color == default)
44-
color = _imageComponent.color; // Stores the old color of the image component, as we can't assume the image will always be black, if no color is specified.
45-
float totalTime = 0f; // Total amount of time this coroutine has taken. Determines when the fadeout will end and what color the imageComponent should be at every frame.
28+
Color startColor = _imageComponent.color;
29+
if (fadeIn) endColor = Color.clear;
30+
31+
float totalTime = 0f;
32+
4633
while (totalTime <= duration)
4734
{
4835
totalTime += Time.deltaTime;
49-
_imageComponent.color = Color.Lerp(color, new Color(0, 0, 0, 0), totalTime / duration); // Sets the image's color to a mixture between the old color and total transparency, and interpolates based on the amount of time to completion.
50-
yield return null;
51-
}
52-
_imageComponent.color = new Color(0, 0, 0, 0); // Here to guarentee the image is fully transparent at the end of the loop.
53-
IsCurrentlyFading = false;
54-
yield return null;
55-
}
36+
_imageComponent.color = Color.Lerp(startColor, endColor, totalTime/duration);
5637

57-
private void OnEnable()
58-
{
59-
if (_fadeChannelSO != null)
60-
{
61-
_fadeChannelSO.OnEventRaised += fadeGeneral;
38+
yield return null;
6239
}
63-
}
6440

65-
private void OnDisable()
66-
{
67-
if (_fadeChannelSO != null)
68-
{
69-
_fadeChannelSO.OnEventRaised += fadeGeneral;
70-
}
41+
_imageComponent.color = endColor; //Force to end result
42+
_isCurrentlyFading = false;
7143
}
7244

7345
/// <summary>
7446
/// Controls the fade-in and fade-out.
7547
/// </summary>
76-
/// <param name="fadeIn">If true, the rectangle fades in. If false, the rectangle fades out.</param>
48+
/// <param name="fadeIn">If true, rectangle fades out and gameplay is visible. If false, the screen becomes black.</param>
7749
/// <param name="duration">How long it takes to the image to fade in/out.</param>
7850
/// <param name="color">Target color for the image to reach. Disregarded when fading out.</param>
79-
private void fadeGeneral(bool fadeIn, float duration, Color color)
51+
private void InitiateFade(bool fadeIn, float duration, Color desiredColor)
8052
{
81-
if (!IsCurrentlyFading) // Makes sure multiple fade-ins or outs don't happen at the same time. Note this will mean fadeouts called at the same time will be discarded.
53+
if (!_isCurrentlyFading) // Makes sure multiple fade-ins or outs don't happen at the same time. Note this will mean fadeouts called at the same time will be discarded.
8254
{
83-
IsCurrentlyFading = true;
84-
if (fadeIn)
85-
{
86-
StartCoroutine(FadeInEnum(duration, color));
87-
}
88-
else
89-
{
90-
StartCoroutine(FadeOutEnum(duration, color)); // Fadeout doesn't need color, so the color parameter is disregarded.
91-
}
55+
_isCurrentlyFading = true;
56+
StartCoroutine(FadeCoroutine(fadeIn, duration, desiredColor));
9257
}
9358
}
9459
}

0 commit comments

Comments
 (0)