147 lines
4.9 KiB
C#
147 lines
4.9 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Unity.VisualScripting;
|
||
using Unity.VisualScripting.Antlr3.Runtime;
|
||
using UnityEngine;
|
||
using UnityEngine.Assertions.Must;
|
||
using UnityEngine.Networking.Types;
|
||
using UnityEngine.UI;
|
||
|
||
public class JueseChoicePop : MonoBehaviour
|
||
{
|
||
public ClassMate classMate;
|
||
public ClassItem classItem;
|
||
|
||
public Button CloseBtn;
|
||
public Button Surebtn;
|
||
public GameObject classmatePrefab;
|
||
public Transform content;
|
||
|
||
public List<ClassMate> classMateList = new List<ClassMate>();
|
||
// 存储已实例化的 GameObject 列表
|
||
private List<GameObject> instantiatedObjects = new List<GameObject>();
|
||
// 用于记录已加载的SceneId或者DutyId
|
||
HashSet<string> loadedplayername = new HashSet<string>(); // 或者使用字典来记录更多信息
|
||
HashSet<string> loadedlevel = new HashSet<string>(); // 或者使用字典来记录更多信息
|
||
|
||
public string s;
|
||
public JSONReader jsonReader;
|
||
public Panel panel;
|
||
public WarningPopPanel WarningPopPanel;
|
||
//Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
this.gameObject.SetActive(false);
|
||
CloseBtn.onClick.AddListener(CLosePop);
|
||
Surebtn.onClick.AddListener(CLosePop);
|
||
//Surebtn.onClick.AddListener(SetFenguan);
|
||
//SetClass();
|
||
}
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
void CLosePop()
|
||
{
|
||
//ClearAll();
|
||
this.gameObject.SetActive(false);
|
||
}
|
||
public void openPop()
|
||
{
|
||
this.gameObject.SetActive(true);
|
||
}
|
||
void SetFenguan()
|
||
{
|
||
//设置此区分的分管人员为用户选中的角色,并刷新界面信息
|
||
classItem.isSet = true;
|
||
//classItem.setClassItem();
|
||
}
|
||
|
||
//加载分管人员
|
||
public void SetClass(string a)
|
||
{
|
||
Debug.LogError("xxxxxxxxxxxxxxxxxxxxxxxxxx" + a);
|
||
foreach (var all in panel.sceneDataDictionary)
|
||
{
|
||
foreach (var info in all.Value)
|
||
{
|
||
Debug.LogError("-------------------------" + info.sceneId);
|
||
LocationData locationData = jsonReader.GetAreaDateById(int.Parse(info.sceneId));
|
||
|
||
if (locationData.Oversee == "-1")
|
||
{
|
||
Debug.Log($"Skipping ID{info.sceneId}: Oversee is -1.");
|
||
continue; // 跳过
|
||
}
|
||
string[] overseeParts = locationData.Oversee.Split(',');
|
||
string firstElement = overseeParts[0];
|
||
string lastElement = overseeParts[1];
|
||
|
||
if (overseeParts.Length > 0 && firstElement == info.dutyId && lastElement == "1")
|
||
{
|
||
Debug.LogError(loadedplayername.Contains(info.name));
|
||
// 如果已经加载过,跳过
|
||
if (loadedplayername.Contains(info.name))
|
||
{
|
||
Debug.Log($"Scene ID {info.sceneId} already loaded. Skipping.");
|
||
continue; // 如果该sceneId已经加载过,就跳过
|
||
}
|
||
else
|
||
{
|
||
// 如果没有加载过,实例化预制体
|
||
GameObject item = GameObject.Instantiate(classmatePrefab, content);
|
||
ClassMate classMate = item.GetComponent<ClassMate>();
|
||
Button button = item.GetComponent<Button>();
|
||
string test = a;
|
||
button.onClick.AddListener(() =>
|
||
{
|
||
Debug.LogError("zzzzzzzzzzzzzzzzzzzzzzzzzz" + test);
|
||
SetClassMate(classMate, test);
|
||
});
|
||
classMate.name = info.name;
|
||
classMate.classmatename.text = classMate.name;
|
||
// classMate.id = info.dutyId;
|
||
instantiatedObjects.Add(item);
|
||
// 将当前加载的玩家名添加到集合中
|
||
loadedplayername.Add(info.name);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// 如果没有数据,弹出提示框
|
||
if (panel.sceneDataDictionary.Count == 0)
|
||
{
|
||
WarningPopPanel.OpenPanel("请先添加对应的应急人员配置");
|
||
}
|
||
}
|
||
|
||
//点击人员后设置位置的方法
|
||
public void SetClassMate(ClassMate classMate, string a)
|
||
{
|
||
foreach (Transform child in content)
|
||
{
|
||
ClassMate find = child.transform.GetComponent<ClassMate>();
|
||
Debug.LogError("????????????????????????" + find.classText.text);
|
||
Debug.LogError("---------------------------" + a);
|
||
if (find.classText.text == a)
|
||
{
|
||
find.classText.text = "";
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
this.classMate = classMate;
|
||
this.classMate.classText.text = a;
|
||
classMate.isBeSet = false;
|
||
loadedlevel.Add(this.classMate.classText.text);
|
||
}
|
||
|
||
public void SetClassItem(ClassItem classItem)
|
||
{
|
||
this.classItem = classItem;
|
||
}
|
||
}
|