forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectMask2D.cs
More file actions
164 lines (144 loc) · 3.98 KB
/
RectMask2D.cs
File metadata and controls
164 lines (144 loc) · 3.98 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections.Generic;
using UnityEngine.EventSystems;
namespace UnityEngine.UI
{
[AddComponentMenu("UI/Rect Mask 2D", 13), DisallowMultipleComponent, ExecuteInEditMode, RequireComponent(typeof(RectTransform))]
public class RectMask2D : UIBehaviour, IClipper, ICanvasRaycastFilter
{
[NonSerialized]
private readonly RectangularVertexClipper m_VertexClipper = new RectangularVertexClipper();
[NonSerialized]
private RectTransform m_RectTransform;
[NonSerialized]
private HashSet<IClippable> m_ClipTargets = new HashSet<IClippable>();
[NonSerialized]
private bool m_ShouldRecalculateClipRects;
[NonSerialized]
private List<RectMask2D> m_Clippers = new List<RectMask2D>();
[NonSerialized]
private Rect m_LastClipRectCanvasSpace;
[NonSerialized]
private bool m_LastValidClipRect;
[NonSerialized]
private bool m_ForceClip;
public Rect canvasRect
{
get
{
Canvas c = null;
List<Canvas> list = ListPool<Canvas>.Get();
base.gameObject.GetComponentsInParent<Canvas>(false, list);
if (list.Count > 0)
{
c = list[list.Count - 1];
}
ListPool<Canvas>.Release(list);
return this.m_VertexClipper.GetCanvasRect(this.rectTransform, c);
}
}
public RectTransform rectTransform
{
get
{
RectTransform arg_1D_0;
if ((arg_1D_0 = this.m_RectTransform) == null)
{
arg_1D_0 = (this.m_RectTransform = base.GetComponent<RectTransform>());
}
return arg_1D_0;
}
}
protected RectMask2D()
{
}
protected override void OnEnable()
{
base.OnEnable();
this.m_ShouldRecalculateClipRects = true;
ClipperRegistry.Register(this);
MaskUtilities.Notify2DMaskStateChanged(this);
}
protected override void OnDisable()
{
base.OnDisable();
this.m_ClipTargets.Clear();
this.m_Clippers.Clear();
ClipperRegistry.Unregister(this);
MaskUtilities.Notify2DMaskStateChanged(this);
}
protected override void OnValidate()
{
base.OnValidate();
this.m_ShouldRecalculateClipRects = true;
if (this.IsActive())
{
MaskUtilities.Notify2DMaskStateChanged(this);
}
}
public virtual bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
return !base.isActiveAndEnabled || RectTransformUtility.RectangleContainsScreenPoint(this.rectTransform, sp, eventCamera);
}
public virtual void PerformClipping()
{
if (this.m_ShouldRecalculateClipRects)
{
MaskUtilities.GetRectMasksForClip(this, this.m_Clippers);
this.m_ShouldRecalculateClipRects = false;
}
bool flag = true;
Rect rect = Clipping.FindCullAndClipWorldRect(this.m_Clippers, out flag);
bool flag2 = rect != this.m_LastClipRectCanvasSpace;
if (flag2 || this.m_ForceClip)
{
foreach (IClippable current in this.m_ClipTargets)
{
current.SetClipRect(rect, flag);
}
this.m_LastClipRectCanvasSpace = rect;
this.m_LastValidClipRect = flag;
}
foreach (IClippable current2 in this.m_ClipTargets)
{
MaskableGraphic maskableGraphic = current2 as MaskableGraphic;
if (!(maskableGraphic != null) || maskableGraphic.canvasRenderer.hasMoved || flag2)
{
current2.Cull(this.m_LastClipRectCanvasSpace, this.m_LastValidClipRect);
}
}
}
public void AddClippable(IClippable clippable)
{
if (clippable != null)
{
this.m_ShouldRecalculateClipRects = true;
if (!this.m_ClipTargets.Contains(clippable))
{
this.m_ClipTargets.Add(clippable);
}
this.m_ForceClip = true;
}
}
public void RemoveClippable(IClippable clippable)
{
if (clippable != null)
{
this.m_ShouldRecalculateClipRects = true;
clippable.SetClipRect(default(Rect), false);
this.m_ClipTargets.Remove(clippable);
this.m_ForceClip = true;
}
}
protected override void OnTransformParentChanged()
{
base.OnTransformParentChanged();
this.m_ShouldRecalculateClipRects = true;
}
protected override void OnCanvasHierarchyChanged()
{
base.OnCanvasHierarchyChanged();
this.m_ShouldRecalculateClipRects = true;
}
}
}