Unity像素抠图多边形区域

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
/// 
/// 不规则区域Image响应
/// 
[RequireComponent(typeof(RectTransform))]
[RequireComponent(typeof(Image))]
public class IrregularRegionResponse : MonoBehaviour
{
    [Tooltip("设定Sprite响应的Alpha阈值")]
    [Range(0, 0.5f)]
    public float alpahThreshold = 0.5f;

    private void Awake()
    {
        Image image = this.GetComponent();
        if (image != null)
        {
            image.alphaHitTestMinimumThreshold = alpahThreshold;
        }
    }
}

注:此方法使用的是判断图片透明度,需要读取图片,所以需在图片属性中Advanced->Read/Write Enabled  打勾

Unity像素抠图多边形区域_第1张图片

你可能感兴趣的:(Unity像素抠图多边形区域)