Language设置

This commit is contained in:
lq 2024-12-04 22:58:31 +08:00
parent 46ec56f0f6
commit 1d623866c4
6 changed files with 1657 additions and 23 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 62a41129c4663ee41a06274114d28feb
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2242,6 +2242,7 @@ MonoBehaviour:
name: name:
duty: duty:
scene: scene:
dutyId: 0
peopleList: [] peopleList: []
managerPanel1: {fileID: 617308873} managerPanel1: {fileID: 617308873}
jsonReader1: {fileID: 1417128757} jsonReader1: {fileID: 1417128757}
@ -8757,6 +8758,7 @@ MonoBehaviour:
sceneJsonFile: {fileID: 4900000, guid: 06c09fd1c8b0a0a45951a1065189d922, type: 3} sceneJsonFile: {fileID: 4900000, guid: 06c09fd1c8b0a0a45951a1065189d922, type: 3}
incidentSiteJosnFile: {fileID: 4900000, guid: 1efa4372b10d4294199638c49173ff4c, type: 3} incidentSiteJosnFile: {fileID: 4900000, guid: 1efa4372b10d4294199638c49173ff4c, type: 3}
NPCJosnFile: {fileID: 4900000, guid: 41009f009f0718647a782c7e1aec97dd, type: 3} NPCJosnFile: {fileID: 4900000, guid: 41009f009f0718647a782c7e1aec97dd, type: 3}
LanguageJsonFile: {fileID: 4900000, guid: 62a41129c4663ee41a06274114d28feb, type: 3}
--- !u!4 &1417128758 --- !u!4 &1417128758
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -11,6 +11,7 @@ public class JSONReader : MonoBehaviour
public TextAsset sceneJsonFile; public TextAsset sceneJsonFile;
public TextAsset incidentSiteJosnFile; public TextAsset incidentSiteJosnFile;
public TextAsset NPCJosnFile; public TextAsset NPCJosnFile;
public TextAsset LanguageJsonFile;
public Dictionary<int, NPCData> npcDictionary = new Dictionary<int, NPCData>(); public Dictionary<int, NPCData> npcDictionary = new Dictionary<int, NPCData>();
public Dictionary<int, LocationData> locationDictionary = new Dictionary<int, LocationData>(); public Dictionary<int, LocationData> locationDictionary = new Dictionary<int, LocationData>();
public Dictionary<int, EventData> eventDictionary = new Dictionary<int, EventData>(); public Dictionary<int, EventData> eventDictionary = new Dictionary<int, EventData>();
@ -18,6 +19,7 @@ public class JSONReader : MonoBehaviour
public Dictionary<int, SceneData> sceneDictionary = new Dictionary<int, SceneData>(); public Dictionary<int, SceneData> sceneDictionary = new Dictionary<int, SceneData>();
public Dictionary<int, IncidentSite> incidentSiteDictionary = new Dictionary<int, IncidentSite>(); public Dictionary<int, IncidentSite> incidentSiteDictionary = new Dictionary<int, IncidentSite>();
public Dictionary<int, NPC> NPCDictionary = new Dictionary<int, NPC>(); public Dictionary<int, NPC> NPCDictionary = new Dictionary<int, NPC>();
public Dictionary<int, Language> LanguageDictionary = new Dictionary<int, Language>();
void Awake() void Awake()
{ {
@ -29,9 +31,12 @@ public class JSONReader : MonoBehaviour
sceneDictionary = SceneParseJSON(sceneJsonFile.text); sceneDictionary = SceneParseJSON(sceneJsonFile.text);
incidentSiteDictionary = IncidentSiteParseJSON(incidentSiteJosnFile.text); incidentSiteDictionary = IncidentSiteParseJSON(incidentSiteJosnFile.text);
NPCDictionary = NPCParseJSON(incidentSiteJosnFile.text); NPCDictionary = NPCParseJSON(incidentSiteJosnFile.text);
foreach (var npc in locationDictionary) LanguageDictionary = LanguageParseJSON(LanguageJsonFile.text);
GetLanguageByID(20008);
foreach (var npc in LanguageDictionary)
{ {
//Debug.Log(npc.Value.Text);
//Debug.Log(npc.Value.Note);
} }
GetNpcDataByID(8001); GetNpcDataByID(8001);
} }
@ -128,6 +133,19 @@ public class JSONReader : MonoBehaviour
return locationDictionary; return locationDictionary;
} }
public Dictionary<int, Language> LanguageParseJSON(string json)
{
Language[] locationArray = JsonHelper.FromJson<Language>(json);
Dictionary<int, Language> locationDictionary = new Dictionary<int, Language>();
foreach (var location in locationArray)
{
locationDictionary[location.ID] = location;
}
return locationDictionary;
}
//将所有的数据都拿出来方便调用 //将所有的数据都拿出来方便调用
// 根据给定的ID获取对应的NPC数据并返回字典中所有数据 // 根据给定的ID获取对应的NPC数据并返回字典中所有数据
public void GetNpcDataByID(int id) public void GetNpcDataByID(int id)
@ -148,6 +166,29 @@ public class JSONReader : MonoBehaviour
Debug.Log($"No NPC found with ID: {id}"); Debug.Log($"No NPC found with ID: {id}");
} }
} }
public Language GetLanguageByID(int id)
{
Language info = null;
if (LanguageDictionary.TryGetValue(id, out info))
{
// 判断 Note 是否等于 "预定演练"
if (info.Note == "预订演练")
{
Debug.Log($"Found Language: ID = {info.ID}, Text = {info.Text}, Note = {info.Note}");
return info; // 返回符合条件的 Language 数据
}
else
{
Debug.Log($"Language with ID {id} found, but Note is not '预定演练'.");
}
}
else
{
Debug.Log($"No Language found with ID: {id}");
}
return null; // 如果没有找到符合条件的语言数据,返回 null
}
} }
// 帮助类,用于解析 JSON 数组 // 帮助类,用于解析 JSON 数组
@ -262,3 +303,12 @@ public class NPC
public string Stats1; public string Stats1;
public string Stats2; public string Stats2;
} }
[System.Serializable]
public class Language
{
public int ID;
public string Text;
public string Note;
}

View File

@ -124,7 +124,7 @@ public class Panel : MonoBehaviour
GameObject item = GameObject.Instantiate(dutyPrefab, dutyCount); GameObject item = GameObject.Instantiate(dutyPrefab, dutyCount);
DutyItem dutyItem = item.GetComponent<DutyItem>(); DutyItem dutyItem = item.GetComponent<DutyItem>();
Button dutuybutton = item.transform.Find("TextBtn").GetComponent<Button>(); Button dutuybutton = item.transform.Find("TextBtn").GetComponent<Button>();
dutuybutton.onClick.AddListener(() => OnPeopleItemClicked (item, Color.red, selectedDuty)); dutuybutton.onClick.AddListener(() => OnDutyItemClicked(item, Color.red, selectedDuty));
dutyItem.dutyNameText.text = npcData.Value.Note; dutyItem.dutyNameText.text = npcData.Value.Note;
dutyItem.leader = npcData.Value.GroupLeader; dutyItem.leader = npcData.Value.GroupLeader;
dutyItem.dutyId = npcData.Value.ID; dutyItem.dutyId = npcData.Value.ID;
@ -167,7 +167,7 @@ public class Panel : MonoBehaviour
GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount); GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
SceneItem sceneItem = item.GetComponent<SceneItem>(); SceneItem sceneItem = item.GetComponent<SceneItem>();
Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>(); Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
scenebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.green, selectedScene)); scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene));
// 设置limitNum // 设置limitNum
sceneItem.dutyId = int.Parse(roleLimits[1]); sceneItem.dutyId = int.Parse(roleLimits[1]);
@ -245,7 +245,8 @@ public class Panel : MonoBehaviour
{ {
name = selectedInfo.name, name = selectedInfo.name,
duty = selectedInfo.duty, duty = selectedInfo.duty,
scene = selectedInfo.scene scene = selectedInfo.scene,
dutyId= selectedInfo.dutyId
}; };
// 将当前选中的人员信息添加到对应场景的人员列表中 // 将当前选中的人员信息添加到对应场景的人员列表中
@ -304,7 +305,7 @@ public class Panel : MonoBehaviour
{ {
// 检测到点击了按钮 // 检测到点击了按钮
Button clickedButton = result.gameObject.GetComponent<Button>(); Button clickedButton = result.gameObject.GetComponent<Button>();
DutyItem item = clickedButton.GetComponentInParent<DutyItem>();
if (clickedButton != null) if (clickedButton != null)
{ {
Text buttonText = clickedButton.GetComponentInChildren<Text>(); Text buttonText = clickedButton.GetComponentInChildren<Text>();
@ -324,7 +325,8 @@ public class Panel : MonoBehaviour
} }
else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息 else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息
{ {
duty = buttonText.text; DutyItem item = clickedButton.GetComponentInParent<DutyItem>();
duty = buttonText.text;
dutyId = item.dutyId; dutyId = item.dutyId;
selectedInfo.duty = duty; selectedInfo.duty = duty;
isDutySelected = true; // 选择了职责 isDutySelected = true; // 选择了职责
@ -352,6 +354,12 @@ public class Panel : MonoBehaviour
arrangeText.text = "[" + name + "]担任[" + duty + "],位于[" + scene + "]"; arrangeText.text = "[" + name + "]担任[" + duty + "],位于[" + scene + "]";
} }
public void SetUIText(Text text,int id)
{
Language languageinfo = jsonReader1.GetLanguageByID(id);
text.text = languageinfo.Text;
}
//筛选 //筛选
public void SetInputFile() public void SetInputFile()
{ {
@ -381,13 +389,13 @@ public class Panel : MonoBehaviour
} }
} }
// 点击选中角色,改变视觉效果(可复用) // 点击选中角色,改变视觉效果
public void OnPeopleItemClicked(GameObject clickedItem, Color color, GameObject select) public void OnPeopleItemClicked(GameObject clickedItem, Color color, GameObject select)
{ {
// 如果有之前选中的角色,重置其视觉效果 // 如果有之前选中的角色,重置其视觉效果
if (select != null && select != clickedItem) if (selectedPerson != null && select != clickedItem)
{ {
Text prevText = select.GetComponentInChildren<Text>(); Text prevText = selectedPerson.GetComponentInChildren<Text>();
if (prevText != null) if (prevText != null)
{ {
prevText.fontSize = 32; // 恢复原始字号 prevText.fontSize = 32; // 恢复原始字号
@ -396,7 +404,57 @@ public class Panel : MonoBehaviour
} }
// 设置当前选中的角色为选中状态 // 设置当前选中的角色为选中状态
select = clickedItem; // 更新选中人物 selectedPerson = clickedItem; // 更新选中人物
Text personText = clickedItem.GetComponentInChildren<Text>();
if (personText != null)
{
// 字号变大和颜色变更(选中状态)
personText.fontSize = 36;
personText.color = color; // 选中颜色
}
}
// 点击选中职责,改变视觉效果
public void OnDutyItemClicked(GameObject clickedItem, Color color, GameObject select)
{
// 如果有之前选中的角色,重置其视觉效果
if (selectedDuty != null && select != clickedItem)
{
Text prevText = selectedDuty.GetComponentInChildren<Text>();
if (prevText != null)
{
prevText.fontSize = 32; // 恢复原始字号
prevText.color = Color.white; // 恢复原始颜色
}
}
// 设置当前选中的角色为选中状态
selectedDuty = clickedItem; // 更新选中人物
Text personText = clickedItem.GetComponentInChildren<Text>();
if (personText != null)
{
// 字号变大和颜色变更(选中状态)
personText.fontSize = 36;
personText.color = color; // 选中颜色
}
}
// 点击选中角色,改变视觉效果
public void OnSceneItemClicked(GameObject clickedItem, Color color, GameObject select)
{
// 如果有之前选中的角色,重置其视觉效果
if (selectedScene != null && select != clickedItem)
{
Text prevText = selectedScene.GetComponentInChildren<Text>();
if (prevText != null)
{
prevText.fontSize = 32; // 恢复原始字号
prevText.color = Color.white; // 恢复原始颜色
}
}
// 设置当前选中的角色为选中状态
selectedScene = clickedItem; // 更新选中人物
Text personText = clickedItem.GetComponentInChildren<Text>(); Text personText = clickedItem.GetComponentInChildren<Text>();
if (personText != null) if (personText != null)
{ {

View File

@ -29,9 +29,8 @@ public class SelectScenePanel : MonoBehaviour
public Button continueBtn; public Button continueBtn;
public List<Toggle> toggleList = new List<Toggle>(); public List<Toggle> toggleList = new List<Toggle>();
public List<Toggle> eventToggleList = new List<Toggle>(); public List<Toggle> eventToggleList = new List<Toggle>();
//public Toggle[] toggleList; public List<Toggle> evnetsceneList = new List<Toggle>();
public Toggle[] schooltoggleList; public Toggle[] schooltoggleList;
//public Toggle[] eventToggleList;
public ToggleGroup toggleGroup; public ToggleGroup toggleGroup;
[Header("数据")] [Header("数据")]
@ -127,13 +126,8 @@ public class SelectScenePanel : MonoBehaviour
if (toggle != null) if (toggle != null)
{ {
// 将 Toggle 添加到 ToggleGroup 中
toggle.group = schoolGroup; toggle.group = schoolGroup;
// 将 Toggle 添加到 schooltoggleList 中
schooltoggleList[i] = toggle; schooltoggleList[i] = toggle;
// 将 SchoolInfo 对象添加到 schoolInfos 列表中
schoolInfoList.Add(item); schoolInfoList.Add(item);
} }
} }
@ -158,7 +152,6 @@ public class SelectScenePanel : MonoBehaviour
toggle.group = eventGroup; toggle.group = eventGroup;
toggle.isOn = false; toggle.isOn = false;
eventInfoList.Add(item); eventInfoList.Add(item);
Debug.Log("!!!!!!!!!!!!!!!!!!!!!" + eventInfoList.Count);
} }
} }
else else
@ -365,7 +358,7 @@ public class SelectScenePanel : MonoBehaviour
SelectSchoolBtn(); SelectSchoolBtn();
SelectSceneBtn(); SelectSceneBtn();
InstantiateEventPrefab(this.scnenId); InstantiateEventPrefab(this.scnenId);
// 如果场景或学校没有选中,则不执行下面的操作 SetFirstChoise(toggleList);
if (continueBtn.interactable) if (continueBtn.interactable)
{ {
schoolChoiceLable.gameObject.SetActive(false); schoolChoiceLable.gameObject.SetActive(false);
@ -436,9 +429,6 @@ public class SelectScenePanel : MonoBehaviour
//默认选择第一个Toggle //默认选择第一个Toggle
public void SetFirstChoise(List<Toggle> toggles) public void SetFirstChoise(List<Toggle> toggles)
{ {
// 获取ToggleGroup中的所有Toggle
// 如果有Toggle则选中第一个 // 如果有Toggle则选中第一个
if (toggles.Count() > 0) if (toggles.Count() > 0)
{ {