using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using UnityEngine.Rendering;
|
|
using System;
|
|
using UnityEngine.Serialization;
|
|
|
|
public class EffectMask : Mask {
|
|
|
|
[NonSerialized]
|
|
private Material c_MaskMaterial;
|
|
|
|
[NonSerialized]
|
|
private Material c_UnmaskMaterial;
|
|
|
|
protected override void OnDisable()
|
|
{
|
|
// we call base OnDisable first here
|
|
// as we need to have the IsActive return the
|
|
// correct value when we notify the children
|
|
// that the mask state has changed.
|
|
base.OnDisable();
|
|
if (graphic != null)
|
|
{
|
|
graphic.SetMaterialDirty();
|
|
graphic.canvasRenderer.hasPopInstruction = false;
|
|
graphic.canvasRenderer.popMaterialCount = 0;
|
|
}
|
|
|
|
StencilMaterial.Remove(c_MaskMaterial);
|
|
c_MaskMaterial = null;
|
|
StencilMaterial.Remove(c_UnmaskMaterial);
|
|
c_UnmaskMaterial = null;
|
|
|
|
MaskUtilities.NotifyStencilStateChanged(this);
|
|
}
|
|
|
|
public override Material GetModifiedMaterial(Material baseMaterial)
|
|
{
|
|
if (!MaskEnabled())
|
|
return baseMaterial;
|
|
|
|
var maskMaterial = StencilMaterial.Add(baseMaterial, 1, StencilOp.Replace, CompareFunction.Always, showMaskGraphic ? ColorWriteMask.All : 0);
|
|
StencilMaterial.Remove(c_MaskMaterial);
|
|
c_MaskMaterial = maskMaterial;
|
|
|
|
return c_MaskMaterial;
|
|
}
|
|
}
|