From e9ea621b93fbb58d9edfca8375918791637bbd52 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 30 Dec 2020 20:59:04 +0800 Subject: +init --- .../Common/MobileAdsEventExecutor.cs | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs (limited to 'Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs') 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 adEventsQueue = new List(); + + 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(); + } + + public static bool IsActive() + { + return MobileAdsEventExecutor.instance != null; + } + + public void Awake() + { + UnityEngine.Object.DontDestroyOnLoad(base.gameObject); + } + + public static void ExecuteInUpdate(Action action) + { + List obj = MobileAdsEventExecutor.adEventsQueue; + lock (obj) + { + MobileAdsEventExecutor.adEventsQueue.Add(action); + MobileAdsEventExecutor.adEventsQueueEmpty = false; + } + } + + public void Update() + { + if (MobileAdsEventExecutor.adEventsQueueEmpty) + { + return; + } + List list = new List(); + List 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; + } + } +} -- cgit v1.1-26-g67d0