第一次提交
This commit is contained in:
142
Assets/Scripts/UI/UIMonstersPanel_old.cs
Normal file
142
Assets/Scripts/UI/UIMonstersPanel_old.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
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<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/monsterItem");
|
||||
if (obj == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("monsterItem.prefabʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = Instantiate(obj) as GameObject; ;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
UIMonsterItem_old item = go.GetComponent<UIMonsterItem_old>();
|
||||
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ʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = Instantiate(obj) as GameObject; ;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
UIMonsterItem_old item = go.GetComponent<UIMonsterItem_old>();
|
||||
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()
|
||||
{
|
||||
//ˢ<><CBA2>
|
||||
int x, y;
|
||||
MonstersConfig mc = new MonstersConfig();
|
||||
|
||||
for (int i = 0; i < itemParent.childCount; i++)
|
||||
{
|
||||
UIMonsterItem_old item = itemParent.GetChild(i).GetComponent<UIMonsterItem_old>();
|
||||
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 = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
mc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
public void LoadMonsterConfig(int mapId)
|
||||
{
|
||||
MonstersConfig mc = new MonstersConfig();
|
||||
if (!mc.LoadXML(mapId))
|
||||
return;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user