forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMask.cs
More file actions
179 lines (163 loc) · 4.78 KB
/
Mask.cs
File metadata and controls
179 lines (163 loc) · 4.78 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
using System;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.Serialization;
namespace UnityEngine.UI
{
[AddComponentMenu("UI/Mask", 13), DisallowMultipleComponent, ExecuteInEditMode, RequireComponent(typeof(RectTransform))]
public class Mask : UIBehaviour, ICanvasRaycastFilter, IMaterialModifier
{
[NonSerialized]
private RectTransform m_RectTransform;
[FormerlySerializedAs("m_ShowGraphic"), SerializeField]
private bool m_ShowMaskGraphic = true;
[NonSerialized]
private Graphic m_Graphic;
[NonSerialized]
private Material m_MaskMaterial;
[NonSerialized]
private Material m_UnmaskMaterial;
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;
}
}
public bool showMaskGraphic
{
get
{
return this.m_ShowMaskGraphic;
}
set
{
if (this.m_ShowMaskGraphic != value)
{
this.m_ShowMaskGraphic = value;
if (this.graphic != null)
{
this.graphic.SetMaterialDirty();
}
}
}
}
public Graphic graphic
{
get
{
Graphic arg_1D_0;
if ((arg_1D_0 = this.m_Graphic) == null)
{
arg_1D_0 = (this.m_Graphic = base.GetComponent<Graphic>());
}
return arg_1D_0;
}
}
protected Mask()
{
}
public virtual bool MaskEnabled()
{
return this.IsActive() && this.graphic != null;
}
[Obsolete("Not used anymore.")]
public virtual void OnSiblingGraphicEnabledDisabled()
{
}
protected override void OnEnable()
{
base.OnEnable();
if (this.graphic != null)
{
this.graphic.canvasRenderer.hasPopInstruction = true;
this.graphic.SetMaterialDirty();
}
MaskUtilities.NotifyStencilStateChanged(this);
}
protected override void OnDisable()
{
base.OnDisable();
if (this.graphic != null)
{
this.graphic.SetMaterialDirty();
this.graphic.canvasRenderer.hasPopInstruction = false;
this.graphic.canvasRenderer.popMaterialCount = 0;
}
StencilMaterial.Remove(this.m_MaskMaterial);
this.m_MaskMaterial = null;
StencilMaterial.Remove(this.m_UnmaskMaterial);
this.m_UnmaskMaterial = null;
MaskUtilities.NotifyStencilStateChanged(this);
}
protected override void OnValidate()
{
base.OnValidate();
if (this.IsActive())
{
if (this.graphic != null)
{
this.graphic.SetMaterialDirty();
}
MaskUtilities.NotifyStencilStateChanged(this);
}
}
public virtual bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
return !base.isActiveAndEnabled || RectTransformUtility.RectangleContainsScreenPoint(this.rectTransform, sp, eventCamera);
}
public virtual Material GetModifiedMaterial(Material baseMaterial)
{
Material result;
if (!this.MaskEnabled())
{
result = baseMaterial;
}
else
{
Transform stopAfter = MaskUtilities.FindRootSortOverrideCanvas(base.transform);
int stencilDepth = MaskUtilities.GetStencilDepth(base.transform, stopAfter);
if (stencilDepth >= 8)
{
Debug.LogError("Attempting to use a stencil mask with depth > 8", base.gameObject);
result = baseMaterial;
}
else
{
int num = 1 << stencilDepth;
if (num == 1)
{
Material maskMaterial = StencilMaterial.Add(baseMaterial, 1, StencilOp.Replace, CompareFunction.Always, (!this.m_ShowMaskGraphic) ? ((ColorWriteMask)0) : ColorWriteMask.All);
StencilMaterial.Remove(this.m_MaskMaterial);
this.m_MaskMaterial = maskMaterial;
Material unmaskMaterial = StencilMaterial.Add(baseMaterial, 1, StencilOp.Zero, CompareFunction.Always, (ColorWriteMask)0);
StencilMaterial.Remove(this.m_UnmaskMaterial);
this.m_UnmaskMaterial = unmaskMaterial;
this.graphic.canvasRenderer.popMaterialCount = 1;
this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
result = this.m_MaskMaterial;
}
else
{
Material maskMaterial2 = 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 = maskMaterial2;
this.graphic.canvasRenderer.hasPopInstruction = true;
Material unmaskMaterial2 = StencilMaterial.Add(baseMaterial, num - 1, StencilOp.Replace, CompareFunction.Equal, (ColorWriteMask)0, num - 1, num | num - 1);
StencilMaterial.Remove(this.m_UnmaskMaterial);
this.m_UnmaskMaterial = unmaskMaterial2;
this.graphic.canvasRenderer.popMaterialCount = 1;
this.graphic.canvasRenderer.SetPopMaterial(this.m_UnmaskMaterial, 0);
result = this.m_MaskMaterial;
}
}
}
return result;
}
}
}