Skip to content

Instantly share code, notes, and snippets.

@uranuno
Created May 16, 2016 05:44
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 uranuno/8c74d73c1696ea60fd1a90954d53e224 to your computer and use it in GitHub Desktop.
Save uranuno/8c74d73c1696ea60fd1a90954d53e224 to your computer and use it in GitHub Desktop.
Unity SceneModule
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// Scene単位でパーツを管理する。
/// 型名 = Scene名
/// </summary>
public class SceneModule<T> : MonoBehaviour where T : SceneModule<T>
{
public static T current { get; private set; }
static string m_SceneName { get { return typeof(T).Name; } }
void Awake ()
{
current = (T)this;
}
public static AsyncOperation LoadAsync ()
{
if (current != null)
return null;
else
return SceneManager.LoadSceneAsync (m_SceneName, LoadSceneMode.Additive);
}
public static void Unload ()
{
if (current == null)
return;
SceneManager.UnloadScene (m_SceneName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment