-
Notifications
You must be signed in to change notification settings - Fork 0
Singleton
This plugin contains two singleton base classes, one Monobehaviour Component and one Scriptable Object Class.
These classes are not made to create ease of access through static fields, instead, they are designed to only allow one object of its type in existence.
The generic type of the Instance static property allows for different inherited classes to be evaluated separately.
A Component that inherits from this class will destroy its own GameObject during runtime when detecting a duplicate.
This Singleton behavior allows for any scene to contain a type of GameManager prefab that will instantiate itself and create a base environment to test individual components.
On the other hand, if it detects an existing instance, it will delete itself to prevent duplication.
Any other Components in the scene that searches for a GameObject with a singleton component will find only one instance.
A Scriptable Object that inherits from this class will throw a warning in the console when detecting more than one asset file in existence.
This difference from the Component Singleton is necessary to prevent the dangerous and unwanted behavior of automatically deleting asset files from the project.