Browse Source

Added Fade Screen command

master
chrisgregan 10 years ago
parent
commit
255970d507
  1. BIN
      Assets/Example/Scenes/Example.unity
  2. 61
      Assets/Fungus/Camera/Commands/FadeScreen.cs
  3. 8
      Assets/Fungus/Camera/Commands/FadeScreen.cs.meta
  4. 10
      Assets/Fungus/Camera/Scripts/CameraController.cs

BIN
Assets/Example/Scenes/Example.unity

Binary file not shown.

61
Assets/Fungus/Camera/Commands/FadeScreen.cs

@ -0,0 +1,61 @@
using UnityEngine;
using System;
using System.Collections;
namespace Fungus
{
[CommandInfo("Camera",
"Fade Screen",
"Draws a fullscreen texture over the scene to give a fade effect. Target alpha 1 will obscure the screen, alpha 0 will reveal the screen.")]
public class FadeScreen : Command
{
public float duration = 1f;
public float targetAlpha = 1f;
public bool waitUntilFinished = true;
public Color fadeColor = Color.black;
public Texture2D fadeTexture;
public override void OnEnter()
{
CameraController cameraController = CameraController.GetInstance();
if (waitUntilFinished)
{
cameraController.waiting = true;
}
if (fadeTexture)
{
cameraController.screenFadeTexture = fadeTexture;
}
else
{
cameraController.screenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32);
}
cameraController.Fade(targetAlpha, duration, delegate {
if (waitUntilFinished)
{
cameraController.waiting = false;
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
Assets/Fungus/Camera/Commands/FadeScreen.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 207aecf668a0345388087ccf522f9957
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

10
Assets/Fungus/Camera/Scripts/CameraController.cs

@ -109,12 +109,12 @@ namespace Fungus
}
// Draw full screen fade texture
if (fadeAlpha < 1f &&
if (fadeAlpha > 0f &&
screenFadeTexture != null)
{
// 1 = scene fully visible
// 0 = scene fully obscured
GUI.color = new Color(1,1,1, 1f - fadeAlpha);
GUI.color = new Color(1,1,1, fadeAlpha);
GUI.depth = -1000;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), screenFadeTexture);
}
@ -134,16 +134,16 @@ namespace Fungus
public void FadeToView(View view, float fadeDuration, Action fadeAction)
{
swipePanActive = false;
fadeAlpha = 1f;
fadeAlpha = 0f;
// Fade out
Fade(0f, fadeDuration / 2f, delegate {
Fade(1f, fadeDuration / 2f, delegate {
// Snap to new view
PanToPosition(view.transform.position, view.transform.rotation, view.viewSize, 0f, null);
// Fade in
Fade(1f, fadeDuration / 2f, delegate {
Fade(0f, fadeDuration / 2f, delegate {
if (fadeAction != null)
{
fadeAction();

Loading…
Cancel
Save