summaryrefslogtreecommitdiff
path: root/Runtime/Export/GUIStateObjects.cs
blob: e37bc9378e275e0c6965f2f7bf77a90253d2ab78 (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
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;

namespace UnityEngine
{

internal class GUIStateObjects
{
	static Dictionary<int, object> s_StateCache = new Dictionary<int, object>();

	[System.Security.SecuritySafeCritical]
	static internal object GetStateObject (System.Type t, int controlID)
	{
		object o;
		if (s_StateCache.TryGetValue(controlID, out o) == false || o.GetType() != t)
		{
			o = System.Activator.CreateInstance(t);
			s_StateCache[controlID] = o;
		} 
		return o;
	}
	
	static internal object QueryStateObject (System.Type t, int controlID)
	{
		object o = s_StateCache[controlID];
		if (t.IsInstanceOfType (o))
			return o;
		return null;
	}
	
}

}		// namespace