Compare commits
2 Commits
3dd80a3816
...
93501dd2b0
Author | SHA1 | Date | |
---|---|---|---|
93501dd2b0 | |||
b383d7bf89 |
@ -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"
|
||||
}
|
||||
]
|
@ -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 数组
|
||||
|
@ -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<GameObject>(scenePrefab, sceneList);
|
||||
SceneItem item = slot.GetComponent<SceneItem>();
|
||||
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<GameObject>(eventPrefab, eventList);
|
||||
EventInfo item = slot.GetComponent<EventInfo>();
|
||||
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<Toggle>();
|
||||
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("<<<<<<<<<<<<<<<<<eventId" + eventData.Key);
|
||||
GameObject slot = GameObject.Instantiate<GameObject>(incidentPrefab, incidentList);
|
||||
IncidentInfo item = slot.GetComponent<IncidentInfo>();
|
||||
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<GameObject>(eventPrefab, eventList);
|
||||
EventInfo item = slot.GetComponent<EventInfo>();
|
||||
item.eventId = eventData.ID;
|
||||
item.eventName.text = eventData.Note;
|
||||
if (item.IsOpen)
|
||||
{
|
||||
// 你可以继续处理相关逻辑,比如创建 UI 或设置属性等
|
||||
GameObject slot = GameObject.Instantiate<GameObject>(eventPrefab, eventList);
|
||||
EventInfo item = slot.GetComponent<EventInfo>();
|
||||
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<Toggle>();
|
||||
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<Toggle>();
|
||||
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; // 找到选中的场景后退出循环
|
||||
}
|
||||
}
|
||||
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<Toggle>().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; // 找到选中的场景后退出循环
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//事件及难度选择
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user