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.
114 lines
3.4 KiB
114 lines
3.4 KiB
// 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) |
|
|
|
using UnityEngine; |
|
|
|
namespace Fungus |
|
{ |
|
/// <summary> |
|
/// Fades the camera out and in again at a position specified by a View object. |
|
/// </summary> |
|
[CommandInfo("Camera", |
|
"Fade To View", |
|
"Fades the camera out and in again at a position specified by a View object.")] |
|
[AddComponentMenu("")] |
|
public class FadeToView : Command |
|
{ |
|
[Tooltip("Time for fade effect to complete")] |
|
[SerializeField] protected float duration = 1f; |
|
|
|
[Tooltip("Fade from fully visible to opaque at start of fade")] |
|
[SerializeField] protected bool fadeOut = true; |
|
|
|
[Tooltip("View to transition to when Fade is complete")] |
|
[SerializeField] protected View targetView; |
|
public virtual View TargetView { get { return targetView; } } |
|
|
|
[Tooltip("Wait until the fade has finished before executing next command")] |
|
[SerializeField] protected bool waitUntilFinished = true; |
|
|
|
[Tooltip("Color to render fullscreen fade texture with when screen is obscured.")] |
|
[SerializeField] protected Color fadeColor = Color.black; |
|
|
|
[Tooltip("Optional texture to use when rendering the fullscreen fade effect.")] |
|
[SerializeField] protected Texture2D fadeTexture; |
|
|
|
[Tooltip("Camera to use for the fade. Will use main camera if set to none.")] |
|
[SerializeField] protected Camera targetCamera; |
|
|
|
protected virtual void AcquireCamera() |
|
{ |
|
if (targetCamera != null) |
|
{ |
|
return; |
|
} |
|
|
|
targetCamera = Camera.main; |
|
if (targetCamera == null) |
|
{ |
|
targetCamera = GameObject.FindObjectOfType<Camera>(); |
|
} |
|
} |
|
|
|
public virtual void Start() |
|
{ |
|
AcquireCamera(); |
|
} |
|
|
|
public override void OnEnter() |
|
{ |
|
AcquireCamera(); |
|
if (targetCamera == null || |
|
targetView == null) |
|
{ |
|
Continue(); |
|
return; |
|
} |
|
|
|
ICameraController cameraController = CameraController.GetInstance(); |
|
|
|
if (fadeTexture) |
|
{ |
|
cameraController.ScreenFadeTexture = fadeTexture; |
|
} |
|
else |
|
{ |
|
cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32); |
|
} |
|
|
|
cameraController.FadeToView(targetCamera, targetView, duration, fadeOut, delegate { |
|
if (waitUntilFinished) |
|
{ |
|
Continue(); |
|
} |
|
}); |
|
|
|
if (!waitUntilFinished) |
|
{ |
|
Continue(); |
|
} |
|
} |
|
|
|
public override void OnStopExecuting() |
|
{ |
|
CameraController.GetInstance().Stop(); |
|
} |
|
|
|
public override string GetSummary() |
|
{ |
|
if (targetView == null) |
|
{ |
|
return "Error: No view selected"; |
|
} |
|
else |
|
{ |
|
return targetView.name; |
|
} |
|
} |
|
|
|
public override Color GetButtonColor() |
|
{ |
|
return new Color32(216, 228, 170, 255); |
|
} |
|
} |
|
} |