37 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| using UnityEngine.UI;
 | |
| using UnityEngine.Rendering;
 | |
| 
 | |
| namespace MMO
 | |
| {
 | |
|     public class MMOHoleImg : Image
 | |
|     {
 | |
|         public override Material GetModifiedMaterial(Material baseMaterial)
 | |
|         {
 | |
|             var toUse = baseMaterial;
 | |
| 
 | |
|             if (m_ShouldRecalculateStencil)
 | |
|             {
 | |
|                 var rootCanvas = MaskUtilities.FindRootSortOverrideCanvas(transform);
 | |
|                 m_StencilValue = maskable ? MaskUtilities.GetStencilDepth(transform, rootCanvas) : 0;
 | |
|                 m_ShouldRecalculateStencil = false;
 | |
|             }
 | |
| 
 | |
|             // if we have a enabled Mask component then it will
 | |
|             // generate the mask material. This is an optimisation
 | |
|             // it adds some coupling between components though :(
 | |
| 
 | |
|             Mask maskComponent = GetComponent<Mask>();
 | |
|             if (m_StencilValue > 0 && (maskComponent == null || !maskComponent.IsActive()))
 | |
|             {
 | |
|                 var maskMat = StencilMaterial.Add(toUse, (1 << m_StencilValue) - 1, StencilOp.Keep, CompareFunction.NotEqual, ColorWriteMask.All, (1 << m_StencilValue) - 1, 0);
 | |
|                 StencilMaterial.Remove(m_MaskMaterial);
 | |
|                 m_MaskMaterial = maskMat;
 | |
|                 toUse = m_MaskMaterial;
 | |
|             }
 | |
|             return toUse;
 | |
|         }
 | |
|     }
 | |
| } |