127 lines
3.6 KiB
C#
127 lines
3.6 KiB
C#
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ʧ°Ü");
|
|
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ʧ°Ü");
|
|
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, item);
|
|
|
|
|
|
}
|
|
|
|
public void SaveJuBaoConfig()
|
|
{
|
|
//Ë¢¹Ö
|
|
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 = MapManager.Instance._curOpenMapId;
|
|
mc.SaveXML(mapId);
|
|
}
|
|
|
|
public void LoadJuBaoConfig(int mapId)
|
|
{
|
|
JuBaosConfig mc = new JuBaosConfig();
|
|
if (!mc.LoadXML(mapId))
|
|
return;
|
|
|
|
//¹ÖÎï
|
|
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);
|
|
}
|
|
}
|
|
}
|