diff --git a/xiaofang/Assets/Resources/JsonAsset/PlayScript.json b/xiaofang/Assets/Resources/JsonAsset/PlayScript.json index 7d896cc0..96d9f9f2 100644 --- a/xiaofang/Assets/Resources/JsonAsset/PlayScript.json +++ b/xiaofang/Assets/Resources/JsonAsset/PlayScript.json @@ -1,16 +1,16 @@ [ - { - "ID": 5001, - "Note": "火灾", - "Name": 5001, - "Role": "8000|8001|8002|8003|8004|8005|8006|8008|8009|8010", - "DisasterLocation": "2001|2002|2003" - }, - { - "ID": 5002, - "Note": "塌方", - "Name": 5002, - "Role": "8000|8001|8002|8003|8004|8005|8006|8008|8009|8010", - "DisasterLocation": 2004 - } + { + "ID": "5001", + "Note": "火灾", + "Name": "5001", + "Role": "8000|8001|8002|8003|8004|8005|8006|8008|8009|8010", + "DisasterLocation": "2001" + }, + { + "ID": "5002", + "Note": "塌方", + "Name": "5002", + "Role": "8000|8001|8002|8003|8004|8005|8006|8008|8009|8010", + "DisasterLocation": "2004|2002" + } ] \ No newline at end of file diff --git a/xiaofang/Assets/Script/JSONReader/JSONReader.cs b/xiaofang/Assets/Script/JSONReader/JSONReader.cs index 4d772969..4db91432 100644 --- a/xiaofang/Assets/Script/JSONReader/JSONReader.cs +++ b/xiaofang/Assets/Script/JSONReader/JSONReader.cs @@ -241,13 +241,22 @@ public class JSONReader : MonoBehaviour else return null; } + public IncidentSite GetIncidentSiteById(int id) + { + IncidentSite info = null; + if (incidentSiteDictionary.TryGetValue(id, out info)) + { + return info; + } + else return null; + } + //UIıķ public void SetUIText(Text text, int id) { Language languageinfo = GetLanguageByID(id); text.text = languageinfo.Text; } - } // ࣬ڽ JSON diff --git a/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs b/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs index 6ab971c1..d1c9ca00 100644 --- a/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs +++ b/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs @@ -44,15 +44,16 @@ public class SelectScenePanel : MonoBehaviour public ToggleGroup toggleGroup; [Header("")] public DatePanel datePanel; - public int schoolId; - public string schoolName; - public int scnenId; - public string sceneName; - public int eventId; - public string eventName; - public string difficulty; - public string isBuy; - public bool isSure;//жǷύť + public Panel panel; + public int schoolId { get; set; } + public string schoolName { get; set; } + public int scnenId { get; set; } + public string sceneName { get; set; } + public int eventId { get; set; } + public string eventName { get; set; } + public string difficulty { get; set; } + public string isBuy { get; set; } + public bool isSure { get; set; }//жǷύť public JSONReader jsonReader; // Start is called before the first frame update void Start() @@ -74,10 +75,6 @@ public class SelectScenePanel : MonoBehaviour void Update() { IsClick(); - if(Input.GetKeyDown(KeyCode.A)) - { - SelectEvnentBtn(); - } } //̬سѡԤ @@ -85,7 +82,6 @@ public class SelectScenePanel : MonoBehaviour { foreach (var sceneData in jsonReader.sceneDictionary) { - Debug.Log("iiiiiiiiiiiiiii"); GameObject slot = GameObject.Instantiate(scenePrefab, sceneList); SceneItem item = slot.GetComponent(); switch (sceneData.Value.Type) @@ -147,34 +143,6 @@ public class SelectScenePanel : MonoBehaviour } } - //̬¼ͼԤ(ѡ˳֮ٵ) - public void InstantiateEventPrefab() - { - foreach (var sceneData in jsonReader.eventDictionary) - { - GameObject slot = GameObject.Instantiate(eventPrefab, eventList); - EventInfo item = slot.GetComponent(); - item.eventId = sceneData.Value.ID; - - item.eventName.text = sceneData.Value.Note; - if (item.IsOpen) - { - item.maskImage.gameObject.SetActive(false); - } - else - { - item.maskImage.gameObject.SetActive(true); - } - Toggle toggle = slot.GetComponent(); - if (toggle != null) - { - toggle.group = eventGroup; - evnetsceneList.Add(toggle); // ʹ Add() Toggle Ԫ - eventInfoList.Add(item); - } - } - } - //̬¼ѡԤ public void InstantiateIncidentPrefab(int eventId) { @@ -182,6 +150,7 @@ public class SelectScenePanel : MonoBehaviour { if (eventData.Key == eventId) { + Debug.Log("<<<<<<<<<<<<<<<<(incidentPrefab, incidentList); IncidentInfo item = slot.GetComponent(); item.incidentText.text = eventData.Value.Note; @@ -216,38 +185,56 @@ public class SelectScenePanel : MonoBehaviour // ÿָ id foreach (string incidentIdStr in incidentIds) { + Debug.Log("incidentIdStr" + incidentIdStr); // תַΪ int if (int.TryParse(incidentIdStr, out int incidentId)) { // incidentId ȡӦ¼ - if (jsonReader.eventDictionary.TryGetValue(incidentId, out var eventData)) + EventData eventData=jsonReader.GetEvenById(incidentId); + Debug.Log("eventData.ID:" + eventData.ID); + Debug.Log("eventData.DisasterLocation:" + eventData.DisasterLocation); + string[] incidentIds2 = eventData.DisasterLocation.Split('|'); + + GameObject slot = GameObject.Instantiate(eventPrefab, eventList); + EventInfo item = slot.GetComponent(); + item.eventId = eventData.ID; + item.eventName.text = eventData.Note; + if (item.IsOpen) { - // Լ߼紴 UI Ե - GameObject slot = GameObject.Instantiate(eventPrefab, eventList); - EventInfo item = slot.GetComponent(); - item.eventId = eventData.ID; - item.eventName.text = eventData.Note; - - if (item.IsOpen) - { - item.maskImage.gameObject.SetActive(false); - } - else - { - item.maskImage.gameObject.SetActive(true); - } - - Toggle toggle = slot.GetComponent(); - if (toggle != null) - { - toggle.group = sceneGroup; - eventInfoList.Add(item); - } + item.maskImage.gameObject.SetActive(false); } else { - Debug.LogWarning($"No event found for Incident ID {incidentId}"); + item.maskImage.gameObject.SetActive(true); } + Toggle toggle = slot.GetComponent(); + if (toggle != null) + { + toggle.group = sceneGroup; + eventInfoList.Add(item); + } + toggle.onValueChanged.AddListener((isSelected) => + { + if (isSelected) // ֻеToggleѡʱŵSelectEventBtn + { + // ¼б + incidentInfos.Clear(); + foreach (Transform child in incidentList) + { + Destroy(child.gameObject); + } + this.eventName = item.eventName.text; // ȡ Text ı + this.eventId = item.eventId; + EventData eventData = jsonReader.GetEvenById(this.eventId); + foreach (string disasterLocation in incidentIds2) + { + Debug.Log("disasterLocation>>>>>>>"+ disasterLocation); + InstantiateIncidentPrefab(int.Parse(disasterLocation)); + } + + createTemplateInfo.Instance.auth_CreateTemplate.sceneId = item.eventId.ToString(); + } + }); } else { @@ -294,36 +281,11 @@ public class SelectScenePanel : MonoBehaviour this.sceneName = item.sceneName.text; // ȡ Text ı this.scnenId = item.sceneId; Debug.Log("------------this.scnenId:" + this.scnenId); - createTemplateInfo.Instance.auth_CreateTemplate.sceneId = item.sceneId.ToString(); sceneSelected = true; break; // ҵѡеij˳ѭ } } - Debug.Log("---------------" + this.scnenId); - Debug.Log("###############3:" + this.schoolId); - } - - //¼ѡ - public void SelectEvnentBtn() - { - bool eventSelected = false; // Ƿгѡ - foreach (EventInfo item in eventInfoList) - { - // 鵱ǰ Toggle Ƿѡ - if (item.gameObject.transform.GetComponent().isOn) - { - // ó - this.eventName = item.eventName.text; // ȡ Text ı - this.eventId = item.eventId; - EventData eventData = jsonReader.GetEvenById(this.eventId); - InstantiateIncidentPrefab(2001); - createTemplateInfo.Instance.auth_CreateTemplate.sceneId = item.eventId.ToString(); - Debug.Log(this.eventName); - eventSelected = true; - break; // ҵѡеij˳ѭ - } - } } //¼Ѷѡ @@ -422,6 +384,7 @@ public class SelectScenePanel : MonoBehaviour //SelectEvnentBtn(); SetDataPanelInfo(); this.gameObject.SetActive(false); + panel.gameObject.SetActive(true); } //رհť @@ -437,7 +400,7 @@ public class SelectScenePanel : MonoBehaviour } // ҪҲϢ - eventToggleList.Clear(); + evnetsceneList.Clear(); eventId = -1; eventName = string.Empty; if (schoolChoiceLable.gameObject.active == false)