Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d7e24f

Browse files
committed
给单例模式加上更直观的一个示例
给单例模式加上更直观的一个示例
1 parent e534fb8 commit 3d7e24f

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

‎Assets/Creational Patterns/Singleton Pattern/Example2.meta‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//-------------------------------------------------------------------------------------
2+
// SingletonPatternExample2.cs
3+
//-------------------------------------------------------------------------------------
4+
5+
using UnityEngine;
6+
using System.Collections;
7+
8+
namespace SingletonPatternExample2
9+
{
10+
public class SingletonPatternExample2 : MonoBehaviour
11+
{
12+
void Start()
13+
{
14+
RenderManager.Instance.Show();
15+
}
16+
17+
void Update()
18+
{
19+
if (Input.GetKeyDown(KeyCode.Alpha1))
20+
{
21+
RenderManager.Instance.Show();
22+
}
23+
}
24+
}
25+
26+
27+
/// <summary>
28+
/// 某单例manager
29+
/// </summary>
30+
public class RenderManager
31+
{
32+
private static RenderManager instance;
33+
public static RenderManager Instance
34+
{
35+
get
36+
{
37+
if (instance == null)
38+
{
39+
instance = new RenderManager();
40+
}
41+
return instance;
42+
}
43+
}
44+
45+
/// <summary>
46+
/// 随便某方法
47+
/// </summary>
48+
public void Show()
49+
{
50+
Debug.Log("RenderManager is a Singleton !");
51+
}
52+
}
53+
54+
55+
56+
57+
}

‎Assets/Creational Patterns/Singleton Pattern/Example2/SingletonPatternExample2.cs.meta‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

‎Assets/Creational Patterns/Singleton Pattern/Example2/SingletonPatternExample2.unity.meta‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /