浏览代码

Small tweaks to UI Fader

Still not functional
/UI
Ciro Continisio 4 年前
当前提交
c799113a
共有 7 个文件被更改,包括 58 次插入99 次删除
  1. 1
      UOP1_Project/Assets/Prefabs/GameplayEssentials/SceneLoader.prefab
  2. 37
      UOP1_Project/Assets/Scenes/PersistentManagers.unity
  3. 4
      UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs
  4. 83
      UOP1_Project/Assets/Scripts/UI/FadeManager.cs
  5. 14
      UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeEventChannel.asset
  6. 18
      UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeChannelSO.asset
  7. 0
      /UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeEventChannel.asset.meta

1
UOP1_Project/Assets/Prefabs/GameplayEssentials/SceneLoader.prefab


_ToggleLoadingScreen: {fileID: 11400000, guid: ce8db9fc090944349ba225edb81028d4,
type: 2}
_OnSceneReady: {fileID: 11400000, guid: b729e40fc41dd8b4ea7aaf5c857f7186, type: 2}
_OnFade: {fileID: 11400000, guid: b40bb60f3ca40164e9d7acc6992bae10, type: 2}

37
UOP1_Project/Assets/Scenes/PersistentManagers.unity


m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1122701836}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -1184.9143, y: -540, z: 0}
m_LocalScale: {x: 2.057143, y: 2.057143, z: 2.057143}
m_LocalPosition: {x: 113.785706, y: 0, z: 0}
m_LocalScale: {x: 0.85714287, y: 0.85714287, z: 0.85714287}
m_Father: {fileID: 1387982343}
m_RootOrder: 2
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1242953036 stripped
MonoBehaviour:

m_Children:
- {fileID: 624605539}
- {fileID: 363619425}
- {fileID: 1122701838}
- {fileID: 565765817888297794}
m_Father: {fileID: 0}
m_RootOrder: 0

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1387982343}
m_RootOrder: 3
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}

m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
type: 3}
propertyPath: m_LocalPosition.x

objectReference: {fileID: 0}
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}

objectReference: {fileID: 0}
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3845877873755819563, guid: ff36e7f2f7928454dae0a4d9af31e076,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}

m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 0}
m_RaycastTarget: 1
m_Maskable: 1
m_RaycastTarget: 0
m_Maskable: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []

- component: {fileID: 138035865882902116}
- component: {fileID: 6952518526949780777}
m_Layer: 5
m_Name: Fadeout Rectangle
m_Name: FadeoutRectangle
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

4
UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs


/// </summary>
public class SceneLoader : MonoBehaviour
{
[Header("Persistent Manager Scene")]
[Header("Gameplay Scene")]
[SerializeField] private GameSceneSO _gameplayScene = default;
[Header("Load Events")]

[Header("Broadcasting on")]
[SerializeField] private BoolEventChannelSO _ToggleLoadingScreen = default;
[SerializeField] private VoidEventChannelSO _OnSceneReady = default;
[SerializeField] private FadeChannelSO _OnFade = default;
private List<AsyncOperation> _scenesToLoadAsyncOperations = new List<AsyncOperation>();
private List<Scene> _scenesToUnload = new List<Scene>();

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


public class FadeManager : MonoBehaviour
{
[Header("Fade Event")]
[Header("Fade Image")]
private bool IsCurrentlyFading = false;
private bool _isCurrentlyFading = false;
/// <summary>
/// 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.
/// </summary>
/// <param name="duration">How long it takes to the image to fade in.</param>
/// <param name="color">Target color for the image to reach.</param>
/// <returns></returns>
private IEnumerator FadeInEnum(float duration, Color color)
private void OnEnable()
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.
while (totalTime <= duration)
{
totalTime += Time.deltaTime;
_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.
yield return null;
}
_imageComponent.color = color; // Here to guarentee the image is exactly the requested color at the end of the loop.
IsCurrentlyFading = false;
yield return null;
_fadeChannelSO.OnEventRaised += InitiateFade;
}
private void OnDisable()
{
_fadeChannelSO.OnEventRaised -= InitiateFade;
/// 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.
/// 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.
/// <param name="duration">How long it takes to the image to fade out.</param>
/// <returns></returns>
private IEnumerator FadeOutEnum(float duration, Color color = default)
private IEnumerator FadeCoroutine(bool fadeIn, float duration, Color endColor = default)
if (color == default)
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.
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.
Color startColor = _imageComponent.color;
if (fadeIn) endColor = Color.clear;
float totalTime = 0f;
_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.
_imageComponent.color = Color.Lerp(startColor, endColor, totalTime/duration);
_imageComponent.color = new Color(0, 0, 0, 0); // Here to guarentee the image is fully transparent at the end of the loop.
IsCurrentlyFading = false;
yield return null;
}
private void OnEnable()
{
if (_fadeChannelSO != null)
{
_fadeChannelSO.OnEventRaised += fadeGeneral;
}
}
private void OnDisable()
{
if (_fadeChannelSO != null)
{
_fadeChannelSO.OnEventRaised += fadeGeneral;
}
_imageComponent.color = endColor; //Force to end result
_isCurrentlyFading = false;
/// <param name="fadeIn">If true, the rectangle fades in. If false, the rectangle fades out.</param>
/// <param name="fadeIn">If true, rectangle fades out and gameplay is visible. If false, the screen becomes black.</param>
private void fadeGeneral(bool fadeIn, float duration, Color color)
private void InitiateFade(bool fadeIn, float duration, Color desiredColor)
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.
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.
IsCurrentlyFading = true;
if (fadeIn)
{
StartCoroutine(FadeInEnum(duration, color));
}
else
{
StartCoroutine(FadeOutEnum(duration, color)); // Fadeout doesn't need color, so the color parameter is disregarded.
}
_isCurrentlyFading = true;
StartCoroutine(FadeCoroutine(fadeIn, duration, desiredColor));
}
}
}

14
UOP1_Project/Assets/ScriptableObjects/Events/UI/FadeEventChannel.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2f3f18ccb43e7594cb1a18cfbc24190e, type: 3}
m_Name: FadeEventChannel
m_EditorClassIdentifier:

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


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2f3f18ccb43e7594cb1a18cfbc24190e, type: 3}
m_Name: FadeChannelSO
m_EditorClassIdentifier:
_color: {r: 0, g: 0, b: 0, a: 0}
_inDuration: 1
_outDuration: 1
_holdDuration: 1

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

正在加载...
取消
保存