分管修改

This commit is contained in:
lq 2024-12-27 23:42:19 +08:00
parent 13e73b29c4
commit 61cc379bf1
3 changed files with 56 additions and 47 deletions

View File

@ -487,7 +487,7 @@ public class EvacuationPanel : Base
{ {
JueseChoicePop jueseChoicePop = jueseChoicePanel.GetComponent<JueseChoicePop>(); JueseChoicePop jueseChoicePop = jueseChoicePanel.GetComponent<JueseChoicePop>();
jueseChoicePanel.gameObject.SetActive(true); jueseChoicePanel.gameObject.SetActive(true);
jueseChoicePop.SetClass(); jueseChoicePop.SetClass(classLevel.classname.text);
//jueseChoicePanel.SetClass(); //jueseChoicePanel.SetClass();
}); });

View File

@ -461,7 +461,7 @@ MonoBehaviour:
id: 0 id: 0
name: name:
classmatename: {fileID: 5469669078877023921} classmatename: {fileID: 5469669078877023921}
classText: {fileID: 0} classText: {fileID: 646037399500158430}
s: s:
otherButton: {fileID: 0} otherButton: {fileID: 0}
button: {fileID: 5469669078140634246} button: {fileID: 5469669078140634246}

View File

@ -20,6 +20,8 @@ public class JueseChoicePop : MonoBehaviour
public List<ClassMate> classMateList = new List<ClassMate> (); public List<ClassMate> classMateList = new List<ClassMate> ();
// 存储已实例化的 GameObject 列表 // 存储已实例化的 GameObject 列表
private List<GameObject> instantiatedObjects = new List<GameObject>(); private List<GameObject> instantiatedObjects = new List<GameObject>();
// 用于记录已加载的SceneId或者DutyId
HashSet<string> loadedSceneIds = new HashSet<string>(); // 或者使用字典来记录更多信息
public string s; public string s;
public JSONReader jsonReader; public JSONReader jsonReader;
@ -40,7 +42,7 @@ public class JueseChoicePop : MonoBehaviour
} }
void CLosePop() void CLosePop()
{ {
ClearAll(); //ClearAll();
this.gameObject.SetActive(false); this.gameObject.SetActive(false);
} }
public void openPop() public void openPop()
@ -55,56 +57,63 @@ public class JueseChoicePop : MonoBehaviour
} }
//加载分管人员 //加载分管人员
public void SetClass() public void SetClass(string a)
{ {
//if (instantiatedObjects.Any(obj => obj.GetComponent<ClassMate>().id == id))
//{
// Debug.Log($"这个: {id} 已经被实例化.");
// return; // 如果已实例化,跳过
//}
//foreach (Transform child in content)
//{
// Destroy(child.gameObject);
//}
foreach(var all in panel.sceneDataDictionary) foreach(var all in panel.sceneDataDictionary)
{ {
foreach (var info in all.Value) foreach (var info in all.Value)
{ {
Debug.LogError("-------------------------"+ info.sceneId); Debug.LogError("-------------------------"+ info.sceneId);
LocationData locationData = jsonReader.GetAreaDateById(int.Parse(info.sceneId)); LocationData locationData = jsonReader.GetAreaDateById(int.Parse(info.sceneId));
if (locationData.Oversee == "-1") if (locationData.Oversee == "-1")
{ {
Debug.Log($"Skipping ID{info.sceneId}: Oversee is -1."); Debug.Log($"Skipping ID{info.sceneId}: Oversee is -1.");
continue; // 跳过 continue; // 跳过
} }
string[] overseeParts = locationData.Oversee.Split(','); string[] overseeParts = locationData.Oversee.Split(',');
string firstElement = overseeParts[0]; string firstElement = overseeParts[0];
string lastElement = overseeParts[1]; string lastElement = overseeParts[1];
if (overseeParts.Length > 0)
{
if(firstElement==info.dutyId&&lastElement=="1") if (overseeParts.Length > 0 && firstElement == info.dutyId && lastElement == "1")
{ {
Debug.LogError(loadedSceneIds.Contains(info.name));
// 如果已经加载过,跳过
if (loadedSceneIds.Contains(info.name))
{
Debug.Log($"Scene ID {info.sceneId} already loaded. Skipping.");
continue; // 如果该sceneId已经加载过就跳过
}
// 如果没有加载过,实例化预制体
GameObject item = GameObject.Instantiate(classmatePrefab, content); GameObject item = GameObject.Instantiate(classmatePrefab, content);
ClassMate classMate = item.GetComponent<ClassMate>(); ClassMate classMate = item.GetComponent<ClassMate>();
Button button = item.GetComponent<Button>(); Button button = item.GetComponent<Button>();
button.onClick.AddListener(() => button.onClick.AddListener(() =>
{ {
//SetClassMate(classMate, ); SetClassMate(classMate, a);
}); });
classMate.name = info.name; classMate.name = info.name;
classMate.classmatename.text = classMate.name; classMate.classmatename.text = classMate.name;
// classMate.id = info.dutyId; // classMate.id = info.dutyId;
instantiatedObjects.Add(item); instantiatedObjects.Add(item);
// 将当前加载的sceneId添加到集合中
loadedSceneIds.Add(info.name);
} }
} }
} }
}
// 如果没有数据,弹出提示框
if (panel.sceneDataDictionary.Count == 0) if (panel.sceneDataDictionary.Count == 0)
{ {
WarningPopPanel.OpenPanel("请先添加对应的应急人员配置"); WarningPopPanel.OpenPanel("请先添加对应的应急人员配置");
} }
} }
//点击人员后设置位置的方法 //点击人员后设置位置的方法
public void SetClassMate(ClassMate classMate, string a = "") public void SetClassMate(ClassMate classMate, string a = "")
{ {