Files
HX_MapEditor/Assets/Scripts/UI/UITeleportItem.cs

92 lines
2.7 KiB
C#
Raw Normal View History

2025-06-14 13:46:24 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
2025-07-18 22:28:40 +08:00
public class UITeleportItem : UIBaseItem
2025-06-14 13:46:24 +08:00
{
public InputField txtPos; //<2F><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
public InputField txtNextMapID; //<2F>¼<EFBFBD><C2BC><EFBFBD>ͼID
public InputField txtNextMapPos; //<2F>¼<EFBFBD><C2BC><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
public Button btnDel; //ɾ<><C9BE>
public int itemIdx;
2025-07-19 12:48:11 +08:00
protected override void Awake()
2025-06-14 13:46:24 +08:00
{
2025-07-19 12:48:11 +08:00
base.Awake();
2025-06-14 13:46:24 +08:00
AddInputNameClickEvent(txtPos);
//AddInputNameClickEvent(txtNextMapPos);
btnDel.onClick.AddListener(RemoveSelf);
2025-11-18 10:11:56 +08:00
txtNextMapID.onEndEdit.AddListener((string value) =>
{
sceneArea?.RefSAreaInfo();
});
txtNextMapPos.onEndEdit.AddListener((string value) =>
{
if (!UtilityClass.IsPosValidFormat(value))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>");
return;
}
});
2025-06-14 13:46:24 +08:00
itemIdx = 0;
}
private void AddInputNameClickEvent(InputField input) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Awake<6B>е<EFBFBD><D0B5><EFBFBD>
{
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)
{
UIWindow.Instance.uiTeleportPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
MapManager.Instance.SetCurTeleportPointIdx(itemIdx);
MapManager.Instance.SetEditCellType(MapManager.EditCellType.TeleportCell);
}
private void RemoveSelf()
{
DestroyImmediate(gameObject);
MapManager.Instance.RemoveTeleportPointSize(itemIdx);
}
2025-07-19 12:48:11 +08:00
public override void SetItemPos(Vector2Int pos)
{
base.SetItemPos(pos);
txtPos.text = pos.ToString();
}
private void OnDestroy()
{
if (sceneArea == null) return;
Destroy(sceneArea.gameObject);
}
2025-06-14 13:46:24 +08:00
public bool CheckValid()
{
if (string.IsNullOrEmpty(txtPos.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return false;
}
if (string.IsNullOrEmpty(txtNextMapID.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ͼID");
return false;
}
if (string.IsNullOrEmpty(txtNextMapPos.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>");
return false;
}
return true;
}
}