using HxGame.Data; using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UIMonstersPanel_old : 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/monsterItem"); if (obj == null) { UIWindow.Instance.ShowMessage("monsterItem.prefabʧ°Ü"); return; } GameObject go = Instantiate(obj) as GameObject; ; go.transform.SetParent(itemParent, false); UIMonsterItem_old item = go.GetComponent(); item.itemIdx = itemParent.childCount; } public void AddItem(HxGame.Data.MonstersConfig.MonsterConfig monster) { UnityEngine.Object obj = Resources.Load("Prefabs/monsterItem"); if (obj == null) { UIWindow.Instance.ShowMessage("monsterItem.prefabʧ°Ü"); return; } GameObject go = Instantiate(obj) as GameObject; ; go.transform.SetParent(itemParent, false); UIMonsterItem_old item = go.GetComponent(); item.itemIdx = itemParent.childCount; item.txtID.text = monster.id.ToString(); item.dropType.value = (int)monster.createMode; item.dropPatrol.value = (int)monster.patrolMode; item.txtPos.text = $"{monster.pos.x},{monster.pos.y}"; item.txtRadius.text = monster.radius.ToString(); item.txtNum.text = monster.num.ToString(); if(monster.createMode == CreateMonsterMode.Death) item.txtTime.text = monster.delayTime.ToString(); else item.txtTime.text = monster.strTime; item.paths = monster.paths; MapManager.Instance.SetMonsterPoint(item.itemIdx,monster.radius, monster.id, monster.num); MapManager.Instance.CreateSpecialPoint(monster.pos.x, monster.pos.y, MapManager.EditCellType.MonsterArea); MapManager.Instance.SetCurMonsterPathIdx(item.pathIdx); for (int i = 0; i < item.paths.Count; i++) { string[] pos = item.paths[i].Split('_'); int x = Convert.ToInt32(pos[0]); int y = Convert.ToInt32(pos[1]); item.txtPath.text += $"[{item.paths[i].Replace('_', ',')}]"; MapManager.Instance.AddMonsterPathSize(); MapManager.Instance.CreateSpecialPoint(x, y, MapManager.EditCellType.MonsterPath); } } public void SaveMonsterConfig() { //Ë¢¹Ö int x, y; MonstersConfig mc = new MonstersConfig(); for (int i = 0; i < itemParent.childCount; i++) { UIMonsterItem_old item = itemParent.GetChild(i).GetComponent(); if (!item.CheckValid()) return; MonstersConfig.MonsterConfig monster = new HxGame.Data.MonstersConfig.MonsterConfig(); monster.id = Convert.ToInt32(item.txtID.text); monster.createMode = (CreateMonsterMode)item.dropType.value; monster.patrolMode = (PatrolMode)item.dropPatrol.value; string[] tmp = item.txtPos.text.Split(','); if (tmp.Length != 2) return; x = Convert.ToInt32(tmp[0]); y = Convert.ToInt32(tmp[1]); monster.pos = new Vector2Int(x, y); monster.radius = Convert.ToInt32(item.txtRadius.text); monster.num = Convert.ToInt32(item.txtNum.text); if(monster.createMode == CreateMonsterMode.Death) monster.delayTime = Convert.ToInt32(item.txtTime.text); else monster.strTime = item.txtTime.text; monster.paths = item.paths; mc.monsterConfigs.Add(monster); } int mapId = MapManager.Instance._curOpenMapId; mc.SaveXML(mapId); } public void LoadMonsterConfig(int mapId) { MonstersConfig mc = new MonstersConfig(); if (!mc.LoadXML(mapId)) return; //¹ÖÎï for (int i = 0; i < mc.monsterConfigs.Count; i++) { MonstersConfig.MonsterConfig monster = mc.monsterConfigs[i]; AddItem(monster); } } public void RemoveAll() { int count = itemParent.childCount; for (int i = 0; i < count; i++) { DestroyImmediate(itemParent.GetChild(0).gameObject); } } }