_xiaofang/xiaofang/Assets/Script/UI/PanelUI/EvacuationPanel.cs
2024-12-01 22:24:03 +08:00

141 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<ClassItem> classItemList = new List<ClassItem>();
public List<ClassMate> classMateList = new List<ClassMate>();
[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<JueseChoicePop>();
redistributeBtn.onClick.AddListener(ClearData);
submitBtn.onClick.AddListener(Submit);
StuCountInputField.onEndEdit.AddListener(CheckInput);
SetClass();
}
private void Submit()
{
}
private void ClearData()
{
jc.classItem.isSet = false;
foreach (var item in classItemList)
{
item.isSet = false;
item.setClassItem("");
}
jc.classMate.isBeSet = false;
foreach(var item in jc.classMateList)
{
item.isBeSet = false;
item.setName();
}
}
// 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;
classItemList.Add(classItem);
}
}
//Npc·ÖÅä
public void NpcDistribution()
{
}
}