summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XEventBlocker.cs
blob: a38bce1fde075eb5c0ee69d7dd820c0020036fb4 (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
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XEventBlocker<T> where T : XEventArgs
	{
		public XEventBlocker<T>.XEventHandler EventHandler { get; set; }

		public bool bBlockReceiver
		{
			get
			{
				return this.m_bBlockReceiver;
			}
			set
			{
				this.m_bBlockReceiver = value;
				bool flag = !this.m_bBlockReceiver;
				if (flag)
				{
					for (int i = 0; i < this.m_EventPool.Count; i++)
					{
						bool flag2 = this.EventHandler != null;
						if (flag2)
						{
							this.EventHandler(this.m_EventPool[i]);
						}
						this.m_EventPool[i].Recycle();
					}
					this.m_EventPool.Clear();
				}
			}
		}

		public bool bBlockSender
		{
			get
			{
				return this.m_bBlockSender;
			}
			set
			{
				this.m_bBlockSender = value;
				bool flag = !this.m_bBlockSender;
				if (flag)
				{
					for (int i = 0; i < this.m_EventPool.Count; i++)
					{
						XSingleton<XEventMgr>.singleton.FireEvent(this.m_EventPool[i]);
					}
					this.m_EventPool.Clear();
				}
			}
		}

		private List<T> m_EventPool = new List<T>();

		private bool m_bBlockReceiver = false;

		private bool m_bBlockSender = false;

		public delegate bool XEventHandler(XEventArgs e);

		public void AddEvent(T e)
		{
			this.m_EventPool.Add(e);
		}

		public void ClearEvents()
		{
			this.m_EventPool.Clear();
			this.m_bBlockReceiver = false;
			this.m_bBlockSender = false;
		}
	}
}