剧本数据串联

This commit is contained in:
lq 2024-12-01 17:51:09 +08:00
parent 350a7e0deb
commit f71b850f24
5 changed files with 173 additions and 63 deletions

View File

@ -1,11 +1,29 @@
[
{
"ID": 9003,
"Name": 40001,
"Type": 1,
"IncidentType": "5001|5002|5003",
"ObjList": "7001,7002,7003|7001,7003|7001,7002,7003",
"AreaList": "1000|1001|1002|1003",
"Storeroom": 1011
}
{
"ID": 9003,
"Name": 40001,
"Type": 1,
"IncidentType": "5001|5002|5003",
"ObjList": "7001,7002,7003|7001,7003|7001,7002,7003",
"AreaList": "1000|1001|1002|1003",
"Storeroom": 1011
},
{
"ID": 9004,
"Name": 40001,
"Type": 2,
"IncidentType": "5001|5002|5003",
"ObjList": "7001,7002,7003|7001,7003|7001,7002,7003",
"AreaList": "1000|1001|1002|1003",
"Storeroom": 1011
},
{
"ID": 9005,
"Name": 40001,
"Type": 3,
"IncidentType": "5001|5002|5003",
"ObjList": "7001,7002,7003|7001,7003|7001,7002,7003",
"AreaList": "1000|1001|1002|1003",
"Storeroom": 1011
}
]

View File

@ -23,27 +23,16 @@ public class JSONReader : MonoBehaviour
eventDictionary = EventParseJSON(eventJsonFile.text);
matialDictionary = MatialParseJSON(matialJsonFile.text);
sceneDictionary = SceneParseJSON(sceneJsonFile.text);
foreach (var npc in locationDictionary)
foreach (var npc in sceneDictionary)
{
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);
}
}
else
{
Debug.Log("RoleLimit is empty for NPC ID: " + npc.Key);
}
Debug.Log($"Scene ID: {npc.Value.ID}");
Debug.Log($"Scene Name: {npc.Value.Name}");
Debug.Log($"Scene Type: {npc.Value.Type}");
Debug.Log($"Incident Type: {npc.Value.IncidentType}");
Debug.Log($"Object List: {npc.Value.ObjList}");
Debug.Log($"Area List: {npc.Value.AreaList}");
Debug.Log($"Storeroom: {npc.Value.Storeroom}");
Debug.Log("===========================");
}
//打印 NPC 数据

View File

@ -161,6 +161,7 @@ public class Panel : MonoBehaviour
}
//=============================================================按钮和点击事件==================================================
//处理人员管理按钮
public void ClickPersonnelManagement()
{
@ -318,6 +319,8 @@ public class Panel : MonoBehaviour
}
}
//==========================================================功能===========================================
//判断是否能够点击按钮
private void UpdateConfirmButtonState()
{

View File

@ -21,13 +21,14 @@ public class SelectScenePanel : MonoBehaviour
public GameObject scoolSelectBtn;//学校选择按钮
public GameObject schoolChoiceLable;//学校选择界面
public GameObject eventChoiceLable;//事件选择界面
public GameObject mainPanel;
public Text title;//界面标题
public List<SchoolInfo> schoolInfoList = new List<SchoolInfo>();//学校信息
public List<EventInfo> eventInfoList = new List<EventInfo>();//事件信息
public List<SceneItem> sceneItemList = new List<SceneItem>();//场景信息
public List<Toggle> difficultyList = new List<Toggle>();//游戏难度
public Button continueBtn;
public Toggle[] toggleList;
public List<Toggle> toggleList=new List<Toggle>();
//public Toggle[] toggleList;
public Toggle[] schooltoggleList;
public Toggle[] eventToggleList;
@ -36,6 +37,7 @@ public class SelectScenePanel : MonoBehaviour
public DatePanel datePanel;
public int schoolId;
public string schoolName;
public int scnenId;
public string sceneName;
public int eventId;
public string eventName;
@ -49,7 +51,7 @@ public class SelectScenePanel : MonoBehaviour
eventChoiceLable.gameObject.SetActive(false);
InstantiateScenePrefab();
InstantiateSchoolPrefab();
InstantiateEventPrefab();
InstantiateIncidentPrefab();
SetEventToggleOpenorClose(eventInfoList);
continueBtn.onClick.AddListener(OnClickContinueBtn);
SetFirstChoise(toggleList);
@ -67,32 +69,32 @@ public class SelectScenePanel : MonoBehaviour
//动态加载场景选择预制体
public void InstantiateScenePrefab()
{
//int index = 0;
//foreach (var sceneData in jsonReader.sceneDictionary)
//{
// GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList);
// SceneItem item = slot.GetComponent<SceneItem>();
// item.sceneName.text = sceneData.Value.Name.ToString();
// item.sceneId= sceneData.Value.ID;
// if (item.IsOpen)
// {
// item.maskImage.gameObject.SetActive(false);
// }
// Toggle toggle = slot.GetComponent<Toggle>();
// if (toggle != null)
// {
// toggle.group = sceneGroup;
// toggleList[index++] = toggle;
// sceneItemList.Add(item);
// }
//}
for (int i = 0; i < 6; i++)
int index = 0;
foreach (var sceneData in jsonReader.sceneDictionary)
{
GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList);
SceneItem item = slot.GetComponent<SceneItem>();
switch (sceneData.Value.Type)
{
case 1:
item.sceneName.text = "学校";
break;
case 2: // 医院
item.sceneName.text = "医院";
break;
item.sceneName.text = "场景" + i;
case 3: // 建筑工地
item.sceneName.text = "建筑工地";
break;
default:
// 如果 Type 的值不在 1, 2, 3 中
Debug.LogError("未知的场景类型");
break;
}
item.sceneId = sceneData.Value.ID;
item.sceneType = sceneData.Value.Type;
if (item.IsOpen)
{
item.maskImage.gameObject.SetActive(false);
@ -105,13 +107,36 @@ public class SelectScenePanel : MonoBehaviour
if (toggle != null)
{
toggle.group = sceneGroup;
toggleList[i] = toggle;
toggleList[index++] = toggle;
sceneItemList.Add(item);
}
}
//for (int i = 0; i < 6; i++)
//{
// GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList);
// SceneItem item = slot.GetComponent<SceneItem>();
// item.sceneName.text = "场景" + i;
// 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;
// toggleList[i] = toggle;
// sceneItemList.Add(item);
// }
//}
}
//动态加载学校选择预制体
//动态加载学校选择预制体(这里面的东西需要判断场景的Id来加载对应的场景)
public void InstantiateSchoolPrefab()
{
for (int i = 0; i < 6; i++)
@ -137,7 +162,7 @@ public class SelectScenePanel : MonoBehaviour
}
//动态加载事件选择预制体
public void InstantiateEventPrefab()
public void InstantiateIncidentPrefab()
{
foreach(var eventData in jsonReader.eventDictionary)
{
@ -165,6 +190,74 @@ public class SelectScenePanel : MonoBehaviour
}
}
//点击继续按钮后更换场景图片及名称
public void InstantiateEventPrefab(int id)
{
// 清空所有的子物体
foreach (Transform child in sceneList)
{
Destroy(child.gameObject);
}
// 通过 id 获取对应的 sceneData
if (jsonReader.sceneDictionary.TryGetValue(id, out var sceneData))
{
// 将 IncidentType 按照 '|' 分隔成一个数组
string[] incidentIds = sceneData.IncidentType.Split('|');
// 遍历每个分隔出来的 id
foreach (string incidentIdStr in incidentIds)
{
// 转换字符串为 int 类型
if (int.TryParse(incidentIdStr, out int incidentId))
{
// 根据 incidentId 获取对应的事件数据
if (jsonReader.eventDictionary.TryGetValue(incidentId, out var eventData))
{
// 在这里你可以根据 eventData 做进一步操作
Debug.Log($"Found event for Incident ID {incidentId}: {eventData.Note}");
// 你可以继续处理相关逻辑,比如创建 UI 或设置属性等
GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList);
SceneItem item = slot.GetComponent<SceneItem>();
item.sceneId = eventData.ID;
item.sceneName.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;
//toggleList.Add(toggle);
sceneItemList.Add(item);
}
}
else
{
Debug.LogWarning($"No event found for Incident ID {incidentId}");
}
}
else
{
Debug.LogWarning($"Invalid Incident ID format: {incidentIdStr}");
}
}
}
else
{
Debug.LogWarning($"No scene data found for ID {id}");
}
}
//学校选择
public void SelectSchoolBtn()
{
@ -175,10 +268,11 @@ public class SelectScenePanel : MonoBehaviour
{
this.schoolId = item.schoolId;
this.schoolName = item.schoolName.text;
title.text = item.schoolName.text;
}
}
//Debug.Log("###############1:" + this.schoolId);
//Debug.Log("###############2:" + this.schoolName);
Debug.Log("###############1:" + this.schoolId);
Debug.Log("###############2:" + this.schoolName);
}
//场景选择
@ -192,11 +286,13 @@ public class SelectScenePanel : MonoBehaviour
{
// 设置场景名称
this.sceneName = item.sceneName.text; // 获取 Text 组件的文本
this.scnenId = item.sceneId;
createTemplateInfo.Instance.auth_CreateTemplate.sceneId = item.sceneId.ToString();
sceneSelected = true;
break; // 找到选中的场景后退出循环
}
}
Debug.Log("---------------" + this.scnenId);
Debug.Log("###############3:" + this.schoolId);
//IsClick();
}
@ -294,6 +390,7 @@ public class SelectScenePanel : MonoBehaviour
//IsClick(); // 调用 IsClick 检查是否选中学校和场景
SelectSchoolBtn();
SelectSceneBtn();
InstantiateEventPrefab(this.scnenId);
// 如果场景或学校没有选中,则不执行下面的操作
if (continueBtn.interactable)
{
@ -326,19 +423,20 @@ public class SelectScenePanel : MonoBehaviour
public void IsClick()
{
bool anyToggleSelected = false;
// // 检查场景选择
// 检查场景选择
foreach (Toggle toggle in toggleList)
{
Debug.Log("++++++++++++++++++++++++="+toggleList.Count());
if (toggle.isOn)
{
anyToggleSelected = true;
break; // 如果有一个场景 Toggle 被选中,停止检查
}
}
// //根据是否有 Toggle 被选中,设置 ContinueBtn 是否可交互
// 根据是否有 Toggle 被选中,设置 ContinueBtn 是否可交互
if (continueBtn != null)
{
//Debug.Log(anyToggleSelected);
continueBtn.interactable = anyToggleSelected; // 如果有选中的 Toggle继续按钮可交互否则不可交互
}
else
@ -347,14 +445,15 @@ public class SelectScenePanel : MonoBehaviour
}
}
//默认选择第一个Toggle
public void SetFirstChoise(Toggle[] toggles)
public void SetFirstChoise(List<Toggle> toggles)
{
// 获取ToggleGroup中的所有Toggle
// 如果有Toggle则选中第一个
if (toggles.Length > 0)
if (toggles.Count() > 0)
{
toggles[0].isOn = true;
}

View File

@ -7,6 +7,7 @@ using UnityEngine.UI;
public class SceneItem : MonoBehaviour
{
public int sceneId;
public int sceneType;
public Text sceneName;
public Image sceneImage;
public Image maskImage;