diff --git a/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs b/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs index 243410ed..d4b0c6ec 100644 --- a/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs +++ b/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs @@ -37,7 +37,7 @@ public class SelectScenePanel : MonoBehaviour public List difficultyList = new List();//游戏难度 public Button continueBtn; public List scenetoggleList = new List(); - public List schooltoggleList=new List(); + public List schooltoggleList = new List(); public List eventToggleList = new List(); public List evnetsceneList = new List(); @@ -174,29 +174,29 @@ public class SelectScenePanel : MonoBehaviour //动态加载事件选择预制体 public void InstantiateIncidentPrefab(int eventId) { - //foreach (var eventData in jsonReader.incidentSiteDictionary) - //{ - // if(eventData.Key==eventId) - // { - // GameObject slot = GameObject.Instantiate(eventPrefab, eventList); - // IncidentInfo item = slot.GetComponent(); - // item.incidentText.text = eventData.Value.Note; - // item.incidentID = eventData.Value.ID; - // Toggle toggle = slot.GetComponent(); + foreach (var eventData in jsonReader.incidentSiteDictionary) + { + if (eventData.Key == eventId) + { + GameObject slot = GameObject.Instantiate(incidentPrefab, incidentList); + IncidentInfo item = slot.GetComponent(); + item.incidentText.text = eventData.Value.Note; + item.incidentID = eventData.Value.ID; + Toggle toggle = slot.GetComponent(); - // if (toggle != null) - // { - // // 将 Toggle 添加到 ToggleGroup 中 - // toggle.group = eventGroup; - // toggle.isOn = false; - // incidentInfos.Add(item); - // } - // } - // else - // { - // break; - // } - //} + if (toggle != null) + { + // 将 Toggle 添加到 ToggleGroup 中 + toggle.group = eventGroup; + toggle.isOn = false; + incidentInfos.Add(item); + } + } + else + { + break; + } + } } //点击继续按钮后更换场景图片及名称 @@ -260,7 +260,7 @@ public class SelectScenePanel : MonoBehaviour //学校选择 public void SelectSchoolBtn() { - if(isSure) + if (isSure) { SchoolInfo gameObject = GetComponentInChildren(); foreach (SchoolInfo item in schoolInfoList) @@ -289,6 +289,7 @@ 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; @@ -420,23 +421,32 @@ public class SelectScenePanel : MonoBehaviour //关闭按钮 public void OnClickCloseBtn() { + // 清空事件列表 + eventInfoList.Clear(); + + // 销毁所有已实例化的事件预制体 + foreach (Transform child in eventList) + { + Destroy(child.gameObject); + } + + // 如果需要,也可以清空其他相关信息 + eventToggleList.Clear(); + eventId = -1; + eventName = string.Empty; + + Debug.Log("事件列表已清空,UI已重置"); if (schoolChoiceLable.gameObject.active == false) { - foreach (Transform child in sceneList) - { - child.gameObject.SetActive(false); - } sceneLable.gameObject.SetActive(true); schoolChoiceLable.gameObject.SetActive(true); eventChoiceLable.gameObject.SetActive(false); incidentLable.gameObject.SetActive(false); - InstantiateScenePrefab(); } else { transform.gameObject.SetActive(false); } - } //通过判断Toggle的IsOn是否被打开来判断继续按钮是否置灰 @@ -447,7 +457,6 @@ public class SelectScenePanel : MonoBehaviour // 检查场景选择 foreach (Toggle toggle in scenetoggleList) { - //Debug.Log("++++++++++++++++++++++++=" + scenetoggleList.Count()); if (toggle.isOn) { anyToggleSelected = true;