Files
HX_MapEditor/Assets/Scripts/UI/UITriggerItem.cs
2025-07-18 22:28:40 +08:00

76 lines
2.2 KiB
C#

using HxGame.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UITriggerItem : UIBaseItem
{
public InputField txtPos; //中心点坐标
public InputField txtRadius; //半径
public Dropdown dropMode; //触发方式
public InputField txtEvent; //触发事件
public Button btnDel; //删除
public int itemIdx;
private void Awake()
{
AddInputNameClickEvent(txtPos);
btnDel.onClick.AddListener(RemoveSelf);
itemIdx = 0;
}
private void AddInputNameClickEvent(InputField input) //可以在Awake中调用
{
var eventTrigger = input.gameObject.AddComponent<EventTrigger>();
UnityAction<BaseEventData> selectEvent = OnInputFieldClicked;
EventTrigger.Entry onClick = new EventTrigger.Entry()
{
eventID = EventTriggerType.PointerClick
};
onClick.callback.AddListener(selectEvent);
eventTrigger.triggers.Add(onClick);
}
private void OnInputFieldClicked(BaseEventData data)
{
if (string.IsNullOrEmpty(txtRadius.text))
return;
UIWindow.Instance.uiTriggersPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
MapManager.Instance.SetCurTriggerCenterPoint(itemIdx, Convert.ToInt32(txtRadius.text), (TriggerMode)dropMode.value);
MapManager.Instance.SetEditCellType(MapManager.EditCellType.TriggerCell);
}
private void RemoveSelf()
{
DestroyImmediate(gameObject);
MapManager.Instance.RemoveTriggerCenterPoint(itemIdx);
}
public bool CheckValid()
{
if (string.IsNullOrEmpty(txtPos.text))
{
UIWindow.Instance.ShowMessage("请填写传送坐标");
return false;
}
if (string.IsNullOrEmpty(txtRadius.text))
{
UIWindow.Instance.ShowMessage("请填写半径");
return false;
}
if (string.IsNullOrEmpty(txtEvent.text))
{
UIWindow.Instance.ShowMessage("请填写传送下级地图坐标");
return false;
}
return true;
}
}