summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-05-08 23:15:13 +0800
committerchai <chaifix@163.com>2021-05-08 23:15:13 +0800
commitd07e14add74e017b52ab2371efeea1aa4ea10ced (patch)
treeefd07869326e4c428f5bfe43fad0c2583d32a401 /Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling
+init
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling')
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/ClipperRegistry.cs50
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/ClipperRegistry.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/Clipping.cs44
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/Clipping.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/IClipRegion.cs16
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/IClipRegion.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/RectangularVertexClipper.cs21
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/RectangularVertexClipper.cs.meta13
8 files changed, 183 insertions, 0 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/ClipperRegistry.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/ClipperRegistry.cs
new file mode 100644
index 0000000..ea7f527
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/ClipperRegistry.cs
@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using UnityEngine.UI.Collections;
+
+namespace UnityEngine.UI
+{
+ public class ClipperRegistry
+ {
+ static ClipperRegistry s_Instance;
+
+ readonly IndexedSet<IClipper> m_Clippers = new IndexedSet<IClipper>();
+
+ protected ClipperRegistry()
+ {
+ // This is needed for AOT platforms. Without it the compile doesn't get the definition of the Dictionarys
+#pragma warning disable 168
+ Dictionary<IClipper, int> emptyIClipperDic;
+#pragma warning restore 168
+ }
+
+ public static ClipperRegistry instance
+ {
+ get
+ {
+ if (s_Instance == null)
+ s_Instance = new ClipperRegistry();
+ return s_Instance;
+ }
+ }
+
+ public void Cull()
+ {
+ for (var i = 0; i < m_Clippers.Count; ++i)
+ {
+ m_Clippers[i].PerformClipping();
+ }
+ }
+
+ public static void Register(IClipper c)
+ {
+ if (c == null)
+ return;
+ instance.m_Clippers.AddUnique(c);
+ }
+
+ public static void Unregister(IClipper c)
+ {
+ instance.m_Clippers.Remove(c);
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/ClipperRegistry.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/ClipperRegistry.cs.meta
new file mode 100644
index 0000000..32995ae
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/ClipperRegistry.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: b494fa40405522d49af6bca6e68e4ba6
+timeCreated: 1602119379
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/Clipping.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/Clipping.cs
new file mode 100644
index 0000000..7dd39bf
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/Clipping.cs
@@ -0,0 +1,44 @@
+using System.Collections.Generic;
+
+namespace UnityEngine.UI
+{
+ public static class Clipping
+ {
+ public static Rect FindCullAndClipWorldRect(List<RectMask2D> rectMaskParents, out bool validRect)
+ {
+ if (rectMaskParents.Count == 0)
+ {
+ validRect = false;
+ return new Rect();
+ }
+
+ var compoundRect = rectMaskParents[0].canvasRect;
+ for (var i = 0; i < rectMaskParents.Count; ++i)
+ compoundRect = RectIntersect(compoundRect, rectMaskParents[i].canvasRect);
+
+ var cull = compoundRect.width <= 0 || compoundRect.height <= 0;
+ if (cull)
+ {
+ validRect = false;
+ return new Rect();
+ }
+
+ Vector3 point1 = new Vector3(compoundRect.x, compoundRect.y, 0.0f);
+ Vector3 point2 = new Vector3(compoundRect.x + compoundRect.width, compoundRect.y + compoundRect.height, 0.0f);
+ validRect = true;
+ return new Rect(point1.x, point1.y, point2.x - point1.x, point2.y - point1.y);
+ }
+
+ // ¼ÆËã¾ØÐν»¼¯
+ private static Rect RectIntersect(Rect a, Rect b)
+ {
+ float xMin = Mathf.Max(a.x, b.x);
+ float xMax = Mathf.Min(a.x + a.width, b.x + b.width);
+ float yMin = Mathf.Max(a.y, b.y);
+ float yMax = Mathf.Min(a.y + a.height, b.y + b.height);
+ if (xMax >= xMin && yMax >= yMin)
+ return new Rect(xMin, yMin, xMax - xMin, yMax - yMin);
+ return new Rect(0f, 0f, 0f, 0f);
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/Clipping.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/Clipping.cs.meta
new file mode 100644
index 0000000..698e06f
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/Clipping.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 88fc11e9a11bf1941abc08b9ed323b6f
+timeCreated: 1602119379
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/IClipRegion.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/IClipRegion.cs
new file mode 100644
index 0000000..4593f17
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/IClipRegion.cs
@@ -0,0 +1,16 @@
+namespace UnityEngine.UI
+{
+ public interface IClipper
+ {
+ void PerformClipping();
+ }
+
+ public interface IClippable
+ {
+ GameObject gameObject { get; }
+ void RecalculateClipping();
+ RectTransform rectTransform { get; }
+ void Cull(Rect clipRect, bool validRect);
+ void SetClipRect(Rect value, bool validRect);
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/IClipRegion.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/IClipRegion.cs.meta
new file mode 100644
index 0000000..1852869
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/IClipRegion.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: d395da6bc4c1e6f4b9521bb99b22f3b4
+timeCreated: 1602119380
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/RectangularVertexClipper.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/RectangularVertexClipper.cs
new file mode 100644
index 0000000..6d12322
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/RectangularVertexClipper.cs
@@ -0,0 +1,21 @@
+namespace UnityEngine.UI
+{
+ internal class RectangularVertexClipper
+ {
+ readonly Vector3[] m_WorldCorners = new Vector3[4];
+ readonly Vector3[] m_CanvasCorners = new Vector3[4];
+
+ public Rect GetCanvasRect(RectTransform t, Canvas c)
+ {
+ if (c == null)
+ return new Rect();
+
+ t.GetWorldCorners(m_WorldCorners);
+ var canvasTransform = c.GetComponent<Transform>();
+ for (int i = 0; i < 4; ++i)
+ m_CanvasCorners[i] = canvasTransform.InverseTransformPoint(m_WorldCorners[i]);
+
+ return new Rect(m_CanvasCorners[0].x, m_CanvasCorners[0].y, m_CanvasCorners[2].x - m_CanvasCorners[0].x, m_CanvasCorners[2].y - m_CanvasCorners[0].y);
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/RectangularVertexClipper.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/RectangularVertexClipper.cs.meta
new file mode 100644
index 0000000..f33cd90
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Culling/RectangularVertexClipper.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 545014a8997364a47b344095371a7332
+timeCreated: 1602119378
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: