Skip to content

Commit 1249a44

Browse files
committed
Merge branch 'main' of https://github.com/ZombieNub/open-project-1 into pr-bash
2 parents 413a003 + fcbc9e5 commit 1249a44

File tree

7 files changed

+306
-0
lines changed

7 files changed

+306
-0
lines changed

UOP1_Project/Assets/Scenes/PersistentManagers.unity

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,51 @@ CanvasRenderer:
480480
m_PrefabAsset: {fileID: 0}
481481
m_GameObject: {fileID: 841012433}
482482
m_CullTransparentMesh: 0
483+
--- !u!1 &1122701836
484+
GameObject:
485+
m_ObjectHideFlags: 0
486+
m_CorrespondingSourceObject: {fileID: 0}
487+
m_PrefabInstance: {fileID: 0}
488+
m_PrefabAsset: {fileID: 0}
489+
serializedVersion: 6
490+
m_Component:
491+
- component: {fileID: 1122701838}
492+
- component: {fileID: 1122701837}
493+
m_Layer: 0
494+
m_Name: FadeManager
495+
m_TagString: Untagged
496+
m_Icon: {fileID: 0}
497+
m_NavMeshLayer: 0
498+
m_StaticEditorFlags: 0
499+
m_IsActive: 1
500+
--- !u!114 &1122701837
501+
MonoBehaviour:
502+
m_ObjectHideFlags: 0
503+
m_CorrespondingSourceObject: {fileID: 0}
504+
m_PrefabInstance: {fileID: 0}
505+
m_PrefabAsset: {fileID: 0}
506+
m_GameObject: {fileID: 1122701836}
507+
m_Enabled: 1
508+
m_EditorHideFlags: 0
509+
m_Script: {fileID: 11500000, guid: d4a9e678d7a028b459e5b9971e79931a, type: 3}
510+
m_Name:
511+
m_EditorClassIdentifier:
512+
_fadeChannelSO: {fileID: 11400000, guid: b40bb60f3ca40164e9d7acc6992bae10, type: 2}
513+
_imageComponent: {fileID: 6952518526949780777}
514+
--- !u!4 &1122701838
515+
Transform:
516+
m_ObjectHideFlags: 0
517+
m_CorrespondingSourceObject: {fileID: 0}
518+
m_PrefabInstance: {fileID: 0}
519+
m_PrefabAsset: {fileID: 0}
520+
m_GameObject: {fileID: 1122701836}
521+
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}
524+
m_Children: []
525+
m_Father: {fileID: 1387982343}
526+
m_RootOrder: 2
527+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
483528
--- !u!114 &1242953036 stripped
484529
MonoBehaviour:
485530
m_CorrespondingSourceObject: {fileID: 3845877873755819562, guid: ff36e7f2f7928454dae0a4d9af31e076,
@@ -805,6 +850,8 @@ RectTransform:
805850
m_Children:
806851
- {fileID: 624605539}
807852
- {fileID: 363619425}
853+
- {fileID: 1122701838}
854+
- {fileID: 565765817888297794}
808855
m_Father: {fileID: 0}
809856
m_RootOrder: 0
810857
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -922,6 +969,33 @@ RectTransform:
922969
m_AnchoredPosition: {x: 0, y: 0}
923970
m_SizeDelta: {x: 100, y: 100}
924971
m_Pivot: {x: 0.5, y: 0.5}
972+
--- !u!222 &138035865882902116
973+
CanvasRenderer:
974+
m_ObjectHideFlags: 0
975+
m_CorrespondingSourceObject: {fileID: 0}
976+
m_PrefabInstance: {fileID: 0}
977+
m_PrefabAsset: {fileID: 0}
978+
m_GameObject: {fileID: 7398076546395718055}
979+
m_CullTransparentMesh: 0
980+
--- !u!224 &565765817888297794
981+
RectTransform:
982+
m_ObjectHideFlags: 0
983+
m_CorrespondingSourceObject: {fileID: 0}
984+
m_PrefabInstance: {fileID: 0}
985+
m_PrefabAsset: {fileID: 0}
986+
m_GameObject: {fileID: 7398076546395718055}
987+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
988+
m_LocalPosition: {x: 0, y: 0, z: 0}
989+
m_LocalScale: {x: 1, y: 1, z: 1}
990+
m_Children: []
991+
m_Father: {fileID: 1387982343}
992+
m_RootOrder: 3
993+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
994+
m_AnchorMin: {x: 0, y: 0}
995+
m_AnchorMax: {x: 1, y: 1}
996+
m_AnchoredPosition: {x: 0, y: 0}
997+
m_SizeDelta: {x: 0, y: 0}
998+
m_Pivot: {x: 0.5, y: 0.5}
925999
--- !u!1001 &3845877872784178022
9261000
PrefabInstance:
9271001
m_ObjectHideFlags: 0
@@ -991,3 +1065,50 @@ PrefabInstance:
9911065
objectReference: {fileID: 0}
9921066
m_RemovedComponents: []
9931067
m_SourcePrefab: {fileID: 100100000, guid: ff36e7f2f7928454dae0a4d9af31e076, type: 3}
1068+
--- !u!114 &6952518526949780777
1069+
MonoBehaviour:
1070+
m_ObjectHideFlags: 0
1071+
m_CorrespondingSourceObject: {fileID: 0}
1072+
m_PrefabInstance: {fileID: 0}
1073+
m_PrefabAsset: {fileID: 0}
1074+
m_GameObject: {fileID: 7398076546395718055}
1075+
m_Enabled: 1
1076+
m_EditorHideFlags: 0
1077+
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
1078+
m_Name:
1079+
m_EditorClassIdentifier:
1080+
m_Material: {fileID: 0}
1081+
m_Color: {r: 0, g: 0, b: 0, a: 0}
1082+
m_RaycastTarget: 1
1083+
m_Maskable: 1
1084+
m_OnCullStateChanged:
1085+
m_PersistentCalls:
1086+
m_Calls: []
1087+
m_Sprite: {fileID: 0}
1088+
m_Type: 0
1089+
m_PreserveAspect: 0
1090+
m_FillCenter: 1
1091+
m_FillMethod: 4
1092+
m_FillAmount: 1
1093+
m_FillClockwise: 1
1094+
m_FillOrigin: 0
1095+
m_UseSpriteMesh: 0
1096+
m_PixelsPerUnitMultiplier: 1
1097+
--- !u!1 &7398076546395718055
1098+
GameObject:
1099+
m_ObjectHideFlags: 0
1100+
m_CorrespondingSourceObject: {fileID: 0}
1101+
m_PrefabInstance: {fileID: 0}
1102+
m_PrefabAsset: {fileID: 0}
1103+
serializedVersion: 6
1104+
m_Component:
1105+
- component: {fileID: 565765817888297794}
1106+
- component: {fileID: 138035865882902116}
1107+
- component: {fileID: 6952518526949780777}
1108+
m_Layer: 5
1109+
m_Name: Fadeout Rectangle
1110+
m_TagString: Untagged
1111+
m_Icon: {fileID: 0}
1112+
m_NavMeshLayer: 0
1113+
m_StaticEditorFlags: 0
1114+
m_IsActive: 1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 2f3f18ccb43e7594cb1a18cfbc24190e, type: 3}
13+
m_Name: FadeChannelSO
14+
m_EditorClassIdentifier:
15+
_color: {r: 0, g: 0, b: 0, a: 0}
16+
_inDuration: 1
17+
_outDuration: 1
18+
_holdDuration: 1

UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeChannelSO.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEngine.Events;
5+
6+
[CreateAssetMenu(menuName = "Events/UI/Fade Channel")]
7+
public class FadeChannelSO : ScriptableObject
8+
{
9+
public UnityAction<bool, float, Color> OnEventRaised;
10+
/// <summary>
11+
/// Generic fade function. Communicates with <seealso cref="FadeManager.cs"/>.
12+
/// </summary>
13+
/// <param name="fadeIn">If true, the rectangle fades in. If false, the rectangle fades out.</param>
14+
/// <param name="duration">How long it takes to the image to fade in/out.</param>
15+
/// <param name="color">Target color for the image to reach. Disregarded when fading out.</param>
16+
public void Fade(bool fadeIn, float duration, Color color = default)
17+
{
18+
if (color == default && fadeIn) // If no fadein color is assigned, black is given as default. If we are supposed to fadeout the rectangle, default is simply passed through.
19+
color = Color.black;
20+
if (OnEventRaised != null)
21+
OnEventRaised.Invoke(fadeIn, duration, color);
22+
}
23+
24+
/// <summary>
25+
/// Fade helper function to simplify usage. Fades in the rectangle.
26+
/// </summary>
27+
/// <param name="duration">How long it takes to the image to fade in.</param>
28+
/// <param name="color">Target color for the image to reach.</param>
29+
public void FadeIn(float duration, Color color = default)
30+
{
31+
if (color == default)
32+
color = Color.black;
33+
Fade(true, duration, color);
34+
}
35+
/// <summary>
36+
/// Fade helper function to simplify usage. Fades out the rectangle.
37+
/// </summary>
38+
/// <param name="duration">How long it takes to the image to fade out.</param>
39+
public void FadeOut(float duration, Color color = default)
40+
{
41+
Fade(false, duration, color);
42+
}
43+
}

UOP1_Project/Assets/Scripts/Events/ScriptableObjects/UI/FadeChannelSO.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEngine.UI;
5+
6+
public class FadeManager : MonoBehaviour
7+
{
8+
[Header("Fade Event")]
9+
[SerializeField] private FadeChannelSO _fadeChannelSO;
10+
11+
[Header("Fade Image")]
12+
[SerializeField] private Image _imageComponent;
13+
14+
private bool IsCurrentlyFading = false;
15+
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)
23+
{
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;
34+
}
35+
36+
/// <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.
38+
/// </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)
42+
{
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.
46+
while (totalTime <= duration)
47+
{
48+
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+
}
56+
57+
private void OnEnable()
58+
{
59+
if (_fadeChannelSO != null)
60+
{
61+
_fadeChannelSO.OnEventRaised += fadeGeneral;
62+
}
63+
}
64+
65+
private void OnDisable()
66+
{
67+
if (_fadeChannelSO != null)
68+
{
69+
_fadeChannelSO.OnEventRaised += fadeGeneral;
70+
}
71+
}
72+
73+
/// <summary>
74+
/// Controls the fade-in and fade-out.
75+
/// </summary>
76+
/// <param name="fadeIn">If true, the rectangle fades in. If false, the rectangle fades out.</param>
77+
/// <param name="duration">How long it takes to the image to fade in/out.</param>
78+
/// <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)
80+
{
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.
82+
{
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+
}
92+
}
93+
}
94+
}

UOP1_Project/Assets/Scripts/UI/FadeManager.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)