using Mogafa.Unity.Common; using Mogafa.Unity.Common.Contexts; using System.Threading.Tasks; using UnityEngine; namespace DidabuCloud.Unity.Core { internal class DidabuGlobalMonoBehaviour : MogafaMonoBehaviourBase { internal static DidabuGlobalMonoBehaviour Global { get; set; } internal Didabu Didabu { get; set; } internal static GameObject GameObject { get; set; } bool isInTick = false; [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void Init() { GameObject = new GameObject("DidabuGlobalMonoBehaviour"); DontDestroyOnLoad(GameObject); Global = GameObject.AddComponent(); } internal T AddComponent() where T:Component { return GameObject.AddComponent(); } void Start() { InvokeRepeating("Tick", 0, 0.02f); } // Update is called once per frame void Update() { } void OnApplicationQuit() { } void OnApplicationPause(bool pauseStatus) { if (pauseStatus) { Logger.LogWarning("Into background."); if (Didabu != null) { Didabu.ApplicationPauseHandler?.Invoke(); } } } async Task Tick() { if (isInTick) { return; } isInTick = true; await TimesTaskManager.Tick(); isInTick = false; } } }