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

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; // 当前选中的角色
@ -69,47 +70,48 @@ public class Panel : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
selectedInfo = new SelectedInfo(); selectedInfo = new SelectedInfo();
DynamicLoadingPeople(); DynamicLoadingPeople();
DynamicLoadingDuty(); DynamicLoadingDuty();
DynamicLoadingScene(); DynamicLoadingScene();
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
GetData(); GetData();
SetText(); SetText();
//SetInputFile(); //SetInputFile();
} }
//==================================================================动态加载======================================================= //==================================================================动态加载=======================================================
//动态加载人员 //动态加载人员
public void DynamicLoadingPeople() public void DynamicLoadingPeople()
{
for (int i = 0; i < 20; i++)
{ {
GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent); for (int i = 0; i < 20; i++)
PeopleItem peopleItem = item.GetComponent<PeopleItem>(); {
Button peoplebutton = item.transform.Find("TextBtn").GetComponent<Button>(); GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent);
peoplebutton.onClick.AddListener(() => OnPeopleItemClicked(item,Color.yellow, selectedPerson)); PeopleItem peopleItem = item.GetComponent<PeopleItem>();
peopleList.Add(item);// 将每个实例化的角色添加到列表中 Button peoplebutton = item.transform.Find("TextBtn").GetComponent<Button>();
peoplebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.yellow, selectedPerson));
peopleList.Add(item);// 将每个实例化的角色添加到列表中
}
} }
}
//动态加载职责 //动态加载职责
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);// 将每个实例化的角色添加到列表中
} }
} }
@ -140,259 +138,254 @@ public class Panel : MonoBehaviour
//动态加载场景 //动态加载场景
public void DynamicLoadingScene() public void DynamicLoadingScene()
{
foreach (var npcData in jsonReader1.locationDictionary)
{ {
// 解析角色限制字段 foreach (var npcData in jsonReader1.locationDictionary)
string roleLimit = npcData.Value.RoleLimit;
if (!string.IsNullOrEmpty(roleLimit))
{ {
// 先按“|”分隔 // 解析角色限制字段
string[] roleLimitSections = roleLimit.Split('|'); string roleLimit = npcData.Value.RoleLimit;
// 遍历每个部分(按“|”分隔后得到的数组)
bool shouldInstantiate = true; // 用于判断是否需要实例化 if (!string.IsNullOrEmpty(roleLimit))
foreach (string section in roleLimitSections)
{ {
string[] roleLimits = section.Split(','); // 先按“|”分隔
// 判断当前部分是否包含 "-1" 来决定是否跳过实例化 string[] roleLimitSections = roleLimit.Split('|');
if (section.Contains("-1")) // 遍历每个部分(按“|”分隔后得到的数组)
bool shouldInstantiate = true; // 用于判断是否需要实例化
foreach (string section in roleLimitSections)
{ {
if (roleLimits[0] == "-1") string[] roleLimits = section.Split(',');
// 判断当前部分是否包含 "-1" 来决定是否跳过实例化
if (section.Contains("-1"))
{ {
shouldInstantiate = false; // 不实例化该NPC if (roleLimits[0] == "-1")
break; // 跳出循环直接处理下一个NPC {
shouldInstantiate = false; // 不实例化该NPC
break; // 跳出循环直接处理下一个NPC
}
}
else
{
GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
SceneItem sceneItem = item.GetComponent<SceneItem>();
Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
scenebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.green, selectedScene));
// 设置limitNum
sceneItem.dutyId = int.Parse(roleLimits[1]);
sceneItem.limitNum = int.Parse(roleLimits[2]);
sceneItem.sceneName.text = npcData.Value.Note;
// 将每个实例化的角色添加到列表中
peopleList.Add(item);
} }
} }
else // 如果不满足实例化条件跳过当前NPC的实例化
if (!shouldInstantiate)
{ {
GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount); continue;
SceneItem sceneItem = item.GetComponent<SceneItem>();
Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
scenebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.green, selectedScene));
// 设置limitNum
sceneItem.dutyId = int.Parse(roleLimits[1]);
sceneItem.limitNum = int.Parse(roleLimits[2]);
sceneItem.sceneName.text = npcData.Value.Note;
// 将每个实例化的角色添加到列表中
peopleList.Add(item);
} }
} }
// 如果不满足实例化条件跳过当前NPC的实例化
if (!shouldInstantiate)
{
continue;
}
} }
} }
}
//=============================================================按钮和点击事件================================================== //=============================================================按钮和点击事件==================================================
//处理人员管理按钮 //处理人员管理按钮
public void ClickPersonnelManagement() public void ClickPersonnelManagement()
{ {
foreach (Transform child in panelContent) foreach (Transform child in panelContent)
{ {
Destroy(child.gameObject); Destroy(child.gameObject);
} }
foreach (var sceneEntry in sceneDataDictionary) foreach (var sceneEntry in sceneDataDictionary)
{ {
//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(); ManagerPanel.gameObject.SetActive(true);
ManagerPanel.gameObject.SetActive(true); }
} }
}
//处理点击确认按钮 //处理点击确认按钮
public void ClickSureBtn() public void ClickSureBtn()
{
// 只有在选择了人员、职责和场景的情况下,才会执行后续操作
if (isPersonSelected && isDutySelected && isSceneSelected)
{ {
// 保存选中的人员信息到场景数据字典中 // 只有在选择了人员、职责和场景的情况下,才会执行后续操作
string sceneName = selectedInfo.scene; if (isPersonSelected && isDutySelected && isSceneSelected)
// 如果场景字典中没有这个场景,先创建一个空列表
if (!sceneDataDictionary.ContainsKey(sceneName))
{ {
sceneDataDictionary[sceneName] = new List<SelectedInfo>(); // 保存选中的人员信息到场景数据字典中
} string sceneName = selectedInfo.scene;
// 需要判断是否达到了职责的人员上限 // 如果场景字典中没有这个场景,先创建一个空列表
bool isLimitReached = false; if (!sceneDataDictionary.ContainsKey(sceneName))
// 获取当前场景中的所有人员信息
List<SelectedInfo> currentSceneInfo = sceneDataDictionary[sceneName];
// 如果选中了“主持人”、“各组长”或“总指挥”则限制数量为1
if (selectedInfo.duty == "主持人" || selectedInfo.duty == "组长" || selectedInfo.duty == "总指挥")
{
int count = currentSceneInfo.Count(info => info.duty == selectedInfo.duty); // 统计当前职责人数
if (count >= 1) // 如果已经有1个此职责的人选
{ {
Debug.LogError($"{selectedInfo.duty} 已达最大人数限制"); sceneDataDictionary[sceneName] = new List<SelectedInfo>();
isLimitReached = true; // 标记限制已达 }
// 需要判断是否达到了职责的人员上限
bool isLimitReached = false;
// 获取当前场景中的所有人员信息
List<SelectedInfo> currentSceneInfo = sceneDataDictionary[sceneName];
// 如果选中了“主持人”、“各组长”或“总指挥”则限制数量为1
if (selectedInfo.duty == "主持人" || selectedInfo.duty == "组长" || selectedInfo.duty == "总指挥")
{
int count = currentSceneInfo.Count(info => info.duty == selectedInfo.duty); // 统计当前职责人数
if (count >= 1) // 如果已经有1个此职责的人选
{
Debug.LogError($"{selectedInfo.duty} 已达最大人数限制");
isLimitReached = true; // 标记限制已达
}
}
// 如果没有达到上限,则可以添加人员信息
if (!isLimitReached)
{
// 通过创建一个新的 SelectedInfo 实例来避免引用同一个对象
SelectedInfo newSelectedInfo = new SelectedInfo
{
name = selectedInfo.name,
duty = selectedInfo.duty,
scene = selectedInfo.scene
};
// 将当前选中的人员信息添加到对应场景的人员列表中
currentSceneInfo.Add(newSelectedInfo);
// 禁用确认按钮并清空选择标志
sureBtn.interactable = false;
isPersonSelected = false;
isDutySelected = false;
isSceneSelected = false;
// 改变已添加人员的显示颜色
UpdatePeopleListVisual();
} }
} }
// 如果没有达到上限,则可以添加人员信息 else
if (!isLimitReached)
{ {
// 通过创建一个新的 SelectedInfo 实例来避免引用同一个对象 Debug.LogError("请确保选择了人员、职责和场景!");
SelectedInfo newSelectedInfo = new SelectedInfo
{
name = selectedInfo.name,
duty = selectedInfo.duty,
scene = selectedInfo.scene
};
// 将当前选中的人员信息添加到对应场景的人员列表中
currentSceneInfo.Add(newSelectedInfo);
// 打印当前场景人员信息
//Debug.Log($"场景: {sceneName},选中的人员: {selectedInfo.name},职责: {selectedInfo.duty}");
// 禁用确认按钮并清空选择标志
sureBtn.interactable = false; // 禁用确认按钮
isPersonSelected = false;
isDutySelected = false;
isSceneSelected = false;
// 改变已添加人员的显示颜色
UpdatePeopleListVisual();
} }
datePanel.NumberText.text = "共" + (sceneDataDictionary.Keys.Count * sceneDataDictionary.Values.Count).ToString() + "人参与";
} }
else
{
Debug.LogError("请确保选择了人员、职责和场景!");
}
datePanel.NumberText.text ="共"+(sceneDataDictionary.Keys.Count * sceneDataDictionary.Values.Count).ToString()+"人参与";
// 可以在这里根据需求继续处理选中的数据
}
//处理界面关闭按钮 //处理界面关闭按钮
public void ClickCloseBtn() public void ClickCloseBtn()
{ {
transform.gameObject.SetActive(false); transform.gameObject.SetActive(false);
} }
//获取鼠标点击位置的信息 //获取鼠标点击位置的信息
public void GetData() public void GetData()
{
ManagerPanel managerPanel = new ManagerPanel();
// 当鼠标左键按下时进行检测
if (Input.GetMouseButtonDown(0))
{ {
// 确保 raycaster 和 eventSystem 不为空 ManagerPanel managerPanel = new ManagerPanel();
if (raycaster == null || eventSystem == null)
// 当鼠标左键按下时进行检测
if (Input.GetMouseButtonDown(0))
{ {
Debug.LogError("Raycaster 或 EventSystem 未正确分配,请在 Inspector 中进行分配。"); // 确保 raycaster 和 eventSystem 不为空
return; if (raycaster == null || eventSystem == null)
}
// 创建 PointerEventData 来记录点击事件的数据
PointerEventData pointerData = new PointerEventData(eventSystem);
pointerData.position = Input.mousePosition; // 获取鼠标点击的位置
// 用于存储射线检测的结果
List<RaycastResult> results = new List<RaycastResult>();
// 射线检测 UI
raycaster.Raycast(pointerData, results);
// 遍历射线检测的结果
foreach (RaycastResult result in results)
{
// 检测到点击了按钮
Button clickedButton = result.gameObject.GetComponent<Button>();
if (clickedButton != null)
{ {
Text buttonText = clickedButton.GetComponentInChildren<Text>(); Debug.LogError("Raycaster 或 EventSystem 未正确分配,请在 Inspector 中进行分配。");
if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息 return;
}
// 创建 PointerEventData 来记录点击事件的数据
PointerEventData pointerData = new PointerEventData(eventSystem);
pointerData.position = Input.mousePosition; // 获取鼠标点击的位置
// 用于存储射线检测的结果
List<RaycastResult> results = new List<RaycastResult>();
// 射线检测 UI
raycaster.Raycast(pointerData, results);
// 遍历射线检测的结果
foreach (RaycastResult result in results)
{
// 检测到点击了按钮
Button clickedButton = result.gameObject.GetComponent<Button>();
DutyItem item = clickedButton.GetComponentInParent<DutyItem>();
if (clickedButton != null)
{ {
name = buttonText.text; Text buttonText = clickedButton.GetComponentInChildren<Text>();
Debug.Log(name); if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息
selectedInfo.name = name; {
isPersonSelected = true; // 选择了人员 name = buttonText.text;
} Debug.Log(name);
else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息 selectedInfo.name = name;
{ isPersonSelected = true; // 选择了人员
scene = buttonText.text; }
Debug.Log(scene); else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息
selectedInfo.scene = scene; {
isSceneSelected = true; // 选择了场景 scene = buttonText.text;
} Debug.Log(scene);
else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息 selectedInfo.scene = scene;
{ isSceneSelected = true; // 选择了场景
duty = buttonText.text; }
Debug.Log(duty); else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息
selectedInfo.duty = duty; {
isDutySelected = true; // 选择了职责 duty = buttonText.text;
dutyId = item.dutyId;
selectedInfo.duty = duty;
isDutySelected = true; // 选择了职责
}
} }
} }
}
// 根据选择情况,启用或禁用确认按钮 // 根据选择情况,启用或禁用确认按钮
UpdateConfirmButtonState(); UpdateConfirmButtonState();
}
} }
}
//==========================================================功能=========================================== //==========================================================功能===========================================
//判断是否能够点击按钮 //判断是否能够点击按钮
private void UpdateConfirmButtonState() private void UpdateConfirmButtonState()
{ {
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用 // 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected; sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
} }
//设置安排文字 //设置安排文字
public void SetText() public void SetText()
{ {
arrangeText.text = "[" + name + "]担任[" + duty + "],位于[" + scene + "]"; arrangeText.text = "[" + name + "]担任[" + duty + "],位于[" + scene + "]";
} }
//筛选 //筛选
public void SetInputFile() public void SetInputFile()
{
// 获取输入框内容
string filterText = shaixuaninputField.text.Trim();
// 遍历所有已实例化的人员预制体
foreach (Transform child in peopleCountent)
{ {
// 获取该子物体上的 Text 组件 // 获取输入框内容
Text personNameText = child.GetComponentInChildren<Text>(); string filterText = shaixuaninputField.text.Trim();
if (personNameText != null) // 遍历所有已实例化的人员预制体
foreach (Transform child in peopleCountent)
{ {
// 比较输入框中的内容与人员姓名 // 获取该子物体上的 Text 组件
if (personNameText.text.Contains(filterText)) Text personNameText = child.GetComponentInChildren<Text>();
if (personNameText != null)
{ {
// 如果匹配,显示该人员 // 比较输入框中的内容与人员姓名
child.gameObject.SetActive(true); if (personNameText.text.Contains(filterText))
} {
else // 如果匹配,显示该人员
{ child.gameObject.SetActive(true);
// 如果不匹配,隐藏该人员 }
child.gameObject.SetActive(false); else
{
// 如果不匹配,隐藏该人员
child.gameObject.SetActive(false);
}
} }
} }
} }
}
// 点击选中角色,改变视觉效果(可复用) // 点击选中角色,改变视觉效果(可复用)
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)
{ {
@ -415,29 +408,30 @@ public class Panel : MonoBehaviour
// 更新人员列表的显示颜色 // 更新人员列表的显示颜色
private void UpdatePeopleListVisual() private void UpdatePeopleListVisual()
{
// 遍历所有已加载的人员预制体,检查是否已添加到场景
foreach (GameObject personItem in peopleList)
{ {
// 获取人员的名字和显示文本 // 遍历所有已加载的人员预制体,检查是否已添加到场景
Text personText = personItem.GetComponentInChildren<Text>(); foreach (GameObject personItem in peopleList)
if (personText != null)
{ {
// 检查该人员是否已经添加到当前场景 // 获取人员的名字和显示文本
bool isPersonAdded = sceneDataDictionary[selectedInfo.scene].Any(info => info.name == personText.text); Text personText = personItem.GetComponentInChildren<Text>();
// 如果该人员已经被添加到场景,改变颜色为灰色 if (personText != null)
if (isPersonAdded)
{ {
personText.color = Color.blue; // 已添加人员的颜色 // 检查该人员是否已经添加到当前场景
} bool isPersonAdded = sceneDataDictionary[selectedInfo.scene].Any(info => info.name == personText.text);
else
{ // 如果该人员已经被添加到场景,改变颜色为灰色
personText.color = Color.white; // 未添加人员的颜色 if (isPersonAdded)
{
personText.color = Color.blue; // 已添加人员的颜色
}
else
{
personText.color = Color.white; // 未添加人员的颜色
}
} }
} }
} }
} }
}

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);
} }