diff options
Diffstat (limited to 'Runtime/Export/GUIStateObjects.cs')
-rw-r--r-- | Runtime/Export/GUIStateObjects.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Runtime/Export/GUIStateObjects.cs b/Runtime/Export/GUIStateObjects.cs new file mode 100644 index 0000000..e37bc93 --- /dev/null +++ b/Runtime/Export/GUIStateObjects.cs @@ -0,0 +1,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 |