summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/GraphicRegistry.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-08 09:50:33 +0800
committerchai <chaifix@163.com>2020-10-08 09:50:33 +0800
commit00dae1bd426d892dff73a50f1c505afd1ac00a90 (patch)
tree5d75f8495406f5b8dd01595e3dd9216887996a34 /Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/GraphicRegistry.cs
+init
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/GraphicRegistry.cs')
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/GraphicRegistry.cs76
1 files changed, 76 insertions, 0 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/GraphicRegistry.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/GraphicRegistry.cs
new file mode 100644
index 0000000..ca7eddf
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/GraphicRegistry.cs
@@ -0,0 +1,76 @@
+using System.Collections.Generic;
+using UnityEngine.UI.Collections;
+
+namespace UnityEngine.UI
+{
+ public class GraphicRegistry
+ {
+ private static GraphicRegistry s_Instance;
+
+ private readonly Dictionary<Canvas, IndexedSet<Graphic>> m_Graphics = new Dictionary<Canvas, IndexedSet<Graphic>>();
+
+ protected GraphicRegistry()
+ {
+ // This is needed for AOT on IOS. Without it the compile doesn't get the definition of the Dictionarys
+#pragma warning disable 168
+ Dictionary<Graphic, int> emptyGraphicDic;
+ Dictionary<ICanvasElement, int> emptyElementDic;
+#pragma warning restore 168
+ }
+
+ public static GraphicRegistry instance
+ {
+ get
+ {
+ if (s_Instance == null)
+ s_Instance = new GraphicRegistry();
+ return s_Instance;
+ }
+ }
+
+ public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic)
+ {
+ if (c == null)
+ return;
+
+ IndexedSet<Graphic> graphics;
+ instance.m_Graphics.TryGetValue(c, out graphics);
+
+ if (graphics != null)
+ {
+ graphics.AddUnique(graphic);
+ return;
+ }
+
+ // Dont need to AddUnique as we know its the only item in the list
+ graphics = new IndexedSet<Graphic>();
+ graphics.Add(graphic);
+ instance.m_Graphics.Add(c, graphics);
+ }
+
+ public static void UnregisterGraphicForCanvas(Canvas c, Graphic graphic)
+ {
+ if (c == null)
+ return;
+
+ IndexedSet<Graphic> graphics;
+ if (instance.m_Graphics.TryGetValue(c, out graphics))
+ {
+ graphics.Remove(graphic);
+
+ if (graphics.Count == 0)
+ instance.m_Graphics.Remove(c);
+ }
+ }
+
+ private static readonly List<Graphic> s_EmptyList = new List<Graphic>();
+ public static IList<Graphic> GetGraphicsForCanvas(Canvas canvas)
+ {
+ IndexedSet<Graphic> graphics;
+ if (instance.m_Graphics.TryGetValue(canvas, out graphics))
+ return graphics;
+
+ return s_EmptyList;
+ }
+ }
+}