https://github.com/pspkurara/singleton
Supports Unity's simple Singleton Behavior.
https://github.com/pspkurara/singleton
simple singleton unity
Last synced: 2 months ago
JSON representation
Supports Unity's simple Singleton Behavior.
- Host: GitHub
- URL: https://github.com/pspkurara/singleton
- Owner: pspkurara
- Created: 2022-09-07T07:18:14.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-21T13:02:35.000Z (almost 4 years ago)
- Last Synced: 2025-03-26T15:54:51.834Z (over 1 year ago)
- Topics: simple, singleton, unity
- Language: C#
- Homepage:
- Size: 167 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Singleton
Supports Unity's simple Singleton Behavior.
[](https://openupm.com/packages/com.pspkurara.singleton/)
[](https://github.com/pspkurara/singleton/releases/)
[](https://github.com/pspkurara/external-selecion-state/subscription)
## Usage
Create a script that extends SingletonMonoBehaviour.
Specify your own class name for the generic T.
```
using UnityEngine;
using Pspkurara.Singleton;
public class SampleSingleton : SingletonMonoBehaviour
{
public int InspectorValue = 1;
}
public class SampleAccess : MonoBehaviour
{
private void Start()
{
Debug.Log(SampleSingleton.instance.InspectorValue); // output: 1
}
}
```
If you inherit anything with "Internal", only the inherited class has access to ".instance".
You can implement static wrapper members to make them look like constants.
```
using UnityEngine;
using Pspkurara.Singleton;
public class SampleSingleton : InternalSingletonMonoBehaviour
{
// raw value.
[SerializeField]
private int m_InspectorValue = 1;
// static wrapper.
public static int Value { get { return instance.m_InspectorValue; } }
}
public class SampleAccess : MonoBehaviour
{
private void Start()
{
Debug.Log(SampleSingleton.Value); // output: 1
}
}
```
### Full API references
* https://pspkurara.github.io/singleton/
## Installation
### Using OpenUPM
Go to Unity's project folder on the command line and call:
```
openupm add com.pspkurara.singleton
```
### Using Unity Package Manager (For Unity 2018.3 or later)
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
```
{
"dependencies": {
"com.pspkurara.singleton": "https://github.com/pspkurara/singleton.git#upm",
...
},
}
```
#### Requirement
Unity 2018.1 or later
May work in Unity5, but unofficial.
## License
* [MIT](https://github.com/pspkurara/singleton/blob/master/Packages/Singleton/LICENSE.md)
## Author
* [pspkurara](https://github.com/pspkurara)
[](https://twitter.com/intent/follow?screen_name=pspkurara)
## See Also
* GitHub page : https://github.com/pspkurara/singleton