using HxGame; using HxGame.Data; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UINpcsPanel : MonoBehaviour { [HideInInspector] public InputField curActiveInput; [HideInInspector] public List curActiveList; public Transform itemParent; public Button btnAdd; // Start is called before the first frame update void Start() { btnAdd.onClick.AddListener(AddItem); } void AddItem() { UnityEngine.Object obj = Resources.Load("Prefabs/npcItem"); if (obj == null) { UIWindow.Instance.ShowMessage("npcItem.prefabʧ°Ü"); return; } GameObject go = Instantiate(obj) as GameObject; ; go.transform.SetParent(itemParent, false); int size = MapManager.Instance.AddNpcPointSize(); UINpcItem item = go.GetComponent(); item.itemIdx = size; } public void AddItem(NpcConfig nc) { UnityEngine.Object obj = Resources.Load("Prefabs/npcItem"); if (obj == null) { UIWindow.Instance.ShowMessage("npcItem.prefabʧ°Ü"); return; } GameObject go = Instantiate(obj) as GameObject; ; go.transform.SetParent(itemParent, false); int size = MapManager.Instance.AddNpcPointSize(); MapManager.Instance.SetCurNpcPointIdx(size); UINpcItem item = go.GetComponent(); item.itemIdx = size; item.txtID.text = nc.id.ToString(); item.txtPos.text = $"{nc.pos.x},{nc.pos.y}"; item.dropDir.value = (int)nc.dir - 1; item.paths = nc.paths; MapManager.Instance.CreateSpecialPoint(nc.pos.x, nc.pos.y, MapManager.EditCellType.NpcCell); MapManager.Instance.SetCurNpcPathIdx(item.pathIdx); for (int i=0; i(); if (!item.CheckValid()) return; NpcConfig npc = new NpcConfig(); npc.id = Convert.ToInt32(item.txtID.text); string[] tmp = item.txtPos.text.Split(','); if (tmp.Length != 2) return; x = Convert.ToInt32(tmp[0]); y = Convert.ToInt32(tmp[1]); npc.pos = new Vector2Int(x, y); npc.dir = (Direction)(item.dropDir.value + 1); npc.paths = item.paths; nc.npcConfigs.Add(npc); } int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text); nc.SaveXML(mapId); } public void LoadNpcsConfig(int mapId) { NpcsConfig nc = new NpcsConfig(); if (!nc.LoadXML(mapId)) return; for (int i = 0; i < nc.npcConfigs.Count; i++) { AddItem(nc.npcConfigs[i]); } } public void RemoveAll() { int count = itemParent.childCount; for (int i = 0; i < count; i++) { DestroyImmediate(itemParent.GetChild(0).gameObject); } } }