From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Export/GUIStateObjects.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Runtime/Export/GUIStateObjects.cs (limited to 'Runtime/Export/GUIStateObjects.cs') 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 s_StateCache = new Dictionary(); + + [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 -- cgit v1.1-26-g67d0