_xiaofang/xiaofang/Assets/Script/UI/PanelUI/EvacuationPanel.cs
杨号敬 f908b4f0a6 yhj1
2024-11-30 17:43:21 +08:00

98 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EvacuationPanel : MonoBehaviour
{
public Transform personnelContent;
public Panel panel;
public GameObject personnelPrefabs;
public GameObject classPrefab;
public Transform content;
public Text topText;
[Header("学生数量")]
public InputField StuCountInputField;
public Button CountsubmitBtn;
public Sprite rsprite;
public Sprite fsprite;
public GameObject JuesechoicePop;
[Header("总按钮")]
public Button redistributeBtn;
public Button submitBtn;
// Start is called before the first frame update
void Start()
{
StuCountInputField.onEndEdit.AddListener(CheckInput);
SetClass();
}
// Update is called once per frame
void Update()
{
CheckInput(StuCountInputField.text);
}
public void SetPersonnel()
{
foreach (Transform child in personnelContent)
{
Destroy(child.gameObject);
}
foreach (var sceneEntry in panel.sceneDataDictionary)
{
GameObject item = GameObject.Instantiate<GameObject>(personnelPrefabs, personnelContent);
PersonnelItem personnelItem=item.GetComponent<PersonnelItem>();
personnelItem.sceneText.text = sceneEntry.Key;
personnelItem.personnelNum.text = sceneEntry.Value.Count.ToString();
}
}
//判断输入框的数字是否大于1
void CheckInput(string input)
{
// 尝试将输入转换为数字
if (float.TryParse(input, out float result))
{
// 判断数字是否大于1
if (result > 1)
{
CountsubmitBtn.GetComponent<Image>().sprite = rsprite;
CountsubmitBtn.onClick.AddListener(Countsubmit);
}
}
}
public void Countsubmit()
{
//按钮置灰
CountsubmitBtn.GetComponent<Image>().sprite = fsprite;
StuCountInputField.text = string.Empty;
//按配置对输入的Npc数量进行 分配
//取消监听
CountsubmitBtn.onClick.RemoveAllListeners();
}
//场景ID进行配置
public void SettopText()
{
topText.text = "以下班级需要设定班主任老师:";
topText.text = "以下楼层需要设定搜救老师:";
}
//实例化ClassItem
public void SetClass()
{
for (int i = 0; i < 10; i++)
{
GameObject item = GameObject.Instantiate<GameObject>(classPrefab, content);
ClassItem classItem = item.GetComponent<ClassItem>();
classItem.JuesechoicePop = JuesechoicePop;
}
}
}