日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UGUI_不规则按钮的响应区域

發布時間:2024/9/30 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UGUI_不规则按钮的响应区域 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.Polygon Collider2D組件圈出精靈響應事件的區域。

?

注意?IsRaycastLocationValid 的判斷區域是RectTransform的區域。 如果 polygon Collider編輯出來的區域大于RectTransform 必須調節RectTransform的區域。

例子:比如想把按鈕的點擊區域改成不規則的。

1.把按鈕的imageRaycastTarget關閉勾選

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_不规则按钮的响应区域的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。