summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/GoogleMobileAds/Common/MobileAdsEventExecutor.cs
blob: 8afa69c67cec6518c2a866b1ed9605c9694edbdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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;
		}
	}
}