Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ShirakawaYoshimaru/90620945db861778d7328c51cbc8d727 to your computer and use it in GitHub Desktop.
Save ShirakawaYoshimaru/90620945db861778d7328c51cbc8d727 to your computer and use it in GitHub Desktop.
public class HogeSingleton
{
private static HogeSingleton singleton = new HogeSingleton ();
private HogeSingleton ()
{
//初期化処理
}
public static HogeSingleton Instance ()
{
return singleton;
}
public void Hoge()
{
//todo
}
}
using UnityEngine;
public class FugaSingleton : MonoBehaviour
{
private static FugaSingleton singleton;
//初期化タイミングをAwake時にやる
void Awake ()
{
//MonoBehaviourを継承しているのでnewできない
singleton = this;
}
public static FugaSingleton Instance ()
{
return singleton;
}
public void Hoge()
{
//todo
}
}
void Main(){
HogeSingleton.Instance ().Hello ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment