You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Install via Unity Package](#install-via-unity-package)
14
+
-[Install via git URL](#install-via-git-url)
12
15
-[License](#license)
13
16
14
17
### Simple Example
15
18
16
19
You can define a singleton by adding the `PowerSingleton` attribute to a class.
17
20
The class must inherit from `MonoBehaviour` and the attribute must be applied to the class.
18
-
The type of the singleton must be specified in the attribute.
19
21
20
22
```csharp
21
23
usingKekser.PowerSingleton.Attributes;
22
24
usingUnityEngine;
23
25
24
-
[PowerSingleton(typeof(GameManager))]
26
+
[PowerSingleton]
25
27
publicclassGameManager : MonoBehaviour
26
28
{
27
29
publicvoidAddScore(intscore)
@@ -39,9 +41,9 @@ using Kekser.PowerSingleton;
39
41
40
42
Single<GameManager>.Instance.AddScore(10);
41
43
```
42
-
### Interface
44
+
### Interface / Abstract Class
43
45
44
-
You can also define a singleton by an interface.
46
+
You can also define a singleton by an interface or an abstract class.
45
47
This widened flexibility allows you to use multiple Singleton classes, given they implement the specified interface. The system intuitively chooses the active class in the current scene.
46
48
47
49
```csharp
@@ -71,7 +73,9 @@ using Kekser.PowerSingleton;
71
73
72
74
Single<IGameManager>.Instance.AddScore(10);
73
75
```
74
-
### If Needed Creation
76
+
### Creation
77
+
78
+
#### If Needed Creation
75
79
76
80
You can define that the singleton should only be created when it is needed.
77
81
This is useful if you want to use the singleton in a scene where it is not yet present.
@@ -92,7 +96,7 @@ public class GameManager : MonoBehaviour
92
96
// ...
93
97
}
94
98
```
95
-
### Auto Creation
99
+
####Auto Creation
96
100
97
101
You can define that the singleton should be created automatically.
98
102
This is useful if you want to use the singleton in a scene where it is not yet present.
@@ -132,7 +136,12 @@ public class GameManager : MonoBehaviour
132
136
// ...
133
137
}
134
138
```
135
-
### Install via git URL
139
+
### Install
140
+
141
+
#### Install via Unity Package
142
+
143
+
Download the latest [release](/releases) and import the package into your Unity project.
144
+
#### Install via git URL
136
145
137
146
You can add this package to your project by adding this git URL in the Package Manager:
0 commit comments