forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectMask2D.cs
More file actions
170 lines (156 loc) · 5.46 KB
/
RectMask2D.cs
File metadata and controls
170 lines (156 loc) · 5.46 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
165
166
167
168
169
170
// Decompiled with JetBrains decompiler
// Type: UnityEngine.UI.RectMask2D
// 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;
using System.Collections.Generic;
using UnityEngine.EventSystems;
namespace UnityEngine.UI
{
/// <summary>
/// <para>A 2D rectangular mask that allows for clipping / masking of areas outside the mask.</para>
/// </summary>
[DisallowMultipleComponent]
[RequireComponent(typeof (RectTransform))]
[ExecuteInEditMode]
[AddComponentMenu("UI/2D Rect Mask", 13)]
public class RectMask2D : UIBehaviour, ICanvasRaycastFilter, IClipper
{
[NonSerialized]
private readonly RectangularVertexClipper m_VertexClipper = new RectangularVertexClipper();
[NonSerialized]
private List<IClippable> m_ClipTargets = new List<IClippable>();
[NonSerialized]
private List<RectMask2D> m_Clippers = new List<RectMask2D>();
[NonSerialized]
private RectTransform m_RectTransform;
[NonSerialized]
private bool m_ShouldRecalculateClipRects;
[NonSerialized]
private Rect m_LastClipRectCanvasSpace;
[NonSerialized]
private bool m_LastValidClipRect;
[NonSerialized]
private bool m_ForceClip;
/// <summary>
/// <para>Get the Rect for the mask in canvas space.</para>
/// </summary>
public Rect canvasRect
{
get
{
Canvas c = (Canvas) null;
List<Canvas> canvasList = ListPool<Canvas>.Get();
this.gameObject.GetComponentsInParent<Canvas>(false, canvasList);
if (canvasList.Count > 0)
c = canvasList[canvasList.Count - 1];
ListPool<Canvas>.Release(canvasList);
return this.m_VertexClipper.GetCanvasRect(this.rectTransform, c);
}
}
/// <summary>
/// <para>Get the RectTransform for the mask.</para>
/// </summary>
public RectTransform rectTransform
{
get
{
return this.m_RectTransform ?? (this.m_RectTransform = this.GetComponent<RectTransform>());
}
}
protected RectMask2D()
{
}
protected override void OnEnable()
{
base.OnEnable();
this.m_ShouldRecalculateClipRects = true;
ClipperRegistry.Register((IClipper) this);
MaskUtilities.Notify2DMaskStateChanged((Component) this);
}
protected override void OnDisable()
{
base.OnDisable();
this.m_ClipTargets.Clear();
this.m_Clippers.Clear();
ClipperRegistry.Unregister((IClipper) this);
MaskUtilities.Notify2DMaskStateChanged((Component) this);
}
protected override void OnValidate()
{
base.OnValidate();
this.m_ShouldRecalculateClipRects = true;
if (!this.IsActive())
return;
MaskUtilities.Notify2DMaskStateChanged((Component) this);
}
/// <summary>
/// <para>See:ICanvasRaycastFilter.</para>
/// </summary>
/// <param name="sp"></param>
/// <param name="eventCamera"></param>
public virtual bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
if (!this.isActiveAndEnabled)
return true;
return RectTransformUtility.RectangleContainsScreenPoint(this.rectTransform, sp, eventCamera);
}
/// <summary>
/// <para>See: IClipper.PerformClipping.</para>
/// </summary>
public virtual void PerformClipping()
{
if (this.m_ShouldRecalculateClipRects)
{
MaskUtilities.GetRectMasksForClip(this, this.m_Clippers);
this.m_ShouldRecalculateClipRects = false;
}
bool validRect = true;
Rect andClipWorldRect = Clipping.FindCullAndClipWorldRect(this.m_Clippers, out validRect);
if (andClipWorldRect != this.m_LastClipRectCanvasSpace || this.m_ForceClip)
{
for (int index = 0; index < this.m_ClipTargets.Count; ++index)
this.m_ClipTargets[index].SetClipRect(andClipWorldRect, validRect);
this.m_LastClipRectCanvasSpace = andClipWorldRect;
this.m_LastValidClipRect = validRect;
}
for (int index = 0; index < this.m_ClipTargets.Count; ++index)
this.m_ClipTargets[index].Cull(this.m_LastClipRectCanvasSpace, this.m_LastValidClipRect);
}
/// <summary>
/// <para>Add a [IClippable]] to be tracked by the mask.</para>
/// </summary>
/// <param name="clippable"></param>
public void AddClippable(IClippable clippable)
{
if (clippable == null)
return;
if (!this.m_ClipTargets.Contains(clippable))
this.m_ClipTargets.Add(clippable);
this.m_ForceClip = true;
}
/// <summary>
/// <para>Remove an IClippable from being tracked by the mask.</para>
/// </summary>
/// <param name="clippable"></param>
public void RemoveClippable(IClippable clippable)
{
if (clippable == null)
return;
clippable.SetClipRect(new 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;
}
}
}