forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMask.cs
More file actions
189 lines (176 loc) · 6.49 KB
/
Mask.cs
File metadata and controls
189 lines (176 loc) · 6.49 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Decompiled with JetBrains decompiler
// Type: UnityEngine.UI.Mask
// 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 UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.Serialization;
namespace UnityEngine.UI
{
/// <summary>
/// <para>A component for masking children elements.</para>
/// </summary>
[AddComponentMenu("UI/Mask", 13)]
[ExecuteInEditMode]
[DisallowMultipleComponent]
[RequireComponent(typeof (RectTransform))]
public class Mask : UIBehaviour, ICanvasRaycastFilter, IMaterialModifier
{
[FormerlySerializedAs("m_ShowGraphic")]
[SerializeField]
private bool m_ShowMaskGraphic = true;
[NonSerialized]
private RectTransform m_RectTransform;
[NonSerialized]
private Graphic m_Graphic;
[NonSerialized]
private Material m_MaskMaterial;
[NonSerialized]
private Material m_UnmaskMaterial;
/// <summary>
/// <para>Cached RectTransform.</para>
/// </summary>
public RectTransform rectTransform
{
get
{
return this.m_RectTransform ?? (this.m_RectTransform = this.GetComponent<RectTransform>());
}
}
/// <summary>
/// <para>Show the graphic that is associated with the Mask render area.</para>
/// </summary>
public bool showMaskGraphic
{
get
{
return this.m_ShowMaskGraphic;
}
set
{
if (this.m_ShowMaskGraphic == value)
return;
this.m_ShowMaskGraphic = value;
if (!((UnityEngine.Object) this.graphic != (UnityEngine.Object) null))
return;
this.graphic.SetMaterialDirty();
}
}
/// <summary>
/// <para>The graphic associated with the Mask.</para>
/// </summary>
public Graphic graphic
{
get
{
return this.m_Graphic ?? (this.m_Graphic = this.GetComponent<Graphic>());
}
}
protected Mask()
{
}
/// <summary>
/// <para>See:IMask.</para>
/// </summary>
[Obsolete("use Mask.enabled instead", true)]
public virtual bool MaskEnabled()
{
throw new NotSupportedException();
}
/// <summary>
/// <para>See:IGraphicEnabledDisabled.</para>
/// </summary>
[Obsolete("Not used anymore.")]
public virtual void OnSiblingGraphicEnabledDisabled()
{
}
protected override void OnEnable()
{
base.OnEnable();
if ((UnityEngine.Object) this.graphic != (UnityEngine.Object) null)
{
this.graphic.canvasRenderer.hasPopInstruction = true;
this.graphic.SetMaterialDirty();
}
MaskUtilities.NotifyStencilStateChanged((Component) this);
}
/// <summary>
/// <para>See MonoBehaviour.OnDisable.</para>
/// </summary>
protected override void OnDisable()
{
base.OnDisable();
if ((UnityEngine.Object) this.graphic != (UnityEngine.Object) null)
{
this.graphic.SetMaterialDirty();
this.graphic.canvasRenderer.hasPopInstruction = false;
this.graphic.canvasRenderer.popMaterialCount = 0;
}
StencilMaterial.Remove(this.m_MaskMaterial);
this.m_MaskMaterial = (Material) null;
StencilMaterial.Remove(this.m_UnmaskMaterial);
this.m_UnmaskMaterial = (Material) null;
MaskUtilities.NotifyStencilStateChanged((Component) this);
}
protected override void OnValidate()
{
base.OnValidate();
if (!this.IsActive())
return;
if ((UnityEngine.Object) this.graphic != (UnityEngine.Object) null)
this.graphic.SetMaterialDirty();
MaskUtilities.NotifyStencilStateChanged((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: IMaterialModifier.</para>
/// </summary>
/// <param name="baseMaterial"></param>
public virtual Material GetModifiedMaterial(Material baseMaterial)
{
if ((UnityEngine.Object) this.graphic == (UnityEngine.Object) null || !this.isActiveAndEnabled)
return baseMaterial;
int stencilDepth = MaskUtilities.GetStencilDepth(this.transform, MaskUtilities.FindRootSortOverrideCanvas(this.transform));
if (stencilDepth >= 8)
{
Debug.LogError((object) "Attempting to use a stencil mask with depth > 8", (UnityEngine.Object) this.gameObject);
return baseMaterial;
}
int num = 1 << stencilDepth;
if (num == 1)
{
Material material1 = StencilMaterial.Add(baseMaterial, 1, StencilOp.Replace, CompareFunction.Always, !this.m_ShowMaskGraphic ? (ColorWriteMask) 0 : ColorWriteMask.All);
StencilMaterial.Remove(this.m_MaskMaterial);
this.m_MaskMaterial = material1;
Material material2 = StencilMaterial.Add(baseMaterial, 1, StencilOp.Zero, CompareFunction.Always, (ColorWriteMask) 0);
StencilMaterial.Remove(this.m_UnmaskMaterial);
this.m_UnmaskMaterial = material2;
this.graphic.canvasRenderer.popMaterialCount = 1;
this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
return this.m_MaskMaterial;
}
Material material3 = StencilMaterial.Add(baseMaterial, num | num - 1, StencilOp.Replace, CompareFunction.Equal, !this.m_ShowMaskGraphic ? (ColorWriteMask) 0 : ColorWriteMask.All, num - 1, num | num - 1);
StencilMaterial.Remove(this.m_MaskMaterial);
this.m_MaskMaterial = material3;
this.graphic.canvasRenderer.hasPopInstruction = true;
Material material4 = StencilMaterial.Add(baseMaterial, num - 1, StencilOp.Replace, CompareFunction.Equal, (ColorWriteMask) 0, num - 1, num | num - 1);
StencilMaterial.Remove(this.m_UnmaskMaterial);
this.m_UnmaskMaterial = material4;
this.graphic.canvasRenderer.popMaterialCount = 1;
this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
return this.m_MaskMaterial;
}
}
}