「Unity/Csharp/シングルトン」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→MonoBehaviourを使ったシングルトン) |
(→MonoBehaviourを使ったシングルトン) |
||
| 行3: | 行3: | ||
using System.Collections.Generic; | using System.Collections.Generic; | ||
using UnityEngine; | using UnityEngine; | ||
| − | public class | + | public class SampleManager : MonoBehaviour { |
| − | private static | + | private static SampleManager mInstance; |
public int x = 1; | public int x = 1; | ||
| − | private | + | private SampleManager () { |
} | } | ||
| − | public static | + | public static SampleManager Instance { |
get { | get { | ||
if (mInstance == null) { | if (mInstance == null) { | ||
| − | GameObject go = new GameObject(" | + | GameObject go = new GameObject("SampleManager"); |
| − | mInstance = go.AddComponent< | + | mInstance = go.AddComponent<SampleManager>(); |
} | } | ||
return mInstance; | return mInstance; | ||
2017年9月22日 (金) 23:52時点における版
MonoBehaviourを使ったシングルトン
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SampleManager : MonoBehaviour {
private static SampleManager mInstance;
public int x = 1;
private SampleManager () {
}
public static SampleManager Instance {
get {
if (mInstance == null) {
GameObject go = new GameObject("SampleManager");
mInstance = go.AddComponent<SampleManager>();
}
return mInstance;
}
}
void Start () {
}
void Update () {
}
}
