152 lines
4.8 KiB
C#
152 lines
4.8 KiB
C#
using Newtonsoft.Json.Schema;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEditor.Search.Providers;
|
||
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<PersonnelPanel>();
|
||
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;
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
public void CreateFirstLable()
|
||
{
|
||
GameObject fistLable = Instantiate<GameObject>(personnelLable, personnelContent);
|
||
PersonnelInfo personnelItem = fistLable.GetComponent<PersonnelInfo>();
|
||
}
|
||
public string CheckMissingRoles(string sceneID)
|
||
{
|
||
List<SelectedInfo> info = null;
|
||
|
||
// 遍历字典中的每一个条目
|
||
foreach (var entry in panel.sceneDataDictionary)
|
||
{
|
||
// 遍历每个 List<SelectedInfo>,查找是否包含 sceneID
|
||
foreach (var selectedInfo in entry.Value)
|
||
{
|
||
if (selectedInfo.sceneId == sceneID) // 如果找到匹配的 sceneId
|
||
{
|
||
// 找到对应的 List<SelectedInfo>
|
||
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<string> selectedDutyIds = new HashSet<string>();
|
||
|
||
// 遍历所有已选择的角色,提取职业ID
|
||
foreach (var selectedInfo in info)
|
||
{
|
||
selectedDutyIds.Add(selectedInfo.dutyId);
|
||
}
|
||
|
||
// 存储缺少的职业ID
|
||
List<string> missingDutyIds = new List<string>();
|
||
|
||
// 获取选中的场景和难度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];
|
||
|
||
// 检查是否符合场景ID和难度ID的条件
|
||
if (sceneLimitId == selectedSceneId && difficultyLimitId == selectedDifficultyId)
|
||
{
|
||
// 检查是否缺少职业
|
||
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(int.Parse(missingDutyId)) + " ";
|
||
}
|
||
return missingCountMessage;
|
||
}
|
||
else
|
||
{
|
||
return null; // 所有职业都已选择,无需返回任何信息
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return "没有找到该 sceneID 的信息!"; // 没有找到该 sceneID 信息
|
||
}
|
||
}
|
||
}
|