zoukankan      html  css  js  c++  java
  • unity 实战图片挖洞Mask(转载)

    转载转载

    https://www.cnblogs.com/j349900963/p/8340571.html

    截取里面俩代码,可以实现图片挖洞的需求

    注意:

    hole image 需要 将图片的透明度调整为1

    public class Hole : Mask
    {
        public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
        {
            if (!isActiveAndEnabled)
                return true;
     
            return !RectTransformUtility.RectangleContainsScreenPoint(rectTransform, sp, eventCamera);
        }
    }
    

      

    public class HoleImage : 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;
        }
    }
  • 相关阅读:
    随笔 祝我快乐
    .NET设计模式单件模式(Singleton Pattern)
    随笔 缘分
    随笔 雨季
    数据库设计中的小经验
    一个字节造成的巨大性能差异——SQL Server存储结构
    随笔 淡淡的幸福
    用LINQ还是NHibernate?
    随笔 风筝
    FreeStyle Wishes
  • 原文地址:https://www.cnblogs.com/leilei-weapon/p/10415274.html
Copyright © 2011-2022 走看看