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

90 lines
2.6 KiB
C#
Raw Normal View History

2025-06-14 13:46:24 +08:00
using HxGame;
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 UINpcItem : UIBaseItem
2025-06-14 13:46:24 +08:00
{
public InputField txtPos; //NPC<50><43><EFBFBD><EFBFBD>
public InputField txtID; //NPCID
public Dropdown dropDir; //Npc<70><63><EFBFBD><EFBFBD>
public InputField txtPath; //NPC·<43><C2B7>
public InputField txtName; //NPC<50><43><EFBFBD><EFBFBD>
public Button btnDel; //ɾ<><C9BE>
public List<string> paths;
public int itemIdx;
public int pathIdx;
// Start is called before the first frame update
void Awake()
{
AddInputNameClickEvent(txtPos);
AddInputNameClickEvent(txtPath, true);
btnDel.onClick.AddListener(RemoveSelf);
itemIdx = 0;
paths = new List<string>();
}
private void AddInputNameClickEvent(InputField input, bool isPath = false) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Awake<6B>е<EFBFBD><D0B5><EFBFBD>
{
var eventTrigger = input.gameObject.AddComponent<EventTrigger>();
UnityAction<BaseEventData> selectEvent = null;
if (isPath)
selectEvent = OnPathInputFieldClicked;
else
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.uiNpcsPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
MapManager.Instance.SetCurNpcPointIdx(itemIdx);
MapManager.Instance.SetEditCellType(MapManager.EditCellType.NpcCell);
}
private void OnPathInputFieldClicked(BaseEventData data)
{
UIWindow.Instance.uiNpcsPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
UIWindow.Instance.uiNpcsPanel.curActiveList = paths;
MapManager.Instance.SetEditCellType(MapManager.EditCellType.NpcPath);
}
2025-07-18 22:28:40 +08:00
public override void SetItemPos(Vector2Int pos)
{
base.SetItemPos(pos);
txtPos.text = pos.ToString();
}
2025-06-14 13:46:24 +08:00
private void RemoveSelf()
{
DestroyImmediate(gameObject);
}
public bool CheckValid()
{
if (string.IsNullOrEmpty(txtID.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>дNpcID");
return false;
}
if (string.IsNullOrEmpty(txtPos.text))
{
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>дNpc<70><63><EFBFBD><EFBFBD>");
return false;
}
return true;
}
}