forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIStateObjects.cs
More file actions
43 lines (38 loc) · 1.16 KB
/
GUIStateObjects.cs
File metadata and controls
43 lines (38 loc) · 1.16 KB
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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngineInternal;
namespace UnityEngine
{
internal class GUIStateObjects
{
static Dictionary<int, object> s_StateCache = new Dictionary<int, object>();
[System.Security.SecuritySafeCritical]
internal static object GetStateObject(System.Type t, int controlID)
{
object o;
if (!s_StateCache.TryGetValue(controlID, out o) || o.GetType() != t)
{
o = System.Activator.CreateInstance(t);
s_StateCache[controlID] = o;
}
return o;
}
internal static object QueryStateObject(System.Type t, int controlID)
{
object o = s_StateCache[controlID];
if (t.IsInstanceOfType(o))
{
return o;
}
return null;
}
static internal void Tests_ClearObjects()
{
s_StateCache.Clear();
}
}
}