You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.7 KiB
70 lines
2.7 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEngine;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Draws a fullscreen texture over the scene to give a fade effect. Setting Target Alpha to 1 will obscure the screen, alpha 0 will reveal the screen.
|
||
|
/// If no Fade Texture is provided then a default flat color texture is used.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Camera",
|
||
|
"Fade Screen",
|
||
|
"Draws a fullscreen texture over the scene to give a fade effect. Setting Target Alpha to 1 will obscure the screen, alpha 0 will reveal the screen. " +
|
||
|
"If no Fade Texture is provided then a default flat color texture is used.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class FadeScreen : Command
|
||
|
{
|
||
|
[Tooltip("Time for fade effect to complete")]
|
||
8 years ago
|
[SerializeField] protected float duration = 1f;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Current target alpha transparency value. The fade gradually adjusts the alpha to approach this target value.")]
|
||
8 years ago
|
[SerializeField] protected float targetAlpha = 1f;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Wait until the fade has finished before executing next command")]
|
||
8 years ago
|
[SerializeField] protected bool waitUntilFinished = true;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Color to render fullscreen fade texture with when screen is obscured.")]
|
||
8 years ago
|
[SerializeField] protected Color fadeColor = Color.black;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Optional texture to use when rendering the fullscreen fade effect.")]
|
||
8 years ago
|
[SerializeField] protected Texture2D fadeTexture;
|
||
8 years ago
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
8 years ago
|
ICameraController cameraController = CameraController.GetInstance();
|
||
8 years ago
|
|
||
|
if (fadeTexture)
|
||
|
{
|
||
8 years ago
|
cameraController.ScreenFadeTexture = fadeTexture;
|
||
8 years ago
|
}
|
||
|
else
|
||
|
{
|
||
8 years ago
|
cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32);
|
||
8 years ago
|
}
|
||
|
|
||
|
cameraController.Fade(targetAlpha, duration, delegate {
|
||
|
if (waitUntilFinished)
|
||
|
{
|
||
|
Continue();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
if (!waitUntilFinished)
|
||
|
{
|
||
|
Continue();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
return "Fade to " + targetAlpha + " over " + duration + " seconds";
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(216, 228, 170, 255);
|
||
|
}
|
||
8 years ago
|
}
|
||
10 years ago
|
}
|