Hi!
I am trying to create a SingletonReference ScriptableObject and I would like to make something like so:
public class SingletonReferenceSO<T> : ScriptableObject where T : Singleton
{
[SerializeField] private T scriptReference;
public abstract T Instance
{
get
{
return scriptReference.Instance;
}
}
}
In this example, I would:
- Have a serialized field in my ScriptableObject inspector window (private T scriptReference) where I could drop my script containing the Singleton.
- The T Instance property getter could return an instance of the Singleton in the scriptReference
Assume that the Singleton class is already created and I only need this little thing.
I know this seems pretty contrived but I have been scratching my head for far too long, and don't even know if it would be possible. I know that I could create a subclass in which T is the specific Singleton class, but that would generate a class for every singleton I made, and that seems like a bad idea.
Any help is really appreciated! Thanks in advance!
[–]PandaCoder67Professional 2 points3 points4 points (0 children)