From d31d805fd281c38e57f02a5aa42b63e4a3d83370 Mon Sep 17 00:00:00 2001 From: LMZ <1477077658@qq.com> Date: Sat, 28 Dec 2024 14:06:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=B7=E5=81=B7=E6=8F=90=E4=BA=A4=E4=B8=8D?= =?UTF-8?q?=E5=91=8A=E8=AF=89=E4=BD=A0=E4=BB=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaofang/Assets/Script/UI/ZZZZZZ/ZZZPlayer.cs | 103 +++++++++++------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/xiaofang/Assets/Script/UI/ZZZZZZ/ZZZPlayer.cs b/xiaofang/Assets/Script/UI/ZZZZZZ/ZZZPlayer.cs index 7cf02757..f8a5cd2a 100644 --- a/xiaofang/Assets/Script/UI/ZZZZZZ/ZZZPlayer.cs +++ b/xiaofang/Assets/Script/UI/ZZZZZZ/ZZZPlayer.cs @@ -1,5 +1,7 @@ +using System; using System.Collections; using System.Collections.Generic; +using System.Xml; using Unity.VisualScripting; using UnityEngine; @@ -8,7 +10,7 @@ public class ZZZPlayer : MonoBehaviour public static ZZZPlayer CSZS; public JSONReader jSONReader; - public Dictionary CSB1 = new Dictionary(); //Key是判断是不是一组,string是ID tanchuang1用的 + public Dictionary> CSB1 = new Dictionary>(); //Key是判断是不是一组,string是ID tanchuang1用的 public bool isYou=true; public void Start() @@ -101,59 +103,81 @@ public class ZZZPlayer : MonoBehaviour /// 是否存在 public void FindPlayerTaskID(int number,string Type) { - foreach (var item in jSONReader.ZZSelectsDictionary) + foreach (var item in jSONReader.ZZSelectsDictionary) { Select data = item.Value; if (data.AppliedUI == "tanchuang1") { var a = GetNumberBeforeComma(data.Group); - Debug.Log("bbbb"); - //先用Grop分组 + + // 检查并初始化键 if (!CSB1.ContainsKey(a)) { - CSB1.Add(a, data.ID);// 更新值 + CSB1[a] = new List(); // 初始化键对应的列表 } + + // 添加值到键对应的列表 + CSB1[a].Add(data.ID); } } - TwoFind(number); + + // 执行后续对比逻辑 + CompareValues(number); } - public void TwoFind(int number) + /// + /// 第二次筛选 + /// + private void CompareValues(int number) { - //再一次来判断 - if (isYou) - { - Debug.Log("进来了脸脸了了了了了了脸脸了脸脸了了了脸脸了了"); - Debug.Log(CSB1.Count); - foreach (KeyValuePair kvp in CSB1) - { - Debug.Log("进不来了"); - int key = kvp.Key; - string value = kvp.Value; + // 获取所有 Key + List allKeys = GetAllKeys(CSB1); + Debug.Log("所有的 Key: " + string.Join(", ", allKeys)); - // 将字符串拆分为 List - List values = new List(value.Split(',')); + // 获取所有 Value + List allValues = GetAllValues(CSB1); + Debug.Log("所有的 Values: " + string.Join(", ", allValues)); + //foreach (var kvp in CSB1) + //{ + // int key = kvp.Key; + // string value = kvp.Value; + + // // 分割 Value 字符串为多个部分 + // List valueList = new List(value.Split(',')); + + // Debug.Log($"Key {key} 包含的值:{string.Join(", ", valueList)}"); + + // // 遍历分割后的值并逐个传递 + // foreach (string item in valueList) + // { + // Debug.Log(key+"_"+item); + // } + //} - // 对值列表进行对比 - for (int i = 0; i < values.Count; i++) - { - Debug.Log("进不来了11111"); - for (int j = i + 1; j < values.Count; j++) - { - Debug.Log("进不来了22222"); - isYou = IsNumberInData(values[j], number); - if (isYou) - { - break; - } - } - if (isYou) - { - break; - } - } - } - } } + #region 测试 + /// + /// 获取所有 Key + /// + private List GetAllKeys(Dictionary> dictionary) + { + return new List(dictionary.Keys); + } + + /// + /// 获取所有 Value + /// + private List GetAllValues(Dictionary> dictionary) + { + List allValues = new List(); + + foreach (var values in dictionary.Values) + { + allValues.AddRange(values); // 合并所有值 + } + + return allValues; + } + #endregion public bool IsNumberInData(string data, int number) { @@ -196,7 +220,6 @@ public class ZZZPlayer : MonoBehaviour /// 逗号前的数字,如果解析失败返回 -1 public int GetNumberBeforeComma(string data) { - Debug.Log("aaaa"); if (string.IsNullOrEmpty(data)) { Debug.LogWarning("输入为空或 null!");