应急人员配置点击变色更改

This commit is contained in:
lq 2024-12-04 16:37:51 +08:00
parent 358701471d
commit 2454ea9555
7 changed files with 272 additions and 306 deletions

View File

@ -2232,7 +2232,7 @@ MonoBehaviour:
eventSystem: {fileID: 1579865912} eventSystem: {fileID: 1579865912}
ManagerPanel: {fileID: 617308871} ManagerPanel: {fileID: 617308871}
peopleCountent: {fileID: 667280287} peopleCountent: {fileID: 667280287}
peoplePrefab: {fileID: 0} peoplePrefab: {fileID: 4204671800070690484, guid: 5e14c4abba3cf1a4099ba76ddf50a689, type: 3}
panelContent: {fileID: 1145997501} panelContent: {fileID: 1145997501}
dutyPrefab: {fileID: 3344224972021141760, guid: 4f774e025e4a15442aedb0588ab62396, type: 3} dutyPrefab: {fileID: 3344224972021141760, guid: 4f774e025e4a15442aedb0588ab62396, type: 3}
dutyCount: {fileID: 1034927193} dutyCount: {fileID: 1034927193}
@ -2504,7 +2504,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -193.59004, y: 309.8263} m_AnchoredPosition: {x: -193.59004, y: 309.8263}
m_SizeDelta: {x: 388.1544, y: 58.599} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 1} m_Pivot: {x: 0, y: 1}
--- !u!114 &667280288 --- !u!114 &667280288
MonoBehaviour: MonoBehaviour:
@ -5861,6 +5861,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: -62 value: -62
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7468736064052287473, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7468736064090762255, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3} - target: {fileID: 7468736064090762255, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
propertyPath: eventName propertyPath: eventName
value: value:
@ -5887,12 +5891,16 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7468736064090762355, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3} - target: {fileID: 7468736064090762355, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
propertyPath: m_AnchoredPosition.x propertyPath: m_AnchoredPosition.x
value: 564.5 value: 206
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7468736064090762355, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3} - target: {fileID: 7468736064090762355, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: -62 value: -62
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7468736064090762356, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7468736064179597218, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3} - target: {fileID: 7468736064179597218, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
value: 0 value: 0

View File

@ -31,15 +31,9 @@ public class JSONReader : MonoBehaviour
NPCDictionary = NPCParseJSON(incidentSiteJosnFile.text); NPCDictionary = NPCParseJSON(incidentSiteJosnFile.text);
foreach (var npc in locationDictionary) foreach (var npc in locationDictionary)
{ {
//.Log($"Scene ID: {npc.Value.ID}");
//Debug.Log("===========================");
} }
GetNpcDataByID(8001);
//打印 NPC 数据
//PrintNPCData(npcDictionary);
// 打印 Location 数据
////PrintLocationData(locationDictionary);
} }
// 解析 JSON 字符串为 NPC 数据 // 解析 JSON 字符串为 NPC 数据
@ -134,43 +128,26 @@ public class JSONReader : MonoBehaviour
return locationDictionary; return locationDictionary;
} }
// 打印 NPC 数据 //将所有的数据都拿出来方便调用
//void PrintNPCData(Dictionary<int, NPCData> npcDictionary) // 根据给定的ID获取对应的NPC数据并返回字典中所有数据
//{ public void GetNpcDataByID(int id)
// foreach (var npc in npcDictionary) {
// { // 例如,获取 NPC 字典中对应 ID 的数据
// Debug.Log($"NPC ID: {npc.Value.ID}"); if (npcDictionary.ContainsKey(id))
// Debug.Log($"Note: {npc.Value.Note}"); {
// Debug.Log($"Name: {npc.Value.Name}"); NPCData npcData = npcDictionary[id];
// Debug.Log($"ActionMode: {npc.Value.ActionMode}");
// Debug.Log($"Group: {npc.Value.Group}");
// Debug.Log($"GroupLeader: {npc.Value.GroupLeader}");
// Debug.Log($"IsLeadingNPC: {npc.Value.IsLeadingNPC}");
// Debug.Log($"ICON: {npc.Value.ICON}");
// Debug.Log($"WeightLimit: {npc.Value.WeightLimit}");
// Debug.Log($"Stats: {npc.Value.Stats}");
// Debug.Log($"Skills: {npc.Value.Skills}");
// Debug.Log($"ResPath: {npc.Value.ResPath}");
// Debug.Log("------------------------------------");
// }
//}
// // 打印 Location 数据 // 遍历并输出字典中的所有数据
//void PrintLocationData(Dictionary<int, LocationData> locationDictionary) foreach (var npc in npcDictionary)
//{ {
// foreach (var location in locationDictionary)
// { }
// Debug.Log($"Location ID: {location.Value.ID}"); }
// Debug.Log($"Note: {location.Value.Note}"); else
// Debug.Log($"Name: {location.Value.Name}"); {
// Debug.Log($"Scene: {location.Value.Scene}"); Debug.Log($"No NPC found with ID: {id}");
// Debug.Log($"NpcRatio: {location.Value.NpcRatio}"); }
// Debug.Log($"Oversee: {location.Value.Oversee}"); }
// Debug.Log($"RoleLimit: {location.Value.RoleLimit}");
// Debug.Log($"Level: {location.Value.Level}");
// Debug.Log("===========================");
// }
//}
} }
// 帮助类,用于解析 JSON 数组 // 帮助类,用于解析 JSON 数组

View File

@ -13,13 +13,13 @@ using UnityEngine.UI;
public class SelectedInfo public class SelectedInfo
{ {
public string name; public string name;//角色名
public string duty; public string duty;//职责
public string scene; public string scene;//场景名
public string leader; public string leader;//是否组长
public int dutyId;//职责的Id
} }
public class Panel : MonoBehaviour public class Panel : MonoBehaviour
{ {
[Header("组件")] [Header("组件")]
@ -52,6 +52,7 @@ public class Panel : MonoBehaviour
[Header("数据")] [Header("数据")]
public string name, duty, scene; public string name, duty, scene;
public int dutyId;
public List<GameObject> peopleList = new List<GameObject>(); // 存储所有已加载的人员预制体 public List<GameObject> peopleList = new List<GameObject>(); // 存储所有已加载的人员预制体
private List<GameObject> filteredPeopleList = new List<GameObject>(); // 存储筛选后的人员列表 private List<GameObject> filteredPeopleList = new List<GameObject>(); // 存储筛选后的人员列表
private GameObject selectedPerson = null; // 当前选中的角色 private GameObject selectedPerson = null; // 当前选中的角色
@ -93,7 +94,7 @@ public class Panel : MonoBehaviour
GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent); GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent);
PeopleItem peopleItem = item.GetComponent<PeopleItem>(); PeopleItem peopleItem = item.GetComponent<PeopleItem>();
Button peoplebutton = item.transform.Find("TextBtn").GetComponent<Button>(); Button peoplebutton = item.transform.Find("TextBtn").GetComponent<Button>();
peoplebutton.onClick.AddListener(() => OnPeopleItemClicked(item,Color.yellow, selectedPerson)); peoplebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.yellow, selectedPerson));
peopleList.Add(item);// 将每个实例化的角色添加到列表中 peopleList.Add(item);// 将每个实例化的角色添加到列表中
} }
@ -102,14 +103,15 @@ public class Panel : MonoBehaviour
//动态加载职责 //动态加载职责
public void DynamicLoadingDuty() public void DynamicLoadingDuty()
{ {
Debug.Log("||||||||||||||||||||||||||||"+ selectScenePanel.eventId);
foreach (var npcData in jsonReader1.npcDictionary) foreach (var npcData in jsonReader1.npcDictionary)
{ {
string[] nameSections = npcData.Value.Name.Split('|'); string[] nameSections = npcData.Value.Name.Split('|');
foreach (var section in nameSections) foreach (var section in nameSections)
{ {
string[] sectionParts = section.Split(','); string[] sectionParts = section.Split(',');
if (int.Parse(sectionParts[0])== 2001)
//判断事件然后确定有哪些职责
if (int.Parse(sectionParts[0]) == 2001)
{ {
int key = int.Parse(sectionParts[1]); int key = int.Parse(sectionParts[1]);
if (jsonReader1.npcDictionary.ContainsKey(key)) if (jsonReader1.npcDictionary.ContainsKey(key))
@ -122,17 +124,13 @@ 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(() => OnPeopleItemClicked (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;
peopleList.Add(item); peopleList.Add(item);
} }
} }
//GameObject item = GameObject.Instantiate<GameObject>(dutyPrefab, dutyCount);
//DutyItem dutyItem = item.GetComponent<DutyItem>();
//dutyItem.dutyNameText.text = npcData.Value.Note;
//dutyItem.leader = npcData.Value.GroupLeader;
//peopleList.Add(item);// 将每个实例化的角色添加到列表中
} }
} }
@ -199,10 +197,9 @@ public class Panel : MonoBehaviour
{ {
//Debug.Log($"场景: {sceneEntry.Key},人数: {sceneEntry.Value.Count}"); //Debug.Log($"场景: {sceneEntry.Key},人数: {sceneEntry.Value.Count}");
GameObject managerPanelInstance = Instantiate(ManagerPanelPrefab, panelContent); GameObject managerPanelInstance = Instantiate(ManagerPanelPrefab, panelContent);
Button button= managerPanelInstance.GetComponent<Button>(); Button button = managerPanelInstance.GetComponent<Button>();
button.onClick.AddListener(() => managerPanel1.OnItemClicked(managerPanelInstance)); button.onClick.AddListener(() => managerPanel1.OnItemClicked(managerPanelInstance));
//ManagerPanel managerPanelScript = managerPanelInstance.GetComponentInParent<ManagerPanel>(); Text sceneText = managerPanelInstance.transform.Find("top/sceneName").GetComponent<Text>();
Text sceneText= managerPanelInstance.transform.Find("top/sceneName").GetComponent<Text>();
sceneText.text = sceneEntry.Key; sceneText.text = sceneEntry.Key;
managerPanel1.CreateScenePanel(sceneEntry.Key, sceneEntry.Value, managerPanelInstance); managerPanel1.CreateScenePanel(sceneEntry.Key, sceneEntry.Value, managerPanelInstance);
//managerPanel1.SetPlate(); //managerPanel1.SetPlate();
@ -254,11 +251,8 @@ public class Panel : MonoBehaviour
// 将当前选中的人员信息添加到对应场景的人员列表中 // 将当前选中的人员信息添加到对应场景的人员列表中
currentSceneInfo.Add(newSelectedInfo); currentSceneInfo.Add(newSelectedInfo);
// 打印当前场景人员信息
//Debug.Log($"场景: {sceneName},选中的人员: {selectedInfo.name},职责: {selectedInfo.duty}");
// 禁用确认按钮并清空选择标志 // 禁用确认按钮并清空选择标志
sureBtn.interactable = false; // 禁用确认按钮 sureBtn.interactable = false;
isPersonSelected = false; isPersonSelected = false;
isDutySelected = false; isDutySelected = false;
isSceneSelected = false; isSceneSelected = false;
@ -271,8 +265,7 @@ public class Panel : MonoBehaviour
{ {
Debug.LogError("请确保选择了人员、职责和场景!"); Debug.LogError("请确保选择了人员、职责和场景!");
} }
datePanel.NumberText.text ="共"+(sceneDataDictionary.Keys.Count * sceneDataDictionary.Values.Count).ToString()+"人参与"; datePanel.NumberText.text = "共" + (sceneDataDictionary.Keys.Count * sceneDataDictionary.Values.Count).ToString() + "人参与";
// 可以在这里根据需求继续处理选中的数据
} }
//处理界面关闭按钮 //处理界面关闭按钮
@ -311,7 +304,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>();
@ -332,7 +325,7 @@ public class Panel : MonoBehaviour
else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息 else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息
{ {
duty = buttonText.text; duty = buttonText.text;
Debug.Log(duty); dutyId = item.dutyId;
selectedInfo.duty = duty; selectedInfo.duty = duty;
isDutySelected = true; // 选择了职责 isDutySelected = true; // 选择了职责
} }
@ -389,10 +382,10 @@ 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) if (select != null && select != clickedItem)
{ {
Text prevText = select.GetComponentInChildren<Text>(); Text prevText = select.GetComponentInChildren<Text>();
if (prevText != null) if (prevText != null)
@ -403,7 +396,7 @@ public class Panel : MonoBehaviour
} }
// 设置当前选中的角色为选中状态 // 设置当前选中的角色为选中状态
select = clickedItem; select = clickedItem; // 更新选中人物
Text personText = clickedItem.GetComponentInChildren<Text>(); Text personText = clickedItem.GetComponentInChildren<Text>();
if (personText != null) if (personText != null)
{ {
@ -439,5 +432,6 @@ public class Panel : MonoBehaviour
} }
} }
} }
} }

View File

@ -9,6 +9,7 @@ public class DutyItem : MonoBehaviour
public Text dutyNameText; public Text dutyNameText;
public Button button; public Button button;
public int leader; public int leader;
public int dutyId;
public Color defaultColor = Color.white; // 默认颜色 public Color defaultColor = Color.white; // 默认颜色
public Color addedColor = Color.gray; // 已添加颜色 public Color addedColor = Color.gray; // 已添加颜色
public Color selectedColor = Color.yellow; // 选中颜色 public Color selectedColor = Color.yellow; // 选中颜色

View File

@ -104,9 +104,6 @@ public class EvacuationPanel : MonoBehaviour
} }
//private void Submit() //private void Submit()
//{ //{
// //int count = int.Parse(StuCountInputField.text);//×ÜÈËÊý // //int count = int.Parse(StuCountInputField.text);//×ÜÈËÊý
@ -298,9 +295,7 @@ public class EvacuationPanel : MonoBehaviour
CountsubmitBtn.onClick.AddListener(Countsubmit); CountsubmitBtn.onClick.AddListener(Countsubmit);
} }
} }
} }
public void Countsubmit() public void Countsubmit()
{ {
@ -329,9 +324,4 @@ public class EvacuationPanel : MonoBehaviour
classItemList.Add(classItem); classItemList.Add(classItem);
} }
} }
//Npc分配
public void NpcDistribution()
{
}
} }

View File

@ -58,7 +58,6 @@ public class ManagerPanel : MonoBehaviour
// 实例化一个人员项并将其作为场景面板的子物体 // 实例化一个人员项并将其作为场景面板的子物体
GameObject item = Instantiate(personItemPrefab, contentTransform); GameObject item = Instantiate(personItemPrefab, contentTransform);
ArrangementItem arrangementItem = item.GetComponent<ArrangementItem>(); ArrangementItem arrangementItem = item.GetComponent<ArrangementItem>();
arrangementItem.name.text = person.name; // 设置姓名 arrangementItem.name.text = person.name; // 设置姓名
arrangementItem.duty.text = person.duty; // 设置职责 arrangementItem.duty.text = person.duty; // 设置职责
} }
@ -84,6 +83,7 @@ public class ManagerPanel : MonoBehaviour
// 使当前选中的项居中显示 // 使当前选中的项居中显示
//CenterOnItem(clickedItemRT); //CenterOnItem(clickedItemRT);
} }
// 使选中的项居中显示 // 使选中的项居中显示
private void CenterOnItem(RectTransform item) private void CenterOnItem(RectTransform item)
{ {

View File

@ -157,10 +157,6 @@ public class SelectScenePanel : MonoBehaviour
// 将 Toggle 添加到 ToggleGroup 中 // 将 Toggle 添加到 ToggleGroup 中
toggle.group = eventGroup; toggle.group = eventGroup;
toggle.isOn = false; toggle.isOn = false;
// 将 Toggle 添加到 schooltoggleList 中
// 将 SchoolInfo 对象添加到 schoolInfos 列表中
eventInfoList.Add(item); eventInfoList.Add(item);
Debug.Log("!!!!!!!!!!!!!!!!!!!!!" + eventInfoList.Count); Debug.Log("!!!!!!!!!!!!!!!!!!!!!" + eventInfoList.Count);
} }