1234567891011121314151617181920212223242526272829 |
- using UnityEngine;
- namespace Blue
- {
- public class SingletonMonobehaviour<T> : AbstractController where T:SingletonMonobehaviour<T>
- {
- private static T _instance;
- public static T Instance
- {
- get => _instance;
- }
- public virtual void OnAwake() { }
- private void Awake()
- {
- if (_instance == null)
- {
- _instance = this.GetComponent<T>();
- _instance.OnAwake();
- DontDestroyOnLoad(_instance);
- }
- else
- {
- Destroy(gameObject);
- }
- }
- }
- }
|