SplashScreen

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Code: In the call to GUI.DrawTexture for the actual splashLogo the fourth parameter was splashLogo.width when it should have been splashLogo.height. Guessing it was just a copy & paste error.)
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
==SplashScreen==
 
==SplashScreen==
 +
Fades in a splash picture on the screen, waits for a few seconds (or waits for user input), then fades out while the next scene is loaded.
  
TODO: Test allot of things. this is a very early version.
+
TODO:
      fade the background color out.
+
* Console still reports the error message: "There are 2 audio listeners in the scene..." Its not critical but it would be nice to get rid of this.
      any additions to this script are always welcome!
+
  
Just create a new scene with a camera and empty gameobject.
+
Any additions to this script are always welcome!
Add the script to the gameobject and set properties (nextlevel and logo)
+
  
==Code==
+
Just create a new scene with a camera and add the script to the camera and set properties.
<csharp>
+
  
 +
==C# Code==
 +
<syntaxhighlight lang="csharp">
 
using UnityEngine;
 
using UnityEngine;
 
using System.Collections;
 
using System.Collections;
  
 +
//
 +
// SplashScreen Script
 +
//
 +
// Version 0.1 by Martijn Dekker
 +
// martijn.pixelstudio@gmail.com
 +
//
 +
// Version 0.2 by Ferdinand Joseph Fernandez, 2010Sep7 16:45 GMT + 8
 +
// Changes:
 +
//  * changed levelToLoad to a string, for easier usage
 +
//  * added waitTime, which adds a pause after fade in, and before fade
 +
//    out (during fade waiting)
 +
//  * added option to either automatically fade out after waitTime
 +
//    seconds (default), or wait for user input (press any key to continue)
 +
//  * added option to wait until fade out is complete before loading next
 +
//    level, instead of the default, which is to load the next level
 +
//    before fade out
 +
//
 +
// Version 0.3 by Ferdinand Joseph Fernandez, 2010Sep8 01:13 GMT + 8
 +
// Changes:
 +
//  * splash screen itself is now fading without the need for a solid
 +
//    background color
 +
//  * optimized some code
 +
//
 +
// Version 0.4 by Ferdinand Joseph Fernandez, 2010Sep14 14:09 GMT + 8
 +
// Changes:
 +
//  * splash screen picture can now be either centered (default) or
 +
//    stretched on the screen
 +
//
 +
// Version 0.5 by Ferdinand Joseph Fernandez, 2010Sep15 18:27 GMT + 8
 +
// Changes:
 +
//  * now has option to start automatically or not. if not started
 +
//    automatically, the splash screen can be started by calling
 +
//    the StartSplash function
 +
//  * code acknowledges if the levelToLoad is blank, in that case,
 +
//    the code simply does not attempt to load a level
 +
//
 +
// Version 0.6 by Ferdinand Joseph Fernandez, 2010Sep29 13:43 GMT + 8
 +
// Changes:
 +
//  * added the property "gui depth" so you can control at which depth the
 +
//    splash screen shows in
 +
//
  
///////////////////////////////////////
+
public class SplashScreen : MonoBehaviour
/// splashScreen script.           ///
+
{
/// Version 0.1 by Martijn Dekker  ///
+
public int guiDepth = 0;
/// martijn.pixelstudio@gmail.com  ///
+
public string levelToLoad = ""; // this has to correspond to a level (file>build settings)
///////////////////////////////////////
+
public Texture2D splashLogo; // the logo to splash;
 +
public float fadeSpeed = 0.3f;
 +
public float waitTime = 0.5f; // seconds to wait before fading out
 +
public bool waitForInput = false; // if true, this acts as a "press any key to continue"
 +
public bool startAutomatically = true;
 +
private float timeFadingInFinished = 0.0f;
  
public class splashScreen : MonoBehaviour {
+
public enum SplashType
 +
{
 +
LoadNextLevelThenFadeOut,
 +
FadeOutThenLoadNextLevel
 +
}
 +
public SplashType splashType;
  
    public int levelToLoad = 2;                        // this has to correspond to a levelIndex (file>build settings)
+
private float alpha = 0.0f;
    public Texture2D splashLogo;                        // the logo to splash;
+
    public Color sceneBackgroundColor = new Color(0,0,0);    // choose a background color for the screen
+
    public float fadeSpeed = 0.3f;
+
 
+
    private float alpha = 0f;
+
    private enum fadeStatus
+
    {
+
        fadeIn,
+
        fadeOut,
+
        fadeWaiting,
+
        fadeExit
+
    }
+
    private fadeStatus status = fadeStatus.fadeIn;
+
    private Object[] cams;
+
    private Camera oldCam;
+
    private Texture2D backTexture = new Texture2D(1, 1);
+
  
   
+
private enum FadeStatus
 +
{
 +
Paused,
 +
FadeIn,
 +
FadeWaiting,
 +
FadeOut
 +
}
 +
private FadeStatus status = FadeStatus.FadeIn;
  
    void setAlpha(float alpha)
+
private Camera oldCam;
    {
+
private GameObject oldCamGO;
        sceneBackgroundColor = new Color(sceneBackgroundColor.r, sceneBackgroundColor.g, sceneBackgroundColor.b, alpha);
+
        for (int x = 1; x <= backTexture.width; x++)
+
        {
+
            for (int y = 1; y <= backTexture.height; y++)
+
            {
+
                backTexture.SetPixel(x, y, sceneBackgroundColor);
+
            }
+
        }
+
    }
+
  
    void Start () {
+
private Rect splashLogoPos = new Rect();
        cams = GameObject.FindObjectsOfType(typeof(Camera));
+
public enum LogoPositioning
        oldCam = Camera.main;
+
{
        setAlpha(1.0f);
+
Centered,
        DontDestroyOnLoad(this);
+
Stretched
        DontDestroyOnLoad(Camera.main);
+
        DontDestroyOnLoad(backTexture);
+
        Destroy(Camera.main.GetComponent(typeof (AudioListener)));
+
        if ((Application.levelCount <= 1) || (Application.levelCount < levelToLoad))
+
        {
+
            Debug.Log("I need to have a level to load or the value of level To load is wrong!");
+
            return;
+
        }
+
 
}
 
}
 +
public LogoPositioning logoPositioning;
  
void Update () {
+
private bool loadingNextLevel = false;
    switch(status) {
+
 
            case fadeStatus.fadeIn:
+
void Start()
                alpha += 1.0f * 0.3f * Time.deltaTime;
+
{
            break;
+
if (startAutomatically)
            case fadeStatus.fadeOut:
+
{
                alpha += -1.0f * 0.3f * Time.deltaTime;
+
status = FadeStatus.FadeIn;
            break;
+
}
            case fadeStatus.fadeWaiting:
+
else
                Application.LoadLevel(levelToLoad);
+
{
                status = fadeStatus.fadeOut;
+
status = FadeStatus.Paused;
            break;
+
}
          // case fadeStatus.fadeExit:
+
oldCam = Camera.main;
          //    backAlpha += -1.0f * exitTimer * Time.deltaTime;
+
oldCamGO = Camera.main.gameObject;
          //    setAlpha(backAlpha);
+
 
          // break;
+
if (logoPositioning == LogoPositioning.Centered)
        }
+
{
 +
splashLogoPos.x = (Screen.width * 0.5f) - (splashLogo.width * 0.5f);
 +
splashLogoPos.y = (Screen.height * 0.5f) - (splashLogo.height * 0.5f);
 +
 
 +
splashLogoPos.width = splashLogo.width;
 +
splashLogoPos.height = splashLogo.height;
 +
}
 +
else
 +
{
 +
splashLogoPos.x = 0;
 +
splashLogoPos.y = 0;
 +
 
 +
splashLogoPos.width = Screen.width;
 +
splashLogoPos.height = Screen.height;
 +
}
 +
 
 +
 
 +
 
 +
if (splashType == SplashType.LoadNextLevelThenFadeOut)
 +
{
 +
DontDestroyOnLoad(this);
 +
DontDestroyOnLoad(Camera.main);
 +
}
 +
if ((Application.levelCount <= 1) || (levelToLoad == ""))
 +
{
 +
Debug.LogWarning("Invalid levelToLoad value.");
 +
}
 
}
 
}
  
    void OnGUI()
+
public void StartSplash()
    {
+
{
        if (splashLogo != null)
+
status = FadeStatus.FadeIn;
        {
+
}
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), backTexture, ScaleMode.StretchToFill, false);
+
 
            float left = (Screen.width / 2) - (splashLogo.width / 2);
+
void Update()
            float top = (Screen.height / 2) - (splashLogo.height / 2);
+
{
            GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpha));
+
switch(status)
            GUI.DrawTexture(new Rect(left, top, splashLogo.width, splashLogo.height), splashLogo);
+
{
            GUI.Label(new Rect((Screen.width / 2) - 50, top + splashLogo.height, 100, 20), "loading level....");
+
case FadeStatus.FadeIn:
           
+
alpha += fadeSpeed * Time.deltaTime;
            if (alpha > 1.0f)  
+
break;
            {
+
case FadeStatus.FadeWaiting:
                status = fadeStatus.fadeWaiting;
+
if ((!waitForInput && Time.time >= timeFadingInFinished + waitTime) || (waitForInput && Input.anyKey))
                alpha = 1.0f;
+
{
            }
+
status = FadeStatus.FadeOut;
            if (alpha < 0.0f)
+
}
            {
+
break;
                status = fadeStatus.fadeExit;
+
case FadeStatus.FadeOut:
                oldCam.depth = -1000;
+
alpha += -fadeSpeed * Time.deltaTime;
                Destroy(this);
+
break;
            }
+
}
        }
+
}
    }
+
 
 +
void OnGUI()
 +
{
 +
GUI.depth = guiDepth;
 +
if (splashLogo != null)
 +
{
 +
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpha));
 +
GUI.DrawTexture(splashLogoPos, splashLogo);
 +
if (alpha > 1.0f)
 +
{
 +
status = FadeStatus.FadeWaiting;
 +
timeFadingInFinished = Time.time;
 +
alpha = 1.0f;
 +
if (splashType == SplashType.LoadNextLevelThenFadeOut)
 +
{
 +
oldCam.depth = -1000;
 +
loadingNextLevel = true;
 +
if ((Application.levelCount >= 1) && (levelToLoad != ""))
 +
{
 +
Application.LoadLevel(levelToLoad);
 +
}
 +
}
 +
}
 +
if (alpha < 0.0f)
 +
{
 +
if (splashType == SplashType.FadeOutThenLoadNextLevel)
 +
{
 +
if ((Application.levelCount >= 1) && (levelToLoad != ""))
 +
{
 +
Application.LoadLevel(levelToLoad);
 +
}
 +
}
 +
else
 +
{
 +
Destroy(oldCamGO); // somehow this doesn't work
 +
Destroy(this);
 +
}
 +
}
 +
}
 +
}
 +
 
 +
void OnLevelWasLoaded(int lvlIdx)
 +
{
 +
if (loadingNextLevel)
 +
{
 +
Destroy(oldCam.GetComponent<AudioListener>());
 +
Destroy(oldCam.GetComponent<GUILayer>());
 +
}
 +
}
 +
 
 +
void OnDrawGizmos()
 +
{
 +
Gizmos.color = new Color(1f, 0f, 0f, .5f);
 +
Gizmos.DrawCube(transform.position, new Vector3(1, 1, 1));
 +
}
 +
}
 +
</syntaxhighlight>
 +
 
 +
 
 +
 
 +
===UnityScript Code===
 +
 
 +
<syntaxhighlight lang="javascript">
 +
//
 +
// SplashScreen Script
 +
//
 +
// This is the same script as above (only a few redundant things were removed), just converted to UnityScript
 +
// to help out those sticking to unity script, and to help those just starting out with it.
 +
// Quantum Fusion Studios
 +
 
 +
var guiDepth : int = 0;
 +
var levelToLoad : String = "";
 +
var splashLogo : Texture2D;
 +
var fadeSpeed : float = 0.3;
 +
var waitTime : float = 0.5;
 +
var waitForInput : boolean = false;
 +
var startAutomatically : boolean = true;
 +
var timeFadingInFinished : float = 0.0;
 +
var logoPositioning : LogoPositioning;
 +
var splashType : SplashType;
 +
enum SplashType {LoadNextLevelThenFadeOut, FadeOutThenLoadNextLevel}
 +
enum LogoPositioning {Centered, Stretched}
 +
private var alpha : float = 0.0;
 +
private var status : FadeStatus = FadeStatus.FadeIn;
 +
private var oldCam : Camera;
 +
private var oldCamGO : GameObject;
 +
private var splashLogoPos : Rect;
 +
private var loadingNextLevel : boolean = false;
 +
private enum FadeStatus {Paused, FadeIn, FadeWaiting, FadeOut}
 +
 
 +
 
 +
function Start()
 +
{
 +
if (startAutomatically)
 +
{
 +
status = FadeStatus.FadeIn;
 +
}
 +
 
 +
else
 +
{
 +
status = FadeStatus.Paused;
 +
}
 +
 
 +
oldCam = Camera.main;
 +
oldCamGO = Camera.main.gameObject;
 +
 
 +
if (logoPositioning == LogoPositioning.Centered)
 +
{
 +
splashLogoPos.x = (Screen.width * 0.5) - (splashLogo.width * 0.5);
 +
splashLogoPos.y = (Screen.height * 0.5) - (splashLogo.height * 0.5);
 +
 
 +
splashLogoPos.width = splashLogo.width;
 +
splashLogoPos.height = splashLogo.height;
 +
}
 +
 
 +
else
 +
{
 +
splashLogoPos.x = 0;
 +
splashLogoPos.y = 0;
 +
 
 +
splashLogoPos.width = Screen.width;
 +
splashLogoPos.height = Screen.height;
 +
}
 +
 
 +
if (splashType == SplashType.LoadNextLevelThenFadeOut)
 +
{
 +
DontDestroyOnLoad(this);
 +
DontDestroyOnLoad(Camera.main);
 +
}
 +
 
 +
 
 +
if ((Application.levelCount <= 1) || (levelToLoad == ""))
 +
{
 +
Debug.LogWarning("Invalid levelToLoad value.");
 +
}
 +
}
 +
 
 +
 
 +
 
 +
function Update()
 +
{
 +
switch(status)
 +
{
 +
case FadeStatus.FadeIn:
 +
alpha += fadeSpeed * Time.deltaTime;
 +
break;
 +
 
 +
case FadeStatus.FadeWaiting:
 +
if ((!waitForInput && Time.time >= timeFadingInFinished + waitTime) || (waitForInput && Input.anyKey))
 +
{
 +
status = FadeStatus.FadeOut;
 +
}
 +
break;
 +
 
 +
case FadeStatus.FadeOut:
 +
alpha += -fadeSpeed * Time.deltaTime;
 +
break;
 +
}
 +
}
 +
 
 +
 
 +
 
 +
function OnGUI()
 +
{
 +
GUI.depth = guiDepth;
 +
 
 +
if (splashLogo != null)
 +
{
 +
GUI.color = Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpha));
 +
GUI.DrawTexture(splashLogoPos, splashLogo);
 +
 
 +
if (alpha > 1.0)
 +
{
 +
status = FadeStatus.FadeWaiting;
 +
timeFadingInFinished = Time.time;
 +
alpha = 1.0;
 +
 
 +
if (splashType == SplashType.LoadNextLevelThenFadeOut)
 +
{
 +
oldCam.depth = -1000;
 +
loadingNextLevel = true;
 +
 
 +
if ((Application.levelCount >= 1) && (levelToLoad != ""))
 +
{
 +
Application.LoadLevel(levelToLoad);
 +
}
 +
}
 +
}
 +
 
 +
if (alpha < 0.0)
 +
{
 +
if (splashType == SplashType.FadeOutThenLoadNextLevel)
 +
{
 +
if ((Application.levelCount >= 1) && (levelToLoad != ""))
 +
{
 +
Application.LoadLevel(levelToLoad);
 +
}
 +
}
 +
 
 +
else
 +
{
 +
Destroy(oldCamGO);
 +
}
 +
}
 +
}
 +
}
 +
 
 +
 
 +
 
 +
function OnLevelWasLoaded(lvlIdx : int)
 +
{
 +
if (loadingNextLevel)
 +
{
 +
Destroy(oldCam);
 +
}
 +
}
 +
 
 +
 
 +
function OnDrawGizmos()
 +
{
 +
Gizmos.color = Color(1, 0, 0, 0.5);
 +
Gizmos.DrawCube(transform.position, Vector3(1, 1, 1));
 +
}
 +
 
  
    void OnDrawGizmos()
+
function StartSplash()
    {
+
{
        Gizmos.color =new Color(1f, 0f, 0f, .5f);
+
status = FadeStatus.FadeIn;
        Gizmos.DrawCube(transform.position, new Vector3(1, 1, 1));
+
    }
+
 
}
 
}
  
</csharp>
+
</syntaxhighlight>

Latest revision as of 20:53, 10 January 2012

[edit] SplashScreen

Fades in a splash picture on the screen, waits for a few seconds (or waits for user input), then fades out while the next scene is loaded.

TODO:

  • Console still reports the error message: "There are 2 audio listeners in the scene..." Its not critical but it would be nice to get rid of this.

Any additions to this script are always welcome!

Just create a new scene with a camera and add the script to the camera and set properties.

[edit] C# Code

using UnityEngine;
using System.Collections;
 
//
// SplashScreen Script
//
// Version 0.1 by Martijn Dekker
// martijn.pixelstudio@gmail.com
//
// Version 0.2 by Ferdinand Joseph Fernandez, 2010Sep7 16:45 GMT + 8
// Changes:
//  * changed levelToLoad to a string, for easier usage
//  * added waitTime, which adds a pause after fade in, and before fade
//    out (during fade waiting)
//  * added option to either automatically fade out after waitTime
//    seconds (default), or wait for user input (press any key to continue)
//  * added option to wait until fade out is complete before loading next
//    level, instead of the default, which is to load the next level
//    before fade out
//
// Version 0.3 by Ferdinand Joseph Fernandez, 2010Sep8 01:13 GMT + 8
// Changes:
//  * splash screen itself is now fading without the need for a solid
//    background color
//  * optimized some code
//
// Version 0.4 by Ferdinand Joseph Fernandez, 2010Sep14 14:09 GMT + 8
// Changes:
//  * splash screen picture can now be either centered (default) or
//    stretched on the screen
//
// Version 0.5 by Ferdinand Joseph Fernandez, 2010Sep15 18:27 GMT + 8
// Changes:
//  * now has option to start automatically or not. if not started
//    automatically, the splash screen can be started by calling
//    the StartSplash function
//  * code acknowledges if the levelToLoad is blank, in that case,
//    the code simply does not attempt to load a level
//
// Version 0.6 by Ferdinand Joseph Fernandez, 2010Sep29 13:43 GMT + 8
// Changes:
//  * added the property "gui depth" so you can control at which depth the
//    splash screen shows in
//
 
public class SplashScreen : MonoBehaviour
{
	public int guiDepth = 0;
	public string levelToLoad = ""; // this has to correspond to a level (file>build settings)
	public Texture2D splashLogo; // the logo to splash;
	public float fadeSpeed = 0.3f;
	public float waitTime = 0.5f; // seconds to wait before fading out
	public bool waitForInput = false; // if true, this acts as a "press any key to continue"
	public bool startAutomatically = true;
	private float timeFadingInFinished = 0.0f;
 
	public enum SplashType
	{
		LoadNextLevelThenFadeOut,
		FadeOutThenLoadNextLevel
	}
	public SplashType splashType;
 
	private float alpha = 0.0f;
 
	private enum FadeStatus
	{
		Paused,
		FadeIn,
		FadeWaiting,
		FadeOut
	}
	private FadeStatus status = FadeStatus.FadeIn;
 
	private Camera oldCam;
	private GameObject oldCamGO;
 
	private Rect splashLogoPos = new Rect();
	public enum LogoPositioning
	{
		Centered,
		Stretched
	}
	public LogoPositioning logoPositioning;
 
	private bool loadingNextLevel = false;
 
	void Start()
	{
		if (startAutomatically)
		{
			status = FadeStatus.FadeIn;
		}
		else
		{
			status = FadeStatus.Paused;
		}
		oldCam = Camera.main;
		oldCamGO = Camera.main.gameObject;
 
		if (logoPositioning == LogoPositioning.Centered)
		{
			splashLogoPos.x = (Screen.width * 0.5f) - (splashLogo.width * 0.5f);
			splashLogoPos.y = (Screen.height * 0.5f) - (splashLogo.height * 0.5f);
 
			splashLogoPos.width = splashLogo.width;
			splashLogoPos.height = splashLogo.height;
		}
		else
		{
			splashLogoPos.x = 0;
			splashLogoPos.y = 0;
 
			splashLogoPos.width = Screen.width;
			splashLogoPos.height = Screen.height;
		}
 
 
 
		if (splashType == SplashType.LoadNextLevelThenFadeOut)
		{
			DontDestroyOnLoad(this);
			DontDestroyOnLoad(Camera.main);
		}
		if ((Application.levelCount <= 1) || (levelToLoad == ""))
		{
			Debug.LogWarning("Invalid levelToLoad value.");
		}
	}
 
	public void StartSplash()
	{
		status = FadeStatus.FadeIn;
	}
 
	void Update()
	{
		switch(status)
		{
			case FadeStatus.FadeIn:
				alpha += fadeSpeed * Time.deltaTime;
			break;
			case FadeStatus.FadeWaiting:
				if ((!waitForInput && Time.time >= timeFadingInFinished + waitTime) || (waitForInput && Input.anyKey))
				{
					status = FadeStatus.FadeOut;
				}
			break;
			case FadeStatus.FadeOut:
				alpha += -fadeSpeed * Time.deltaTime;
			break;
		}
	}
 
	void OnGUI()
	{
		GUI.depth = guiDepth;
		if (splashLogo != null)
		{
			GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpha));
			GUI.DrawTexture(splashLogoPos, splashLogo);
			if (alpha > 1.0f)
			{
				status = FadeStatus.FadeWaiting;
				timeFadingInFinished = Time.time;
				alpha = 1.0f;
				if (splashType == SplashType.LoadNextLevelThenFadeOut)
				{
					oldCam.depth = -1000;
					loadingNextLevel = true;
					if ((Application.levelCount >= 1) && (levelToLoad != ""))
					{
						Application.LoadLevel(levelToLoad);
					}
				}
			}
			if (alpha < 0.0f)
			{
				if (splashType == SplashType.FadeOutThenLoadNextLevel)
				{
					if ((Application.levelCount >= 1) && (levelToLoad != ""))
					{
						Application.LoadLevel(levelToLoad);
					}
				}
				else
				{
					Destroy(oldCamGO); // somehow this doesn't work
					Destroy(this);
				}
			}
		}
	}
 
	void OnLevelWasLoaded(int lvlIdx)
	{
		if (loadingNextLevel)
		{
			Destroy(oldCam.GetComponent<AudioListener>());
			Destroy(oldCam.GetComponent<GUILayer>());
		}
	}
 
	void OnDrawGizmos()
	{
		Gizmos.color = new Color(1f, 0f, 0f, .5f);
		Gizmos.DrawCube(transform.position, new Vector3(1, 1, 1));
	}
}


[edit] UnityScript Code

//
// SplashScreen Script
//
// This is the same script as above (only a few redundant things were removed), just converted to UnityScript
// to help out those sticking to unity script, and to help those just starting out with it.
// Quantum Fusion Studios
 
var guiDepth : int = 0;
var levelToLoad : String = "";
var splashLogo : Texture2D;
var fadeSpeed : float = 0.3;
var waitTime : float = 0.5;
var waitForInput : boolean = false;
var startAutomatically : boolean = true;
var timeFadingInFinished : float = 0.0;
var logoPositioning : LogoPositioning;
var splashType : SplashType;
enum SplashType {LoadNextLevelThenFadeOut, FadeOutThenLoadNextLevel}
enum LogoPositioning {Centered, Stretched}
private var alpha : float = 0.0;
private var status : FadeStatus = FadeStatus.FadeIn;
private var oldCam : Camera;
private var oldCamGO : GameObject;
private var splashLogoPos : Rect;
private var loadingNextLevel : boolean = false;
private enum FadeStatus {Paused, FadeIn, FadeWaiting, FadeOut}
 
 
function Start()
{
	if (startAutomatically)
	{
		status = FadeStatus.FadeIn;
	}
 
	else
	{
		status = FadeStatus.Paused;
	}
 
	oldCam = Camera.main;
	oldCamGO = Camera.main.gameObject;
 
	if (logoPositioning == LogoPositioning.Centered)
	{
		splashLogoPos.x = (Screen.width * 0.5) - (splashLogo.width * 0.5);
		splashLogoPos.y = (Screen.height * 0.5) - (splashLogo.height * 0.5);
 
		splashLogoPos.width = splashLogo.width;
		splashLogoPos.height = splashLogo.height;
	}
 
	else
	{
		splashLogoPos.x = 0;
		splashLogoPos.y = 0;
 
		splashLogoPos.width = Screen.width;
		splashLogoPos.height = Screen.height;
	}
 
	if (splashType == SplashType.LoadNextLevelThenFadeOut)
	{
		DontDestroyOnLoad(this);
		DontDestroyOnLoad(Camera.main);
	}
 
 
	if ((Application.levelCount <= 1) || (levelToLoad == ""))
	{
		Debug.LogWarning("Invalid levelToLoad value.");
	}
}
 
 
 
function Update()
{
	switch(status)
	{
		case FadeStatus.FadeIn:
			alpha += fadeSpeed * Time.deltaTime;
		break;
 
		case FadeStatus.FadeWaiting:
			if ((!waitForInput && Time.time >= timeFadingInFinished + waitTime) || (waitForInput && Input.anyKey))
			{
				status = FadeStatus.FadeOut;
			}
		break;
 
		case FadeStatus.FadeOut:
			alpha += -fadeSpeed * Time.deltaTime;
		break;
	}
}
 
 
 
function OnGUI()
{
	GUI.depth = guiDepth;
 
	if (splashLogo != null)
	{
		GUI.color = Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpha));
		GUI.DrawTexture(splashLogoPos, splashLogo);
 
			if (alpha > 1.0)
			{
				status = FadeStatus.FadeWaiting;
				timeFadingInFinished = Time.time;
				alpha = 1.0;
 
				if (splashType == SplashType.LoadNextLevelThenFadeOut)
				{
					oldCam.depth = -1000;
					loadingNextLevel = true;
 
					if ((Application.levelCount >= 1) && (levelToLoad != ""))
					{
						Application.LoadLevel(levelToLoad);
					}
				}
			}
 
			if (alpha < 0.0)
			{
				if (splashType == SplashType.FadeOutThenLoadNextLevel)
				{
					if ((Application.levelCount >= 1) && (levelToLoad != ""))
					{
						Application.LoadLevel(levelToLoad);
					}
				}
 
				else
				{
					Destroy(oldCamGO);
				}
			}
	}
}
 
 
 
function OnLevelWasLoaded(lvlIdx : int)
{
	if (loadingNextLevel)
	{
		Destroy(oldCam);
	}
}
 
 
function OnDrawGizmos()
{
	Gizmos.color = Color(1, 0, 0, 0.5);
	Gizmos.DrawCube(transform.position, Vector3(1, 1, 1));
}
 
 
function StartSplash()
{
	status = FadeStatus.FadeIn;
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox