2025-06-14 13:46:24 +08:00
|
|
|
|
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<string> 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ʧ<62><CAA7>");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GameObject go = Instantiate(obj) as GameObject; ;
|
|
|
|
|
|
go.transform.SetParent(itemParent, false);
|
|
|
|
|
|
int size = MapManager.Instance.AddNpcPointSize();
|
2025-07-19 12:48:11 +08:00
|
|
|
|
Vector2Int newPos = MapManager.Instance.GetCameraPos();
|
2025-06-14 13:46:24 +08:00
|
|
|
|
UINpcItem item = go.GetComponent<UINpcItem>();
|
2025-07-19 12:48:11 +08:00
|
|
|
|
item.SetItemPos(newPos);
|
2025-06-14 13:46:24 +08:00
|
|
|
|
item.itemIdx = size;
|
2025-07-19 12:48:11 +08:00
|
|
|
|
item.editCellType = MapManager.EditCellType.NpcCell;
|
|
|
|
|
|
MapManager.Instance.CreateSpecialPoint(newPos, item);
|
2025-06-14 13:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddItem(NpcConfig nc)
|
|
|
|
|
|
{
|
|
|
|
|
|
UnityEngine.Object obj = Resources.Load("Prefabs/npcItem");
|
|
|
|
|
|
if (obj == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIWindow.Instance.ShowMessage("npcItem.prefabʧ<62><CAA7>");
|
|
|
|
|
|
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<UINpcItem>();
|
|
|
|
|
|
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;
|
2025-07-18 22:28:40 +08:00
|
|
|
|
item.editCellType = MapManager.EditCellType.NpcCell;
|
|
|
|
|
|
MapManager.Instance.SetNpcPoint(item.itemIdx,nc.id,(int)nc.dir);
|
|
|
|
|
|
MapManager.Instance.CreateSpecialPoint(nc.pos, item);
|
2025-06-14 13:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SaveNpcsConfig()
|
|
|
|
|
|
{
|
|
|
|
|
|
int x, y;
|
|
|
|
|
|
NpcsConfig nc = new NpcsConfig();
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<itemParent.childCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
UINpcItem item = itemParent.GetChild(i).GetComponent<UINpcItem>();
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-16 00:15:41 +08:00
|
|
|
|
int mapId = MapManager.Instance._curOpenMapId;
|
2025-06-14 13:46:24 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|