UGUI_不规则按钮的响应区域
来源:互联网 发布:mac svn客户端 编辑:程序博客网 时间:2024/06/05 22:58
1.用Polygon Collider2D组件圈出精灵响应事件的区域。
注意 IsRaycastLocationValid 的判断区域是RectTransform的区域。如果 polygon Collider编辑出来的区域大于RectTransform ,必须调节RectTransform的区域。
例子:比如想把按钮的点击区域改成不规则的。
1.把按钮的image的RaycastTarget关闭勾选
2.在子节点创建新的gameObject挂上下面UIPolygon脚本。
3.编辑Polygon的区域即可。
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
[RequireComponent(typeof(PolygonCollider2D))]
public class UIPolygon : Image
{
private PolygonCollider2D _polygon = null;
private PolygonCollider2D polygon
{
get{
if(_polygon == null )
_polygon = GetComponent<PolygonCollider2D>();
return _polygon;
}
}
protected UIPolygon()
{
useLegacyMeshGeneration = true;
}
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
}
public override bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
{
return polygon.OverlapPoint( eventCamera.ScreenToWorldPoint(screenPoint));
}
#if UNITY_EDITOR
protected override void Reset()
{
base.Reset();
transform.localPosition = Vector3.zero;
float w = (rectTransform.sizeDelta.x *0.5f) + 0.1f;
float h = (rectTransform.sizeDelta.y*0.5f) + 0.1f;
polygon.points = new Vector2[]
{
new Vector2(-w,-h),
new Vector2(w,-h),
new Vector2(w,h),
new Vector2(-w,h)
};
}
#endif
}
#if UNITY_EDITOR
[CustomEditor(typeof(UIPolygon), true)]
public class UIPolygonInspector : Editor
{
public override void OnInspectorGUI()
{
}
}
#endif
- UGUI_不规则按钮的响应区域
- UGUI 之 不规则按钮的响应区域
- ulua--不规则按钮的响应区域
- android不规则区域的点击响应思路
- UGUI不规则相应区域的按钮
- 不规则区域响应点击事件
- Android中不规则图片按钮透明区域的点击效果
- 关于扩大按钮响应区域的方法
- UIButton 扩大按钮的响应区域
- Unity 关于Spine不规则响应区域解决方法
- UGUI实现不规则区域点击响应
- UGUI_不规则图片点击事件处理
- UGUI_不规则图片点击事件处理
- 代码增大按钮响应区域
- 不规则图片的点击响应
- Android ImageView图片透明区域不响应点击事件,不规则图片透明区域响应点击事件
- cocos2dx 不规则按钮的实现
- UGUI 不规则按钮的点击
- UGUI_UGUI事件系统简述及使用方法总结
- 实现多线程的两种方式
- Zabbix监控windows系统
- C 强制类型转换
- nginx之proxy_pass指令完全拆解
- UGUI_不规则按钮的响应区域
- 如何搭建mybatis框架
- javascript的Array.prototype.slice.call
- 二值图像的腐蚀和膨胀
- JAVASE基础(十二)
- Java Socket编程----通信是这样炼成的
- spring特性介绍
- sso单点登录--拦截器篇
- HDU-6153 A Secret (扩展KMP)