summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/XInterfaceMgr.cs
blob: 38bfaece81ac3b51069ac9c3e6ec96b4d8f34fff (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
using System;
using System.Collections.Generic;

namespace XUtliPoolLib
{
	public class XInterfaceMgr : XSingleton<XInterfaceMgr>
	{
		private Dictionary<uint, IXInterface> _interfaces = new Dictionary<uint, IXInterface>();

		public T GetInterface<T>(uint key) where T : IXInterface
		{
			IXInterface ixinterface = null;
			this._interfaces.TryGetValue(key, out ixinterface);
			return (T)((object)ixinterface);
		}

		public T AttachInterface<T>(uint key, T value) where T : IXInterface
		{
			bool flag = this._interfaces.ContainsKey(key);
			if (flag)
			{
				this._interfaces[key].Deprecated = true;
				XSingleton<XDebug>.singleton.AddLog("Duplication key for interface ", this._interfaces[key].ToString(), " and ", value.ToString(), null, null, XDebugColor.XDebug_None);
				this._interfaces[key] = value;
			}
			else
			{
				this._interfaces.Add(key, value);
			}
			this._interfaces[key].Deprecated = false;
			return value;
		}

		public void DetachInterface(uint key)
		{
			bool flag = this._interfaces.ContainsKey(key);
			if (flag)
			{
				this._interfaces[key].Deprecated = true;
				this._interfaces.Remove(key);
			}
		}

		public override bool Init()
		{
			return true;
		}

		public override void Uninit()
		{
			this._interfaces.Clear();
		}
	}
}