2018-11-20 20:10:49 +01:00
|
|
|
using UnityEngine;
|
|
|
|
|
2023-06-11 13:39:49 +02:00
|
|
|
namespace Fie.Manager {
|
|
|
|
public class FieManagerBehaviour<T> : FieManagerBase where T : FieManagerBase {
|
2018-11-20 20:10:49 +01:00
|
|
|
[SerializeField]
|
|
|
|
private bool _isAutoStartUp;
|
|
|
|
|
|
|
|
private static T instance;
|
|
|
|
|
2023-06-11 13:39:49 +02:00
|
|
|
public static T I {
|
|
|
|
get {
|
|
|
|
if (instance != null && instance.isDestroyed) {
|
|
|
|
instance = null;
|
2018-11-20 20:10:49 +01:00
|
|
|
}
|
2023-06-11 13:39:49 +02:00
|
|
|
if (instance == null)
|
2018-11-20 20:10:49 +01:00
|
|
|
{
|
|
|
|
instance = UnityEngine.Object.FindObjectOfType<T>();
|
2023-06-11 13:39:49 +02:00
|
|
|
if (instance == null || instance.isDestroyed) {
|
2018-11-20 20:10:49 +01:00
|
|
|
GameObject gameObject = new GameObject();
|
|
|
|
UnityEngine.Object.DontDestroyOnLoad(gameObject);
|
|
|
|
instance = gameObject.AddComponent<T>();
|
|
|
|
gameObject.name = instance.GetType().Name;
|
|
|
|
}
|
|
|
|
FieManagerFactory.I.AddManager(instance);
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
2023-06-11 13:39:49 +02:00
|
|
|
set {
|
2018-11-20 20:10:49 +01:00
|
|
|
instance = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-11 13:39:49 +02:00
|
|
|
private void Start() {
|
|
|
|
if (_isAutoStartUp) {
|
|
|
|
I.StartUp();
|
2018-11-20 20:10:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|