248 lines
7.2 KiB
C#
248 lines
7.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
// Token: 0x02000179 RID: 377
|
|
[DisallowMultipleComponent]
|
|
[ExecuteInEditMode]
|
|
[RequireComponent(typeof(RectTransform))]
|
|
public class CustomAlphaMask : Mask
|
|
{
|
|
// Token: 0x1700014F RID: 335
|
|
// (get) Token: 0x06000D8F RID: 3471 RVA: 0x0003F938 File Offset: 0x0003EB38
|
|
// (set) Token: 0x06000D90 RID: 3472 RVA: 0x0003F940 File Offset: 0x0003EB40
|
|
public bool IsScreen { get; private set; }
|
|
|
|
// Token: 0x17000150 RID: 336
|
|
// (get) Token: 0x06000D91 RID: 3473 RVA: 0x0003F949 File Offset: 0x0003EB49
|
|
public Vector2 Tiling
|
|
{
|
|
get
|
|
{
|
|
return this.tiling;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000151 RID: 337
|
|
// (get) Token: 0x06000D92 RID: 3474 RVA: 0x0003F951 File Offset: 0x0003EB51
|
|
public Vector2 Offset
|
|
{
|
|
get
|
|
{
|
|
return this.offset;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000152 RID: 338
|
|
// (get) Token: 0x06000D93 RID: 3475 RVA: 0x0003F95C File Offset: 0x0003EB5C
|
|
public Graphic GetGraphic
|
|
{
|
|
get
|
|
{
|
|
Graphic graphic;
|
|
if ((graphic = this.maskGraphic) == null)
|
|
{
|
|
graphic = (this.maskGraphic = base.GetComponent<Graphic>());
|
|
}
|
|
return graphic;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000153 RID: 339
|
|
// (get) Token: 0x06000D94 RID: 3476 RVA: 0x0003F984 File Offset: 0x0003EB84
|
|
public RectTransform GetRectTransform
|
|
{
|
|
get
|
|
{
|
|
RectTransform rectTransform;
|
|
if ((rectTransform = this.maskRectTransform) == null)
|
|
{
|
|
rectTransform = (this.maskRectTransform = base.GetComponent<RectTransform>());
|
|
}
|
|
return rectTransform;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000D95 RID: 3477 RVA: 0x0003F9AA File Offset: 0x0003EBAA
|
|
public override bool MaskEnabled()
|
|
{
|
|
return this.IsActive() && this.GetGraphic != null;
|
|
}
|
|
|
|
// Token: 0x06000D96 RID: 3478 RVA: 0x0003F9C2 File Offset: 0x0003EBC2
|
|
protected override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
if (this.GetGraphic != null)
|
|
{
|
|
this.GetGraphic.canvasRenderer.hasPopInstruction = true;
|
|
this.GetGraphic.SetMaterialDirty();
|
|
}
|
|
this.UpdateMask();
|
|
MaskUtilities.NotifyStencilStateChanged(this);
|
|
}
|
|
|
|
// Token: 0x06000D97 RID: 3479 RVA: 0x0003FA00 File Offset: 0x0003EC00
|
|
protected override void OnDisable()
|
|
{
|
|
base.OnDisable();
|
|
if (this.GetGraphic != null)
|
|
{
|
|
this.GetGraphic.SetMaterialDirty();
|
|
this.GetGraphic.canvasRenderer.hasPopInstruction = false;
|
|
this.GetGraphic.canvasRenderer.popMaterialCount = 0;
|
|
}
|
|
StencilMaterial.Remove(this.stencilMaskMaterial);
|
|
this.stencilMaskMaterial = null;
|
|
StencilMaterial.Remove(this.stencilUnmaskMaterial);
|
|
this.stencilUnmaskMaterial = null;
|
|
this.UpdateMask();
|
|
MaskUtilities.NotifyStencilStateChanged(this);
|
|
}
|
|
|
|
// Token: 0x06000D98 RID: 3480 RVA: 0x00003598 File Offset: 0x00002798
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000D99 RID: 3481 RVA: 0x0003FA7E File Offset: 0x0003EC7E
|
|
private void LateUpdate()
|
|
{
|
|
this.UpdateMask();
|
|
}
|
|
|
|
// Token: 0x06000D9A RID: 3482 RVA: 0x0003FA88 File Offset: 0x0003EC88
|
|
private void OnRenderObject()
|
|
{
|
|
RectTransform component = base.GetComponent<RectTransform>();
|
|
Vector3 vector = base.transform.lossyScale;
|
|
if (component != null)
|
|
{
|
|
vector = Vector3.Scale(vector, component.rect.size);
|
|
}
|
|
vector.z = 0.1f;
|
|
Vector3 vector2;
|
|
vector2..ctor(1f, 1f, 1f);
|
|
vector2.x = 1f / vector2.x;
|
|
vector2.y = 1f / vector2.y;
|
|
Vector3 vector3 = Vector3.Scale(vector, vector2);
|
|
Matrix4x4 matrix4x = Matrix4x4.TRS(base.transform.position, base.transform.rotation, vector3);
|
|
Vector3 vector4 = base.transform.rotation * -vector * 0.5f;
|
|
Vector3 vector5 = Vector3.Scale(new Vector3(0f, 0f, 0f), -vector3);
|
|
Matrix4x4 matrix4x2 = Matrix4x4.TRS(vector4 + vector5, Quaternion.identity, Vector3.one);
|
|
this.maskQuadMatrix = matrix4x2 * matrix4x;
|
|
this.UpdateMask();
|
|
}
|
|
|
|
// Token: 0x06000D9B RID: 3483 RVA: 0x0003FBA8 File Offset: 0x0003EDA8
|
|
private void OnDrawGizmos()
|
|
{
|
|
Gizmos.matrix = this.maskQuadMatrix;
|
|
Vector3 one = Vector3.one;
|
|
one.z = 0f;
|
|
Gizmos.color = new Color(0f, 0f, 0f, 0f);
|
|
Gizmos.DrawCube(new Vector3(0.5f, 0.5f, 0.5f), one);
|
|
}
|
|
|
|
// Token: 0x06000D9C RID: 3484 RVA: 0x0003FC0C File Offset: 0x0003EE0C
|
|
public override Material GetModifiedMaterial(Material baseMaterial)
|
|
{
|
|
if (!this.MaskEnabled())
|
|
{
|
|
return baseMaterial;
|
|
}
|
|
int stencilDepth = MaskUtilities.GetStencilDepth(base.transform, MaskUtilities.FindRootSortOverrideCanvas(base.transform));
|
|
if (stencilDepth >= 8)
|
|
{
|
|
return baseMaterial;
|
|
}
|
|
int num = 1 << stencilDepth;
|
|
if (num == 1)
|
|
{
|
|
Material material = StencilMaterial.Add(baseMaterial, 1, 2, 8, 0);
|
|
StencilMaterial.Remove(this.stencilMaskMaterial);
|
|
this.stencilMaskMaterial = material;
|
|
Material material2 = StencilMaterial.Add(baseMaterial, 1, 1, 8, 0);
|
|
StencilMaterial.Remove(this.stencilUnmaskMaterial);
|
|
this.stencilUnmaskMaterial = material2;
|
|
this.GetGraphic.canvasRenderer.popMaterialCount = 1;
|
|
this.GetGraphic.canvasRenderer.SetPopMaterial(this.stencilUnmaskMaterial, 0);
|
|
}
|
|
else
|
|
{
|
|
Material material3 = StencilMaterial.Add(baseMaterial, num | (num - 1), 2, 3, 0, num - 1, num | (num - 1));
|
|
StencilMaterial.Remove(this.stencilMaskMaterial);
|
|
this.stencilMaskMaterial = material3;
|
|
this.GetGraphic.canvasRenderer.hasPopInstruction = true;
|
|
Material material4 = StencilMaterial.Add(baseMaterial, num - 1, 2, 3, 0, num - 1, num | (num - 1));
|
|
StencilMaterial.Remove(this.stencilUnmaskMaterial);
|
|
this.stencilUnmaskMaterial = material4;
|
|
this.GetGraphic.canvasRenderer.popMaterialCount = 1;
|
|
this.GetGraphic.canvasRenderer.SetPopMaterial(this.stencilUnmaskMaterial, 0);
|
|
}
|
|
return this.stencilMaskMaterial;
|
|
}
|
|
|
|
// Token: 0x06000D9D RID: 3485 RVA: 0x0003FD48 File Offset: 0x0003EF48
|
|
private void UpdateMask()
|
|
{
|
|
if (this.GetGraphic == null)
|
|
{
|
|
return;
|
|
}
|
|
this.maskMatrix = base.transform.worldToLocalMatrix;
|
|
Vector3 vector = this.GetRectTransform.rect.size;
|
|
vector.z = 1f;
|
|
vector = Vector3.Scale(vector, base.transform.lossyScale);
|
|
this.maskMatrix.SetTRS(base.transform.position, base.transform.rotation, vector);
|
|
this.maskMatrix = Matrix4x4.Inverse(this.maskMatrix);
|
|
if (this.maskMatrix != this.prevMatrix)
|
|
{
|
|
Matrix4x4 matrix4x = Matrix4x4.identity;
|
|
Canvas canvas = this.GetGraphic.canvas;
|
|
this.IsScreen = canvas != null && (canvas.renderMode == null || (canvas.renderMode == 1 && canvas.worldCamera == null));
|
|
if (this.IsScreen)
|
|
{
|
|
matrix4x = Matrix4x4.TRS(canvas.GetComponent<RectTransform>().rect.size / 2f * canvas.scaleFactor, Quaternion.identity, Vector3.one * canvas.scaleFactor);
|
|
this.maskMatrix *= matrix4x;
|
|
}
|
|
MaskUtilities.NotifyStencilStateChanged(this);
|
|
}
|
|
this.prevMatrix = this.maskMatrix;
|
|
}
|
|
|
|
// Token: 0x04000A64 RID: 2660
|
|
[SerializeField]
|
|
private Vector2 tiling = new Vector2(1f, 1f);
|
|
|
|
// Token: 0x04000A65 RID: 2661
|
|
[SerializeField]
|
|
private Vector2 offset = new Vector2(0f, 0f);
|
|
|
|
// Token: 0x04000A66 RID: 2662
|
|
[NonSerialized]
|
|
private Material stencilMaskMaterial;
|
|
|
|
// Token: 0x04000A67 RID: 2663
|
|
[NonSerialized]
|
|
private Material stencilUnmaskMaterial;
|
|
|
|
// Token: 0x04000A68 RID: 2664
|
|
[NonSerialized]
|
|
public Matrix4x4 maskMatrix = Matrix4x4.identity;
|
|
|
|
// Token: 0x04000A69 RID: 2665
|
|
[NonSerialized]
|
|
private RectTransform maskRectTransform;
|
|
|
|
// Token: 0x04000A6A RID: 2666
|
|
[NonSerialized]
|
|
private Graphic maskGraphic;
|
|
|
|
// Token: 0x04000A6B RID: 2667
|
|
private Matrix4x4 maskQuadMatrix = Matrix4x4.identity;
|
|
|
|
// Token: 0x04000A6D RID: 2669
|
|
private Matrix4x4 prevMatrix = Matrix4x4.identity;
|
|
}
|