LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/ObjectComponent.cs

44 lines
1.1 KiB
C#
Raw Normal View History

2023-09-13 15:04:19 +08:00
using Mono.Event;
using Sirenix.OdinInspector;
2023-09-13 09:28:54 +08:00
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI.Extensions;
namespace UnityTest.ZXL
{
2023-09-13 15:04:19 +08:00
public class ObjectComponent : MonoBehaviour, IPointerClickHandler
2023-09-13 09:28:54 +08:00
{
/// <summary>
/// 当前物体的名字(可能存在名字对不上的情况,需要进行深度查找)
/// </summary>
public string objectName;
/// <summary>
/// 描述
/// </summary>
public string desc;
2023-09-13 20:15:22 +08:00
public bool isCanClick;
2023-09-13 09:28:54 +08:00
public void Clicked()
{
Debug.Log($"点击了{objectName}");
2023-09-13 15:04:19 +08:00
EventManager.Instance.FireNow(this, new ClickObjectEventArgs(this.gameObject));
2023-09-13 09:28:54 +08:00
}
#if UNITY_EDITOR
[Button]
void Add()
{
var component = gameObject.GetOrAddComponent<EventTrigger>();
// component.OnPointerClick();
}
#endif
public void OnPointerClick(PointerEventData eventData)
{
2023-09-13 20:15:22 +08:00
if (!isCanClick) return;
isCanClick = false;
2023-09-13 09:28:54 +08:00
Clicked();
}
}
}