summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs')
-rw-r--r--Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs72
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;
+ }
+ }
+}