-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathSingletonPatternExample2.cs
49 lines (42 loc) · 1.1 KB
/
SingletonPatternExample2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//-------------------------------------------------------------------------------------
// SingletonPatternExample2.cs
//-------------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
namespace SingletonPatternExample2
{
public class SingletonPatternExample2 : MonoBehaviour
{
void Start()
{
RenderManager.Instance.Show();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
RenderManager.Instance.Show();
}
}
}
public sealed class RenderManager
{
private static RenderManager _instance;
private RenderManager() { }
public static RenderManager Instance
{
get
{
if (_instance == null)
{
_instance = new RenderManager();
}
return _instance;
}
}
public void Show()
{
Debug.Log("RenderManager is a Singleton!");
}
}
}