This commit is contained in:
lq 2025-01-03 19:15:54 +08:00
parent 67564d89f0
commit 9728ebc08d
2 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,153 @@
using Obi;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using static UnityEditor.Progress;
public class RequirementPanel : MonoBehaviour
{
[Header("场景")]
public GameObject sceneLable;
[Header("加载场景的content")]
public Transform content;
[Header("关闭按钮")]
public Button closeBtn;
public Panel panel;
public SelectScenePanel selectScenePanel;
public JSONReader jsonReader;
// Start is called before the first frame update
void Start()
{
closeBtn.onClick.AddListener(() => ClosePanel());
}
// Update is called once per frame
void Update()
{
}
//加载每个场景的lable
public void LoadingSceneLable()
{
// 清除现有的子物体
foreach (Transform child in content)
{
Destroy(child.gameObject);
}
// 用于记录已经加载的场景名称
HashSet<string> loadedSceneNames = new HashSet<string>();
// 遍历所有场景
foreach (var sceneEntry in jsonReader.locationDictionary)
{
// 拆分角色限制
string[] limit = sceneEntry.Value.RoleLimit.Split('|');
// 标记是否找到所有符合条件的职业
bool missingJob = false;
foreach (var entry in limit)
{
string[] limitDetails = entry.Split(',');
if (limitDetails.Length == 4)
{
string sceneLimitId = limitDetails[0]; // 事故位置ID
string difficultyLimitId = limitDetails[1]; // 处置难度ID
string dutyId = limitDetails[2]; // 职业ID
string dutyNum = limitDetails[3]; // 最低要求人数
if (dutyNum == "-1")
{
continue;
}
if (sceneLimitId == selectScenePanel.idcidentId.ToString() && difficultyLimitId == selectScenePanel.difficultyId.ToString())
{
// 先检查该场景是否已经加载过,如果加载过,则跳过
if (loadedSceneNames.Contains(sceneEntry.Key.ToString()))
{
continue; // 跳过当前场景
}
// 实例化每个场景的面板
GameObject managerPanelInstance = Instantiate(sceneLable, content);
PersonnelPanel scenetext = managerPanelInstance.GetComponent<PersonnelPanel>();
scenetext.personelPanelText.text = jsonReader.SetUIText(sceneEntry.Value.Name.ToString());
loadedSceneNames.Add(sceneEntry.Key.ToString()); // 记录该场景已加载
if (dutyNum == "-1")
{
continue;
}
// 遍历人员数据并加载
foreach (var Entry in panel.sceneDataDictionary)
{
string sceneId = Entry.Key;
List<SelectedInfo> selectedInfoList = Entry.Value; // 获取场景对应的人员数据列表
foreach (var selectedInfo in selectedInfoList)
{
if (selectedInfo.sceneId == sceneEntry.Key.ToString())
{
scenetext.LoadingpersonelItem(scenetext.personelContent, selectedInfo.name.ToString());
}
else
{
Debug.Log($"场景 {sceneEntry.Key} 没有人员数据");
}
}
}
// 查找该场景的职业数据
foreach (var sceneData in panel.sceneDataDictionary)
{
var dutyCount = new Dictionary<string, int>();
foreach (var npc in sceneData.Value)
{
if (npc.sceneId == sceneEntry.Key.ToString())
{
// 统计该职业的数量
if (dutyCount.ContainsKey(npc.dutyId))
{
dutyCount[npc.dutyId]++;
}
else
{
dutyCount[npc.dutyId] = 1;
}
}
}
// 判断该职业是否满足要求
int requiredDutyNum = int.Parse(dutyNum);
if (!dutyCount.ContainsKey(dutyId))
{
// 如果没有找到该职业
Debug.Log($"!!!!!!!!!!!!!!!!!!场景 {sceneEntry.Key} 缺少职业 {dutyId}");
int missingNum = requiredDutyNum;
scenetext.lockText.text = $"缺少至少{missingNum}名{jsonReader.SetUIText(dutyId)}";
missingJob = true;
}
else
{
// 判断该职业的人数是否足够
int currentDutyCount = dutyCount[dutyId];
if (currentDutyCount < requiredDutyNum)
{
int missingNum = requiredDutyNum - currentDutyCount;
scenetext.lockText.text = $"缺少{missingNum}名{jsonReader.SetUIText(dutyId)}";
missingJob = true;
}
}
}
// 如果找不到任何符合条件的职业,显示缺少的职业
if (!missingJob)
{
scenetext.lockText.text = $"缺少至少{dutyNum}名{jsonReader.SetUIText(dutyId)}";
}
}
}
}
}
}
public void ClosePanel()
{
transform.gameObject.SetActive(false);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 509805c9e4d3ed14d97e240e18ec8e09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: