Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MonoSingleton Type #29

Merged
merged 2 commits into from
Aug 19, 2019
Merged

Added MonoSingleton Type #29

merged 2 commits into from
Aug 19, 2019

Conversation

wqyeo
Copy link
Contributor

@wqyeo wqyeo commented Aug 18, 2019

Same functionality as Singleton, but you can choose to apply a DontDestroyOnLoad on it via the inspector.

However, it inherits from MonoBehaviour unlike the original Singleton. This is due to it using Awake call to apply a DontDestroyOnLoad on the instance if need.
The child class will need to override an OnAwake function. (simulates an Awake call)

I decided to keep the original Singleton, and made this into MonoSingleton due to the above stated differences.

P.S: Also, should we make the original Singleton class an abstract?

Like singleton, but you can choose to apply a DontDestroyOnLoad on it. It also inherits from MonoBehaviour already.
@Deadcows
Copy link
Owner

Well actually existing Singleton<> is for MonoBehaviours but simply for caching and global access.
So Singleton.Instance.Play(...); will access and cache AudioManager on scene.
It's possible to easily add Instantiation functionality along with Don't destroy on load there.
I like the idea that MB itself is not a singleton, but outer scripts may access it statically :) But it was made for specific case and I didn't used it for a few years now, so...

Personally I don't like base MB classes, but I got your point 👍🏻

@Deadcows Deadcows merged commit 54925ea into Deadcows:master Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants