using Newtonsoft.Json.Schema; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DistributionPanel : MonoBehaviour { public GameObject personnelLable; public Transform personnelContent; public Panel panel; public SelectScenePanel selectScenePanel; public JSONReader jsonReader; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void OnClickPeopleWindows() { foreach(Transform child in personnelContent) { Destroy(child.gameObject); } } public void CreateAllLable() { foreach (Transform child in personnelContent) { Destroy(child.gameObject); } //CreateFirstLable(); foreach (var sceneEntry in panel.sceneDataDictionary) { GameObject managerPanelInstance = Instantiate(personnelLable, personnelContent); PersonnelPanel scenetext = managerPanelInstance.GetComponent(); scenetext.personelPanelText.text = sceneEntry.Key; scenetext.personelNumText.text = sceneEntry.Value.Count.ToString(); scenetext.CreatePeopleItem(sceneEntry.Value); foreach(var scene in sceneEntry.Value) { string a=CheckMissingRoles(scene.sceneId); scenetext.lockText.text = a; if(a==null) { scenetext.lockBg.SetActive(false); } else { scenetext.lockText.transform.SetParent(scenetext.lockBg.transform); scenetext.lockBg.SetActive(true); } } } } public void CreateFirstLable() { GameObject fistLable = Instantiate(personnelLable, personnelContent); PersonnelInfo personnelItem = fistLable.GetComponent(); } public string CheckMissingRoles(string sceneID) { List info = null; // 遍历字典中的每一个条目 foreach (var entry in panel.sceneDataDictionary) { // 遍历每个 List,查找是否包含 sceneID foreach (var selectedInfo in entry.Value) { if (selectedInfo.sceneId == sceneID) // 如果找到匹配的 sceneId { // 找到对应的 List info = entry.Value; break; } } // 如果找到了对应的 sceneId,跳出循环 if (info != null) { break; } } if (info != null) { string roleLimit = jsonReader.GetAreaDateById(int.Parse(sceneID)).RoleLimit; string[] sceneLimits = roleLimit.Split('|'); // 存储已选择的职业ID集合 HashSet selectedDutyIds = new HashSet(); // 遍历所有已选择的角色,提取职业ID foreach (var selectedInfo in info) { selectedDutyIds.Add(selectedInfo.dutyId); } // 存储缺少的职业ID List missingDutyIds = new List(); // 获取选中的场景和难度ID string selectedSceneId = selectScenePanel.idcidentId.ToString(); string selectedDifficultyId = selectScenePanel.difficultyId.ToString(); // 遍历每个限制条件,检查是否缺少职业 foreach (var sceneLimit in sceneLimits) { string[] limit = sceneLimit.Split(','); if (limit.Length == 4) { string sceneLimitId = limit[0]; string difficultyLimitId = limit[1]; string dutyId = limit[2]; string dutyNum = limit[3]; // 检查是否符合场景ID和难度ID的条件 if (sceneLimitId == selectedSceneId && difficultyLimitId == selectedDifficultyId&& dutyNum!="-1") { // 检查是否缺少职业 if (!selectedDutyIds.Contains(dutyId)) { missingDutyIds.Add(dutyId); } } } } // 输出缺少的职业ID并返回 if (missingDutyIds.Count > 0) { string missingCountMessage = "缺少至少" + missingDutyIds.Count + "名"; foreach (var missingDutyId in missingDutyIds) { // 获取职业名称(假设 SetUIText 方法用于获取职业名称) missingCountMessage += jsonReader.SetUIText(missingDutyId) + " "; } return missingCountMessage; } else { return null; // 所有职业都已选择,无需返回任何信息 } } else { return "没有找到该 sceneID 的信息!"; // 没有找到该 sceneID 信息 } } }