-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonoBehaviourSingleton.snippet
More file actions
42 lines (42 loc) · 1.16 KB
/
MonoBehaviourSingleton.snippet
File metadata and controls
42 lines (42 loc) · 1.16 KB
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
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MonoBehaviour Singleton</Title>
<Author>Cong Wang</Author>
<Shortcut>ms</Shortcut>
<Description>MonoBehaviour Singleton</Description>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>UnityEngine</Namespace>
</Import>
</Imports>
<Declarations>
<Literal>
<ID>classname</ID>
<Default>NewBehaviourSingleton</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
public class $classname$ : MonoBehaviour
{
public static $classname$ Instance { get; private set; }
public static $classname$ NewInstance()
{
var go = new GameObject("$classname$", typeof($classname$));
DontDestroyOnLoad(go);
return Instance;
}
private void Awake()
{
Instance = this;
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>