2023-07-26 21:47:00 +02:00
|
|
|
// Cinema Suite
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace CinemaDirector
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Transition from Clear to Black over time by overlaying a guiTexture.
|
|
|
|
/// </summary>
|
|
|
|
[CutsceneItem("Transitions", "Fade to Black", CutsceneItemGenre.GlobalItem)]
|
|
|
|
public class FadeToBlack : CinemaGlobalAction
|
|
|
|
{
|
|
|
|
private Color From = Color.clear;
|
|
|
|
private Color To = Color.black;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Setup the effect when the script is loaded.
|
|
|
|
/// </summary>
|
|
|
|
void Awake()
|
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
if (GetComponent<GUITexture>() == null)
|
2023-07-26 21:47:00 +02:00
|
|
|
{
|
|
|
|
gameObject.transform.position = Vector3.zero;
|
|
|
|
gameObject.transform.localScale = new Vector3(100, 100, 100);
|
|
|
|
gameObject.AddComponent<GUITexture>();
|
2023-07-27 12:38:45 +02:00
|
|
|
GetComponent<GUITexture>().enabled = false;
|
|
|
|
GetComponent<GUITexture>().texture = new Texture2D(1, 1);
|
|
|
|
GetComponent<GUITexture>().pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
|
|
|
|
GetComponent<GUITexture>().color = Color.clear;
|
2023-07-26 21:47:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enable the overlay texture and set the Color to Clear.
|
|
|
|
/// </summary>
|
|
|
|
public override void Trigger()
|
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
GetComponent<GUITexture>().enabled = true;
|
|
|
|
GetComponent<GUITexture>().pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
|
|
|
|
GetComponent<GUITexture>().color = From;
|
2023-07-26 21:47:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Firetime is reached when playing in reverse, disable the effect.
|
|
|
|
/// </summary>
|
|
|
|
public override void ReverseTrigger()
|
|
|
|
{
|
|
|
|
End();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Update the effect over time, progressing the transition
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="time">The time this action has been active</param>
|
|
|
|
/// <param name="deltaTime">The time since the last update</param>
|
|
|
|
public override void UpdateTime(float time, float deltaTime)
|
|
|
|
{
|
|
|
|
float transition = time / Duration;
|
|
|
|
FadeToColor(From, To, transition);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set the transition to an arbitrary time.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="time">The time of this action</param>
|
|
|
|
/// <param name="deltaTime">the deltaTime since the last update call.</param>
|
|
|
|
public override void SetTime(float time, float deltaTime)
|
|
|
|
{
|
|
|
|
if (time >= 0 && time <= Duration)
|
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
GetComponent<GUITexture>().enabled = true;
|
2023-07-26 21:47:00 +02:00
|
|
|
UpdateTime(time, deltaTime);
|
|
|
|
}
|
2023-07-27 12:38:45 +02:00
|
|
|
else if (GetComponent<GUITexture>().enabled)
|
2023-07-26 21:47:00 +02:00
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
GetComponent<GUITexture>().enabled = false;
|
2023-07-26 21:47:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// End the effect by disabling the overlay texture.
|
|
|
|
/// </summary>
|
|
|
|
public override void End()
|
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
GetComponent<GUITexture>().enabled = false;
|
2023-07-26 21:47:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The end of the action has been triggered while playing the Cutscene in reverse.
|
|
|
|
/// </summary>
|
|
|
|
public override void ReverseEnd()
|
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
GetComponent<GUITexture>().enabled = true;
|
|
|
|
GetComponent<GUITexture>().pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
|
|
|
|
GetComponent<GUITexture>().color = To;
|
2023-07-26 21:47:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Disable the overlay texture
|
|
|
|
/// </summary>
|
|
|
|
public override void Stop()
|
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
if (GetComponent<GUITexture>() != null)
|
2023-07-26 21:47:00 +02:00
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
GetComponent<GUITexture>().enabled = false;
|
2023-07-26 21:47:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fade from one colour to another over a transition period.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="from">The starting colour</param>
|
|
|
|
/// <param name="to">The final colour</param>
|
|
|
|
/// <param name="transition">the Lerp transition value</param>
|
|
|
|
private void FadeToColor(Color from, Color to, float transition)
|
|
|
|
{
|
2023-07-27 12:38:45 +02:00
|
|
|
GetComponent<GUITexture>().color = Color.Lerp(from, to, transition);
|
2023-07-26 21:47:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|