UGUI粒子裁剪

作者: 好怕怕 | 来源:发表于2019-02-28 13:30 被阅读3次
    image.png
    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    
    public class MaskPlus : Mask
    {
        Camera cam;
        protected override void Start()
        {
            base.Start();
            ResetShaderMaskClip();
        }
    
        public void ResetShaderMaskClip()
        {
            Vector3[] points = new Vector3[4];
            (transform as RectTransform).GetWorldCorners(points);
            float x;
            float y;
            float x1;
            float y1;
    
            Vector3 scPos = cam.WorldToScreenPoint(points[0]);
            x = scPos.x;
            y = scPos.y;
            x1 = scPos.x;
            y1 = scPos.y;
    
            for (int i = 0; i < points.Length; i++)
            {
                scPos = cam.WorldToScreenPoint(points[i]);
                //取最小xy
                x = scPos.x < x ? scPos.x : x;
                y = scPos.y < y ? scPos.y : y;
    
                //取最大
                x1 = scPos.x > x1 ? scPos.x : x1;
                y1 = scPos.y > y1 ? scPos.y : y1;
    
    
            }
    
    
            Vector4 normalize = new Vector4(x / Screen.width, y / (float)Screen.height, x1 / (float)Screen.width, y1 / (float)Screen.height);
    
            Shader.SetGlobalVector("_MaskClip", normalize);
    
        }
    
    
    
    
    }
    
    

    相关文章

      网友评论

        本文标题:UGUI粒子裁剪

        本文链接:https://www.haomeiwen.com/subject/staksqtx.html