unity ui button ugui 按钮如何设置点击区域为圆形?【整理转载】

用ugui,重写Image类
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;


public class TestImageCustomCollideerRect : Image
{
private CircleCollider2D collider2d;
void Start()
{
collider2d = GetComponent();
}
public override bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)

{
bool isRay = base.IsRaycastLocationValid(screenPoint, eventCamera);
if (isRay && (collider2d != null))
{
bool isTrig = collider2d.OverlapPoint(screenPoint);
return isTrig;
}
return isRay;
}
}



直接把这个代码替代ugui的button按钮上的image脚本,然后再给这个按钮加一个Circle Collider2D就行了,Circle Collider2D的区域就是点击的区域。

你可能感兴趣的:(unity ui button ugui 按钮如何设置点击区域为圆形?【整理转载】)