using System; 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; public List classItemList = new List(); [Header("学生数量")] public InputField StuCountInputField; public Button CountsubmitBtn; public Sprite rsprite; public Sprite fsprite; public GameObject JuesechoicePop; public JueseChoicePop jc = new JueseChoicePop(); [Header("总按钮")] public Button redistributeBtn; public Button submitBtn; [Header("Npc数量")] public int npcNum; // Start is called before the first frame update void Start() { jc = JuesechoicePop.GetComponent(); redistributeBtn.onClick.AddListener(ClearData); submitBtn.onClick.AddListener(Submit); StuCountInputField.onEndEdit.AddListener(CheckInput); SetClass(); } private void Submit() { } private void ClearData() { foreach(var item in classItemList) { item.isSet = false; item.setClassItem(""); } } // 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(personnelPrefabs, personnelContent); PersonnelItem personnelItem=item.GetComponent(); 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().sprite = rsprite; CountsubmitBtn.onClick.AddListener(Countsubmit); } } } public void Countsubmit() { //按钮置灰 CountsubmitBtn.GetComponent().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(classPrefab, content); ClassItem classItem = item.GetComponent(); classItem.JuesechoicePop = JuesechoicePop; classItemList.Add(classItem); } } //Npc分配 public void NpcDistribution() { } }