Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
【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
You can’t perform that action at this time.