Skip to content

Instantly share code, notes, and snippets.

@ZeredaGames
Last active December 27, 2015 05:04
Show Gist options
  • Save ZeredaGames/8766e155a29dda94669e to your computer and use it in GitHub Desktop.
Save ZeredaGames/8766e155a29dda94669e to your computer and use it in GitHub Desktop.
Display's a splash manater from a texture 2D. Displays durring the loading period.
//
// PlayerPrefsManager.cs
//
// Author:
// ${ZeredaGames-AKA Thamas Bell} <${thamasbell@hotmail.com}>
//
// Copyright (c) ${2015} ${Thamas Bell}
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using UnityEngine;
namespace UnityEngine.ZG.Scripts.Managers.Spash
{
public class SplashManager : MonoBehaviour
{
public Texture2D splash;
public Key_Bindings AKBs;
public static Texture2D background;
public static bool loading;
public static bool LoadTheLevel = false;
public static int levelIndexToLoad = 1;
public static float timeToWait = 30.0f;
public const int SplashScreen = 0;
void Start ()
{
loading = true;
GetSplashInfo ();
}
void GetSplashInfo ()
{
if (loading) {
background = new Texture2D (2, 2);
background.SetPixels (new Color[] {Color.black, Color.black, Color.black, Color.black});
background.Apply ();
DontDestroyOnLoad (gameObject);
}
return;
}
void OnLevelWasLoaded (int levelIndexToLoad)
{
if (levelIndexToLoad == 2) {
loading = false;
}
}
void OnGUI ()
{
if (!loading) {
return;
}
float splashWidth = splash.width, splashHeight = splash.height;
if (splashWidth > Screen.width) {
float scale = Screen.width / splashWidth;
splashWidth *= scale;
splashHeight *= scale;
}
GUI.DrawTexture (new Rect (0.0f, 0.0f, Screen.width, Screen.height), background);
GUI.DrawTexture (new Rect ((Screen.width - splashWidth) * 0.5f, (Screen.height - splashHeight)
* 0.5f, splashWidth, splashHeight), splash);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment