浏览代码

Added FadeOut color selection compatability and default parameters.

/devlogs-3-input
IroncladLandship 4 年前
当前提交
1b4ab2a6
共有 2 个文件被更改,包括 13 次插入28 次删除
  1. 31
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/UI/FadeChannelSO.cs
  2. 10
      UOP1_Project/Assets/Scripts/UI/FadeManager.cs

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


/// <param name="fadeIn">If true, the rectangle fades in. If false, the rectangle fades out.</param>
/// <param name="duration">How long it takes to the image to fade in/out.</param>
/// <param name="color">Target color for the image to reach. Disregarded when fading out.</param>
public void Fade(bool fadeIn, float duration, Color color)
public void Fade(bool fadeIn, float duration, Color color = default)
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.
color = Color.black;
/// Generic fade function. Communicates with <seealso cref="FadeManager.cs"/>.
/// </summary>
/// <param name="fadeIn">If true, the rectangle fades in. If false, the rectangle fades out.</param>
/// <param name="duration">How long it takes to the image to fade in/out.</param>
public void Fade(bool fadeIn, float duration)
{
if (OnEventRaised != null)
OnEventRaised.Invoke(fadeIn, duration, new Color(0, 0, 0, 1));
}
/// <summary>
public void FadeIn(float duration, Color color)
public void FadeIn(float duration, Color color = default)
if (color == default)
color = Color.black;
/// Fade helper function to simplify usage. Fades in the rectangle.
/// </summary>
/// <param name="duration">How long it takes to the image to fade in.</param>
public void FadeIn(float duration)
{
Fade(true, duration, new Color(0, 0, 0, 1));
}
/// <summary>
public void FadeOut(float duration)
public void FadeOut(float duration, Color color = default)
Fade(false, duration, new Color(0, 0, 0, 1));
Fade(false, duration, color);
}
}

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


/// </summary>
/// <param name="duration">How long it takes to the image to fade out.</param>
/// <returns></returns>
private IEnumerator FadeOutEnum(float duration)
private IEnumerator FadeOutEnum(float duration, Color color = default)
Color oldColor = _imageComponent.color; // Temporarily stores the old color of the image component, as we can't assume the image will always be black.
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.
_imageComponent.color = Color.Lerp(oldColor, 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(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.
yield return null;
}
_imageComponent.color = new Color(0, 0, 0, 0); // Here to guarentee the image is fully transparent at the end of the loop.

}
else
{
StartCoroutine(FadeOutEnum(duration)); // Fadeout doesn't need color, so the color parameter is disregarded.
// I would like to say that setting the color for the fadeout wouldn't be hard to implement, but I reckon most people wouldn't use it, so it would just be an unnecessary burden.
StartCoroutine(FadeOutEnum(duration, color)); // Fadeout doesn't need color, so the color parameter is disregarded.
}
}
}
正在加载...
取消
保存