heyJordanParker/yaSingleton

Using yaSingletons for NON-MONOBEHAVIOUR Classes, like Utility classes?

Closed this issue · 2 comments

As mentioned in the title, I would love to know, am I able to use ur SIngletones as constant undismissable classes which keeps their data alive even when editor/runtime refreshes, since I have a current static class called "Utility" which has some int and lists of objects which gets their content from assertdatabase calls and which it should keep persistent for the entire lifetime of the unityEngine as such. Is this possible and if so, how can I do this, since it seems to me that its only useful if it should do mono stuff or am i wrong (hopefully i might add ^haha)

Best regards

Shpend

To be more specific:

I have a Tile subclass (MyTile: Tile {...}) and in this MyTile i have a "MenuItem" which creates a new mytuile with specifc settings and within that i need a counter, persistent counter, which only shall notify when the creation of the tile is finished at a given amount, like when i created 10 amount of that tile it should stop making new ones. But when i do:

public class Utility : yaSingleton.Singleton {...}
it tells me that ur singleton is calling DontDestroyOnLoad which wont work for editor scripts and hence my question how can I have a scritpablesingleton of my utlility class its so important, any help much appreciated!

Heya,

A basic ScriptableObject should do the trick for what you're describing. I also have a bunch of tooling around ScriptableObjects in my main library Elarion. Just extend the SavedObject class and then add a menu item so you can create it.
There's also a bunch of things you can use to store small specific things - e.g. values or arrays of objects.

I hope that's helpful!

PS: The library can't really create singletons in the Editor (I've planned those forever, but still haven't implemented them) because it lacks the Update methods.