mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix(AdditiveLevels): FadeInOut more user friendly
This commit is contained in:
parent
7333f88e1f
commit
1aedd8d7c0
@ -438,9 +438,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 363a8867bb9c7b845a73233566df8c1e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
stepRate: 0.02
|
||||
fadeImage: {fileID: 1040404845}
|
||||
fadeColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
stepRate: 2
|
||||
--- !u!114 &1300359892
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -7,22 +7,29 @@ namespace Mirror.Examples.AdditiveLevels
|
||||
public class FadeInOut : MonoBehaviour
|
||||
{
|
||||
// set these in the inspector
|
||||
[Range(0.01f, 10f), Tooltip("Rate of fade in / out: higher is faster")]
|
||||
public float stepRate = 0.02f;
|
||||
|
||||
[Tooltip("Reference to Image component on child panel")]
|
||||
public Image fadeImage;
|
||||
|
||||
[Tooltip("Color to use during scene transition")]
|
||||
public Color fadeColor = Color.black;
|
||||
|
||||
[Range(1, 100), Tooltip("Rate of fade in / out: higher is faster")]
|
||||
public byte stepRate = 2;
|
||||
|
||||
float step;
|
||||
|
||||
void Start()
|
||||
{
|
||||
step = stepRate * 0.001f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates FadeIn / FadeOut time.
|
||||
/// </summary>
|
||||
/// <returns>Duration in seconds</returns>
|
||||
public float GetDuration()
|
||||
{
|
||||
float frames = 1 / (stepRate * 0.1f);
|
||||
float frames = 1 / step;
|
||||
float frameRate = Time.deltaTime;
|
||||
float duration = frames * frameRate * 0.1f;
|
||||
return duration;
|
||||
@ -35,7 +42,7 @@ public IEnumerator FadeIn()
|
||||
while (alpha < 1)
|
||||
{
|
||||
yield return null;
|
||||
alpha += stepRate * 0.1f;
|
||||
alpha += step;
|
||||
fadeColor.a = alpha;
|
||||
fadeImage.color = fadeColor;
|
||||
}
|
||||
@ -48,7 +55,7 @@ public IEnumerator FadeOut()
|
||||
while (alpha > 0)
|
||||
{
|
||||
yield return null;
|
||||
alpha -= stepRate * 0.1f;
|
||||
alpha -= step;
|
||||
fadeColor.a = alpha;
|
||||
fadeImage.color = fadeColor;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user