Skip to content

Instantly share code, notes, and snippets.

@urahimono
Created August 14, 2016 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urahimono/44c51a6acf66a00c3668c3a6699a04b2 to your computer and use it in GitHub Desktop.
Save urahimono/44c51a6acf66a00c3668c3a6699a04b2 to your computer and use it in GitHub Desktop.
【Unity】簡易フェード制御コンポーネントについて考えてみる SceneController
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class SceneController : MonoBehaviour
{
private FadeController m_fade = null;
public static SceneController Instance
{
get;
private set;
}
void Awake()
{
if( Instance != null )
{
Destroy( this );
return;
}
DontDestroyOnLoad( gameObject );
var obj = new GameObject();
m_fade = obj.AddComponent<FadeController>();
}
void OnDestroy()
{
if( Instance == this )
{
Instance = null;
}
}
public void ChangeScene( string i_scene )
{
StartCoroutine( ChangeSceneProcess( i_scene ) );
}
private IEnumerator ChangeSceneProcess( string i_scene )
{
m_fade.FadeOut( 2.0f, Color.red );
yield return new WaitWhile( () => m_fade.State == FadeController.EFadeState.Process );
SceneManager.LoadScene( i_scene );
m_fade.FadeIn();
yield return new WaitWhile( () => m_fade.State == FadeController.EFadeState.Process );
}
} // class SceneController
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment