diff options
author | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
commit | e9ea621b93fbb58d9edfca8375918791637bbd52 (patch) | |
tree | 19ce3b1c1f2d51eda6878c9d0f2c9edc27f13650 /Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs |
+init
Diffstat (limited to 'Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs')
-rw-r--r-- | Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs b/Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs new file mode 100644 index 0000000..8afa69c --- /dev/null +++ b/Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace GoogleMobileAds.Common +{ + public class MobileAdsEventExecutor : MonoBehaviour + { + public static MobileAdsEventExecutor instance = null; + + private static List<Action> adEventsQueue = new List<Action>(); + + private static volatile bool adEventsQueueEmpty = true; + + public static void Initialize() + { + if (MobileAdsEventExecutor.IsActive()) + { + return; + } + GameObject gameObject = new GameObject("MobileAdsMainThreadExecuter"); + gameObject.hideFlags = HideFlags.HideAndDontSave; + UnityEngine.Object.DontDestroyOnLoad(gameObject); + MobileAdsEventExecutor.instance = gameObject.AddComponent<MobileAdsEventExecutor>(); + } + + public static bool IsActive() + { + return MobileAdsEventExecutor.instance != null; + } + + public void Awake() + { + UnityEngine.Object.DontDestroyOnLoad(base.gameObject); + } + + public static void ExecuteInUpdate(Action action) + { + List<Action> obj = MobileAdsEventExecutor.adEventsQueue; + lock (obj) + { + MobileAdsEventExecutor.adEventsQueue.Add(action); + MobileAdsEventExecutor.adEventsQueueEmpty = false; + } + } + + public void Update() + { + if (MobileAdsEventExecutor.adEventsQueueEmpty) + { + return; + } + List<Action> list = new List<Action>(); + List<Action> obj = MobileAdsEventExecutor.adEventsQueue; + lock (obj) + { + list.AddRange(MobileAdsEventExecutor.adEventsQueue); + MobileAdsEventExecutor.adEventsQueue.Clear(); + MobileAdsEventExecutor.adEventsQueueEmpty = true; + } + foreach (Action action in list) + { + action(); + } + } + + public void OnDisable() + { + MobileAdsEventExecutor.instance = null; + } + } +} |