第一次提交
This commit is contained in:
123
Assets/Scripts/UI/UIFuBensPanel.cs
Normal file
123
Assets/Scripts/UI/UIFuBensPanel.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using HxGame.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIFuBensPanel : 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/fubenItem");
|
||||
if (obj == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("fubenItem.prefabʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = Instantiate(obj) as GameObject; ;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
UIFuBenItem item = go.GetComponent<UIFuBenItem>();
|
||||
item.itemIdx = itemParent.childCount;
|
||||
}
|
||||
|
||||
public void AddItem(FuBenConfig monster)
|
||||
{
|
||||
UnityEngine.Object obj = Resources.Load("Prefabs/fubenItem");
|
||||
if (obj == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("monsterItem.prefabʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = Instantiate(obj) as GameObject; ;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
UIFuBenItem item = go.GetComponent<UIFuBenItem>();
|
||||
|
||||
item.itemIdx = itemParent.childCount;
|
||||
item.txtOrder.text = monster.order.ToString();
|
||||
item.txtID.text = monster.monsterId.ToString();
|
||||
item.txtPos.text = $"{monster.pos.x},{monster.pos.y}";
|
||||
item.txtRadius.text = monster.radius.ToString();
|
||||
item.txtNum.text = monster.num.ToString();
|
||||
item.txtTime.text = monster.delayTime.ToString();
|
||||
|
||||
MapManager.Instance.SetCurFuBenCenterPoint(monster.order, monster.radius, monster.monsterId, monster.num);
|
||||
MapManager.Instance.CreateSpecialPoint(monster.pos.x, monster.pos.y, MapManager.EditCellType.FuBenArea);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SaveFuBenConfig()
|
||||
{
|
||||
//ˢ<><CBA2>
|
||||
int x, y;
|
||||
FuBensConfig mc = new FuBensConfig();
|
||||
|
||||
for (int i = 0; i < itemParent.childCount; i++)
|
||||
{
|
||||
UIFuBenItem item = itemParent.GetChild(i).GetComponent<UIFuBenItem>();
|
||||
if (!item.CheckValid())
|
||||
return;
|
||||
|
||||
FuBenConfig monster = new FuBenConfig();
|
||||
monster.order = Convert.ToInt32(item.txtOrder.text);
|
||||
monster.monsterId = 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]);
|
||||
monster.pos = new Vector2Int(x, y);
|
||||
monster.radius = Convert.ToInt32(item.txtRadius.text);
|
||||
monster.num = Convert.ToInt32(item.txtNum.text);
|
||||
|
||||
monster.delayTime = Convert.ToInt32(item.txtTime.text);
|
||||
|
||||
mc.fubenConfigs.Add(monster);
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
mc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
public void LoadFuBenConfig(int mapId)
|
||||
{
|
||||
FuBensConfig mc = new FuBensConfig();
|
||||
if (!mc.LoadXML(mapId))
|
||||
return;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
for (int i = 0; i < mc.fubenConfigs.Count; i++)
|
||||
{
|
||||
FuBenConfig monster = mc.fubenConfigs[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