From 5af6fe0d544e88ebdb88384d57f26c98e7a8fcbb Mon Sep 17 00:00:00 2001 From: huyulong <1838407198@qq.com> Date: Mon, 2 Dec 2024 01:46:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E6=80=A5=E4=BA=BA=E7=BE=A4=E5=85=AC?= =?UTF-8?q?=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Scenes/Schedule_03333333333.unity | 49 +++--- .../Script/UI/PanelUI/EvacuationPanel.cs | 156 +++++++++++++++++- xiaofang/Assets/Script/UI/PersonnelItem.cs | 6 + 3 files changed, 188 insertions(+), 23 deletions(-) diff --git a/xiaofang/Assets/Scenes/Schedule_03333333333.unity b/xiaofang/Assets/Scenes/Schedule_03333333333.unity index 5751bc3a..958dae83 100644 --- a/xiaofang/Assets/Scenes/Schedule_03333333333.unity +++ b/xiaofang/Assets/Scenes/Schedule_03333333333.unity @@ -2113,6 +2113,7 @@ MonoBehaviour: scenePanelPrefab: {fileID: 6740850324693622957, guid: a15ee694d5f79864d816998fae77116d, type: 3} peopleWindowsPrefab: {fileID: 7318934474885050405} personnelPanel: {fileID: 5900002971020626571, guid: 297444ab6ae692b4dbcb38d34e0c5716, type: 3} + jsonReader: {fileID: 0} sceneText: {fileID: 0} scrollRect: {fileID: 1435623615} panelInfo: {fileID: 618256462} @@ -2241,9 +2242,11 @@ MonoBehaviour: name: duty: scene: + peopleList: [] managerPanel1: {fileID: 617308873} jsonReader1: {fileID: 1417128757} - selectScenePanel: {fileID: 0} + selectScenePanel: {fileID: 7468736063766935910, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3} + datePanel: {fileID: 7187413038405322106, guid: 26d5710936f5f7d468eb5eb9da96112e, type: 3} --- !u!1 &625672672 GameObject: m_ObjectHideFlags: 0 @@ -10609,7 +10612,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2102021660636739381, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_SizeDelta.x - value: -361.72 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2102021660636739381, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_SizeDelta.y @@ -10663,6 +10666,10 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 2102021661112157380, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} + propertyPath: m_Horizontal + value: 0 + objectReference: {fileID: 0} - target: {fileID: 2102021661231301985, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMax.y value: 0 @@ -10705,19 +10712,19 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4764228630658219266, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228630658219266, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228630658219266, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchoredPosition.x - value: 190.05 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228630658219266, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchoredPosition.y - value: -23.991 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228630805767484, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_Name @@ -10725,7 +10732,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4764228630805767484, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_IsActive - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 4764228630805767485, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_Pivot.x @@ -10813,59 +10820,59 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4764228631245731675, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_SizeDelta.x - value: 249.00002 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228631278755135, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_SizeDelta.x - value: 629.702 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228631451568083, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228631451568083, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228631451568083, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchoredPosition.x - value: 133.7755 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228631451568083, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchoredPosition.y - value: -39.08695 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228632225803364, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228632225803364, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228632225803364, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchoredPosition.x - value: 58.95 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228632225803364, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchoredPosition.y - value: -23.991 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228632238488446, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228632238488446, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228632238488446, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchoredPosition.x - value: 495.9265 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4764228632238488446, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_AnchoredPosition.y - value: -39.08695 + value: 0 objectReference: {fileID: 0} - target: {fileID: 9196293257107006892, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} propertyPath: m_IsActive diff --git a/xiaofang/Assets/Script/UI/PanelUI/EvacuationPanel.cs b/xiaofang/Assets/Script/UI/PanelUI/EvacuationPanel.cs index 111279b2..b3fbdf88 100644 --- a/xiaofang/Assets/Script/UI/PanelUI/EvacuationPanel.cs +++ b/xiaofang/Assets/Script/UI/PanelUI/EvacuationPanel.cs @@ -6,6 +6,9 @@ using UnityEngine.UI; public class EvacuationPanel : MonoBehaviour { + public Dictionary distributePeople = new Dictionary(); + public List personnelItems; + public Transform personnelContent; public Panel panel; public GameObject personnelPrefabs; @@ -38,17 +41,165 @@ public class EvacuationPanel : MonoBehaviour jc = JuesechoicePop.GetComponent(); redistributeBtn.onClick.AddListener(ClearData); - submitBtn.onClick.AddListener(Submit); + CountsubmitBtn.onClick.AddListener(Submit); + submitBtn.onClick.AddListener(totalSubmit); StuCountInputField.onEndEdit.AddListener(CheckInput); SetClass(); } - private void Submit() + + public void totalSubmit() { + foreach(var item in createTemplateInfo.Instance.auth_CreateTemplate.npcList) + { + + } } + + + + + //private void Submit() + //{ + // //int count = int.Parse(StuCountInputField.text);//总人数 + // //StuCountInputField.text = ""; + // //int initialPeople = panel.sceneDataDictionary.Keys.Count* panel.sceneDataDictionary.Values.Count;//已经分了的人 + // //string[] sceneNames = { }; + // //for(int i = 0; i< panel.sceneDataDictionary.Keys.Count;i++)//拿场景名称 + // //{ + // // foreach(var item in panel.sceneDataDictionary.Keys) + // // { + // // sceneNames[i] = item; + // // } + // //} + + // //distributePeople = DistributePeople(sceneNames, initialPeople, count); + + // //foreach(var item in distributePeople) + // //{ + // // Debug.Log(item.Value); + // //} + + // int count = int.Parse(StuCountInputField.text); // 总人数 + // StuCountInputField.text = ""; + + // // 已经分配的人员数量 + // int initialPeople = panel.sceneDataDictionary.Keys.Count * panel.sceneDataDictionary.Values.Count; + + // // 动态创建sceneNames数组,大小为场景数量 + // string[] sceneNames = new string[panel.sceneDataDictionary.Keys.Count]; + + // // 遍历场景数据字典并填充sceneNames数组 + // int i = 0; + // foreach (var item in panel.sceneDataDictionary.Keys) + // { + // sceneNames[i] = item; + // i++; + // } + + // // 调用分配人员函数 + // distributePeople = DistributePeople(sceneNames, initialPeople, count); + + // // 输出分配结果 + // foreach (var item in distributePeople) + // { + // //Debug.Log(item.Value); + + // foreach(var a in personnelItems) + // { + // a.SetInfo(item.Value.ToString()); + // } + // } + + //} + + private void Submit() + { + // 获取输入的总人数 + int count = int.Parse(StuCountInputField.text); // 总人数 + StuCountInputField.text = ""; + + // 计算已分配的人员数量 + int initialPeople = 0; + foreach (var item in panel.sceneDataDictionary.Values) + { + initialPeople += item.Count; // 假设每个场景的Value是一个List或类似的结构,其中包含该场景下的所有人员 + } + + // 动态创建sceneNames数组,大小为场景数量 + string[] sceneNames = new string[panel.sceneDataDictionary.Keys.Count]; + + // 填充sceneNames数组 + int i = 0; + foreach (var item in panel.sceneDataDictionary.Keys) + { + sceneNames[i] = item; + i++; + } + + // 调用分配人员函数(假设该函数处理人员分配的逻辑) + distributePeople = DistributePeople(sceneNames, initialPeople, count); + + // 输出分配结果 + foreach (var item in distributePeople) + { + // 假设 personnelItems 是存储UI元素的列表 + foreach (var a in personnelItems) + { + a.SetInfo(item.Value.ToString()); + } + } + } + + public static Dictionary DistributePeople(string[] scenes, int initialPeople, int totalPeople) + { + // 1. 计算已分配的人员数 + int totalAssigned = initialPeople; + + //foreach (var scene in scenes) + //{ + // if (initialPeople.ContainsKey(scene)) + // { + // totalAssigned += initialPeople[scene]; + // } + //} + + // 2. 计算剩余人员数 + int remainingPeople = totalPeople - totalAssigned; + + // 3. 将剩余人员平均分配到所有场景中 + Dictionary finalDistribution = new Dictionary(initialPeople); + int peoplePerScene = remainingPeople / scenes.Length; + int extraPeople = remainingPeople % scenes.Length; // 计算余数 + + // 4. 每个场景分配均等的人员 + foreach (var scene in scenes) + { + if (finalDistribution.ContainsKey(scene)) + { + finalDistribution[scene] += peoplePerScene; // 均分的人员 + } + else + { + finalDistribution[scene] = peoplePerScene; // 新场景初始化 + } + } + + // 5. 随机分配余数人员 + System.Random rand = new System.Random(); + for (int i = 0; i < extraPeople; i++) + { + string randomScene = scenes[rand.Next(scenes.Length)]; + finalDistribution[randomScene]++; + } + + return finalDistribution; + } + + private void ClearData() { jc.classItem.isSet = false; @@ -84,6 +235,7 @@ public class EvacuationPanel : MonoBehaviour { GameObject item = GameObject.Instantiate(personnelPrefabs, personnelContent); PersonnelItem personnelItem=item.GetComponent(); + personnelItems.Add(personnelItem); personnelItem.sceneText.text = sceneEntry.Key; personnelItem.personnelNum.text = sceneEntry.Value.Count.ToString(); } diff --git a/xiaofang/Assets/Script/UI/PersonnelItem.cs b/xiaofang/Assets/Script/UI/PersonnelItem.cs index 7f231304..2a1716d0 100644 --- a/xiaofang/Assets/Script/UI/PersonnelItem.cs +++ b/xiaofang/Assets/Script/UI/PersonnelItem.cs @@ -16,6 +16,12 @@ public class PersonnelItem : MonoBehaviour } + public void SetInfo(string s) + { + personnelNum.text = s; + } + + // Update is called once per frame void Update() {