forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaskUtilities.cs
More file actions
131 lines (124 loc) · 4.79 KB
/
MaskUtilities.cs
File metadata and controls
131 lines (124 loc) · 4.79 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Decompiled with JetBrains decompiler
// Type: UnityEngine.UI.MaskUtilities
// Assembly: UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 2216A18B-AF52-44A5-85A0-A1CAA19C1090
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEngine.UI.dll
using System.Collections.Generic;
namespace UnityEngine.UI
{
/// <summary>
/// <para>Mask related utility class.</para>
/// </summary>
public class MaskUtilities
{
/// <summary>
/// <para>Notify all IClippables under the given component that they need to recalculate clipping.</para>
/// </summary>
/// <param name="mask"></param>
public static void Notify2DMaskStateChanged(Component mask)
{
List<Component> componentList = ListPool<Component>.Get();
mask.GetComponentsInChildren<Component>(componentList);
for (int index = 0; index < componentList.Count; ++index)
{
if (!((Object) componentList[index] == (Object) null) && !((Object) componentList[index].gameObject == (Object) mask.gameObject))
{
IClippable clippable = componentList[index] as IClippable;
if (clippable != null)
clippable.RecalculateClipping();
}
}
ListPool<Component>.Release(componentList);
}
/// <summary>
/// <para>Notify all IMaskable under the given component that they need to recalculate masking.</para>
/// </summary>
/// <param name="mask"></param>
public static void NotifyStencilStateChanged(Component mask)
{
List<Component> componentList = ListPool<Component>.Get();
mask.GetComponentsInChildren<Component>(componentList);
for (int index = 0; index < componentList.Count; ++index)
{
if (!((Object) componentList[index] == (Object) null) && !((Object) componentList[index].gameObject == (Object) mask.gameObject))
{
IMaskable maskable = componentList[index] as IMaskable;
if (maskable != null)
maskable.RecalculateMasking();
}
}
ListPool<Component>.Release(componentList);
}
/// <summary>
/// <para>Find a root Canvas.</para>
/// </summary>
/// <param name="start">Search start.</param>
/// <returns>
/// <para>Canvas transform.</para>
/// </returns>
public static Transform FindRootSortOverrideCanvas(Transform start)
{
List<Canvas> canvasList = ListPool<Canvas>.Get();
start.GetComponentsInParent<Canvas>(false, canvasList);
Canvas canvas = (Canvas) null;
for (int index = 0; index < canvasList.Count; ++index)
{
canvas = canvasList[index];
if (canvas.overrideSorting)
break;
}
ListPool<Canvas>.Release(canvasList);
if ((Object) canvas != (Object) null)
return canvas.transform;
return (Transform) null;
}
/// <summary>
/// <para>Find the stencil depth for a given element.</para>
/// </summary>
/// <param name="transform"></param>
/// <param name="stopAfter"></param>
public static int GetStencilDepth(Transform transform, Transform stopAfter)
{
int num = 0;
if ((Object) transform == (Object) stopAfter)
return num;
Transform parent = transform.parent;
List<Mask> maskList = ListPool<Mask>.Get();
for (; (Object) parent != (Object) null; parent = parent.parent)
{
parent.GetComponents<Mask>(maskList);
for (int index = 0; index < maskList.Count; ++index)
{
if ((Object) maskList[index] != (Object) null && maskList[index].IsActive() && ((Object) maskList[index].graphic != (Object) null && maskList[index].graphic.IsActive()))
{
++num;
break;
}
}
if ((Object) parent == (Object) stopAfter)
break;
}
ListPool<Mask>.Release(maskList);
return num;
}
/// <summary>
/// <para>Find the correct RectMask2D for a given IClippable.</para>
/// </summary>
/// <param name="transform">Clippable to search from.</param>
public static RectMask2D GetRectMaskForClippable(IClippable transform)
{
List<RectMask2D> rectMask2DList = ListPool<RectMask2D>.Get();
RectMask2D rectMask2D = (RectMask2D) null;
transform.rectTransform.GetComponentsInParent<RectMask2D>(false, rectMask2DList);
if (rectMask2DList.Count > 0)
rectMask2D = rectMask2DList[0];
ListPool<RectMask2D>.Release(rectMask2DList);
return rectMask2D;
}
public static void GetRectMasksForClip(RectMask2D clipper, List<RectMask2D> masks)
{
masks.Clear();
clipper.transform.GetComponentsInParent<RectMask2D>(false, masks);
}
}
}