UI 이벤트 추가

This commit is contained in:
2026-01-25 23:45:33 +09:00
parent 8b013830a0
commit 698300d465
7 changed files with 61 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UI_Base : MonoBehaviour
@@ -59,4 +60,21 @@ public class UI_Base : MonoBehaviour
{
return Get<Image>(idx);
}
public static void AddUIEvent(GameObject go, Action<PointerEventData> action, Define.UIEvent type = Define.UIEvent.Click)
{
UI_EventHandler evt = Util.GetOrAddComponent<UI_EventHandler>(go);
switch (type)
{
case Define.UIEvent.Click:
evt.OnClickHandler -= action;
evt.OnClickHandler += action;
break;
case Define.UIEvent.Drag:
evt.OnDragHandler -= action;
evt.OnDragHandler += action;
break;
}
}
}