TH1/Unity/Assets/Scripts/UI/ActionClickedEvent.cs
2025-07-17 18:26:28 +08:00

32 lines
687 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using System;
public class ActionClickedEvent : MonoBehaviour, IPointerClickHandler
{
public event Action<GameObject> OnItemClicked; // 定义事件,用来被父节点监听
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnPointerClick(PointerEventData eventData)
{
//Debug.Log($"点击了对象: {gameObject.name}");
OnItemClicked?.Invoke(gameObject);//触发事件,传回自身参数
}
}