第一次提交
This commit is contained in:
126
Assets/Scripts/UI/UIJuBaoPanel.cs
Normal file
126
Assets/Scripts/UI/UIJuBaoPanel.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using HxGame.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIJuBaoPanel : 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/jubaoItem");
|
||||
if (obj == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("jubaoItem.prefabʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = Instantiate(obj) as GameObject; ;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
UIJuBaoItem item = go.GetComponent<UIJuBaoItem>();
|
||||
item.itemIdx = itemParent.childCount;
|
||||
}
|
||||
|
||||
public void AddItem(JuBaoConfig jubao)
|
||||
{
|
||||
UnityEngine.Object obj = Resources.Load("Prefabs/jubaoItem");
|
||||
if (obj == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("jubaoItem.prefabʧ<62><CAA7>");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = Instantiate(obj) as GameObject; ;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
UIJuBaoItem item = go.GetComponent<UIJuBaoItem>();
|
||||
item.itemIdx = itemParent.childCount;
|
||||
item.txtID.text = jubao.id.ToString();
|
||||
item.txtKillCount.text = jubao.killCount.ToString();
|
||||
item.txtInterval.text = jubao.interval.ToString();
|
||||
item.txtCurCount.text = jubao.curCount.ToString();
|
||||
item.txtRefreshCount.text = jubao.refreshCount.ToString();
|
||||
item.txtPos.text = $"{jubao.pos.x},{jubao.pos.y}";
|
||||
item.txtRadius.text = jubao.radius.ToString();
|
||||
|
||||
|
||||
MapManager.Instance.SetCurJuBaoCenterPoint(item.itemIdx, jubao.radius, jubao.id);
|
||||
MapManager.Instance.CreateSpecialPoint(jubao.pos.x, jubao.pos.y, MapManager.EditCellType.JuBaoArea);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SaveJuBaoConfig()
|
||||
{
|
||||
//ˢ<><CBA2>
|
||||
int x, y;
|
||||
JuBaosConfig mc = new JuBaosConfig();
|
||||
|
||||
for (int i = 0; i < itemParent.childCount; i++)
|
||||
{
|
||||
UIJuBaoItem item = itemParent.GetChild(i).GetComponent<UIJuBaoItem>();
|
||||
if (!item.CheckValid())
|
||||
return;
|
||||
|
||||
JuBaoConfig jubao = new JuBaoConfig();
|
||||
jubao.id = Convert.ToInt32(item.txtID.text);
|
||||
|
||||
jubao.killCount = Convert.ToInt32(item.txtKillCount.text);
|
||||
jubao.interval = Convert.ToInt32(item.txtInterval.text);
|
||||
jubao.curCount = item.txtCurCount.text;
|
||||
jubao.refreshCount = item.txtRefreshCount.text;
|
||||
|
||||
string[] tmp = item.txtPos.text.Split(',');
|
||||
if (tmp.Length != 2)
|
||||
return;
|
||||
|
||||
x = Convert.ToInt32(tmp[0]);
|
||||
y = Convert.ToInt32(tmp[1]);
|
||||
jubao.pos = new Vector2Int(x, y);
|
||||
jubao.radius = Convert.ToInt32(item.txtRadius.text);
|
||||
|
||||
|
||||
mc.jubaoConfigs.Add(jubao);
|
||||
}
|
||||
|
||||
int mapId = Convert.ToInt32(UIWindow.Instance.uiCreateMap.txtMapID.text);
|
||||
mc.SaveXML(mapId);
|
||||
}
|
||||
|
||||
public void LoadJuBaoConfig(int mapId)
|
||||
{
|
||||
JuBaosConfig mc = new JuBaosConfig();
|
||||
if (!mc.LoadXML(mapId))
|
||||
return;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
for (int i = 0; i < mc.jubaoConfigs.Count; i++)
|
||||
{
|
||||
JuBaoConfig jubao = mc.jubaoConfigs[i];
|
||||
AddItem(jubao);
|
||||
}
|
||||
}
|
||||
|
||||
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