using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SceneItem : MonoBehaviour { public int sceneId; public int sceneType; public Text sceneName; public Image sceneImage; public Image maskImage; public string roleLimit;//场景限制条件 public int limitNum;//限制人数 public int dutyId; public JSONReader jsonReader; public bool IsOpen { get; set; } = true; // Start is called before the first frame update void Start() { jsonReader = GameObject.Find("JsonObj").GetComponent(); } // Update is called once per frame void Update() { } //分隔数据 public void SetData() { foreach (var npc in jsonReader.locationDictionary) { Debug.Log("111111111111" + npc.Value.RoleLimit); // 通过逗号分隔 RoleLimit 字段 string roleLimit = npc.Value.RoleLimit; // 如果 RoleLimit 不是空字符串,按照逗号分隔 if (!string.IsNullOrEmpty(roleLimit)) { string[] roleLimits = roleLimit.Split(','); // 遍历分隔后的角色限制 foreach (string role in roleLimits) { Debug.Log("RoleLimit Item: " + role); // 判断角色限制是否为 -1 if (role == "-1") { Debug.Log("角色限制为-1,区域限制人数为无限!"); } } } else { Debug.Log("RoleLimit is empty for NPC ID: " + npc.Key); } } } }