Created
August 14, 2016 06:02
-
-
Save urahimono/44c51a6acf66a00c3668c3a6699a04b2 to your computer and use it in GitHub Desktop.
【Unity】簡易フェード制御コンポーネントについて考えてみる SceneController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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