_xiaofang/xiaofang/Assets/Script/UI/PanelUI/EvacuationPanel.cs

566 lines
20 KiB
C#
Raw Normal View History

2024-12-01 19:24:07 +08:00
using System;
2024-11-29 09:47:47 +08:00
using System.Collections;
using System.Collections.Generic;
2024-12-11 21:28:05 +08:00
using System.Linq;
using System.Xml.Serialization;
2024-12-10 08:05:28 +08:00
using Unity.VisualScripting;
2024-11-29 09:47:47 +08:00
using UnityEngine;
2024-12-10 08:05:28 +08:00
using UnityEngine.Networking.Types;
2024-11-29 09:47:47 +08:00
using UnityEngine.UI;
using static System.Collections.Specialized.BitVector32;
2024-12-09 23:53:38 +08:00
using static UnityEditor.Progress;
2024-11-29 09:47:47 +08:00
public class EvacuationPanel : MonoBehaviour
{
2024-12-10 08:05:28 +08:00
public Dictionary<string, int> distributePeople = new Dictionary<string, int>();// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-02 01:46:57 +08:00
public List<PersonnelItem> personnelItems;
2024-11-29 09:47:47 +08:00
public Transform personnelContent;
public Panel panel;
public GameObject personnelPrefabs;
2024-11-29 16:20:58 +08:00
public GameObject classPrefab;
2024-12-10 15:02:05 +08:00
public GameObject classCount;//
public GameObject scenePrefab;//<2F><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
2024-12-10 18:14:08 +08:00
public Transform sceneCount;//<2F><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public GameObject jueseChoicePanel;
2024-11-29 16:20:58 +08:00
public Transform content;
2024-11-30 17:43:21 +08:00
public Text topText;
2024-12-10 08:05:28 +08:00
private GameObject selectedScene = null;//<2F><>ǰѡ<C7B0>г<EFBFBD><D0B3><EFBFBD>
2024-12-01 19:24:07 +08:00
public List<ClassItem> classItemList = new List<ClassItem>();
2024-12-01 22:24:03 +08:00
public List<ClassMate> classMateList = new List<ClassMate>();
2024-12-01 19:24:07 +08:00
2024-11-30 17:43:21 +08:00
[Header("ѧ<><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")]
public InputField StuCountInputField;
public Button CountsubmitBtn;
public Sprite rsprite;
public Sprite fsprite;
public GameObject JuesechoicePop;
2024-12-01 19:24:07 +08:00
public JueseChoicePop jc = new JueseChoicePop();
public JSONReader js;
2024-12-01 19:24:07 +08:00
2024-11-30 17:43:21 +08:00
[Header("<22>ܰ<EFBFBD>ť")]
public Button redistributeBtn;
public Button submitBtn;
2024-11-29 16:20:58 +08:00
2024-12-01 15:06:22 +08:00
[Header("Npc<70><63><EFBFBD><EFBFBD>")]
public int npcNum;
[Header("Npc<70><63><EFBFBD><EFBFBD>")]
public string npcType;
public string roleid;
2024-12-10 08:05:28 +08:00
[Header("<22>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD>б<EFBFBD>")]
List<int> nonZeroAreas = new List<int>();
Dictionary<int, PersonnelItem> personnelItemsDict = new Dictionary<int, PersonnelItem>();
private HashSet<int> excludedAreas = new HashSet<int>(); // <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD> ID
public SelectScenePanel selectScene;
2024-12-11 21:28:05 +08:00
private HashSet<int> clearedAreas = new HashSet<int>();
2024-11-29 09:47:47 +08:00
// Start is called before the first frame update
void Start()
{
SetNpcType();
2024-12-10 08:05:28 +08:00
nonZeroAreas= GetNonZeroNpcRatioAreas();
2024-12-01 19:24:07 +08:00
jc = JuesechoicePop.GetComponent<JueseChoicePop>();
2024-12-10 08:05:28 +08:00
//redistributeBtn.onClick.AddListener(ClearData);
redistributeBtn.onClick.AddListener(() =>
{
if (redistributeBtn.interactable)
{
Debug.Log("Redistribute button clicked!");
RedistributeLogic();
}
});
2024-12-02 01:46:57 +08:00
CountsubmitBtn.onClick.AddListener(Submit);
submitBtn.onClick.AddListener(totalSubmit);
2024-11-30 17:43:21 +08:00
StuCountInputField.onEndEdit.AddListener(CheckInput);
SetClass();
2024-11-29 09:47:47 +08:00
}
2024-12-10 08:05:28 +08:00
void Update()
{
CheckInput(StuCountInputField.text);
IsRedistribution();
IsOpen(selectScene.difficultyId);
}
//<2F>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>
2024-12-02 01:46:57 +08:00
public void totalSubmit()
2024-12-01 19:24:07 +08:00
{
2024-12-09 14:20:37 +08:00
Debug.Log(createTemplateInfo.Instance.auth_CreateTemplate + "===============");
NpcList nPC = new NpcList();
2024-12-11 16:36:27 +08:00
nPC.npcId = npcType;
nPC.areaId = roleid;
2024-12-09 14:20:37 +08:00
createTemplateInfo.Instance.auth_CreateTemplate.npcList = new List<NpcList>();
createTemplateInfo.Instance.auth_CreateTemplate.npcList.Add(nPC);
2024-12-11 15:50:06 +08:00
panel.panelToggle[3].interactable = true; // <20><><EFBFBD>õڶ<C3B5><DAB6><EFBFBD>Toggle
panel.panelToggle[3].gameObject.transform.GetComponent<Image>().sprite = panel.toggleImage[1];
panel.panelToggle[4].interactable = true; // <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>Toggle
panel.panelToggle[4].gameObject.transform.GetComponent<Image>().sprite = panel.toggleImage[1];
2024-12-01 19:24:07 +08:00
}
public void SetNpcType()
{
foreach (var scene in panel.sceneDataDictionary)
{
foreach (var npcData in js.locationDictionary)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
string roleLimit = npcData.Value.NpcRatio;
if(npcData.Value.NpcRatio=="-1")
{
continue;
}
else
{
// <20>Ȱ<EFBFBD><C8B0><EFBFBD>,<2C><><EFBFBD>ָ<EFBFBD>
string[] roleLimitSections = roleLimit.Split(',');
if (scene.Key == npcData.Value.Note)
{
// ֻ<>е<EFBFBD> scene.Key <20><> npcData.Value.Note ƥ<><C6A5>ʱ<EFBFBD><CAB1>ִ<EFBFBD><D6B4>
this.npcType = roleLimitSections[1];
roleid = roleLimitSections[0];
}
}
}
}
}
2024-12-02 01:46:57 +08:00
private void Submit()
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int count = int.Parse(StuCountInputField.text); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
StuCountInputField.text = "";
2024-12-10 08:05:28 +08:00
foreach (var item in personnelItems)
2024-12-02 01:46:57 +08:00
{
2024-12-10 08:05:28 +08:00
personnelItemsDict[item.sceneId] = item; // ʹ<><CAB9> sceneId <20><>Ϊ<EFBFBD><CEAA>
2024-12-02 01:46:57 +08:00
}
2024-12-10 08:05:28 +08:00
// <20><> nonZeroAreas ת<><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD> ID <20><><EFBFBD><EFBFBD>
int[] sceneIds = nonZeroAreas.ToArray();
2024-12-02 01:46:57 +08:00
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><E4B7BD>
var result = DistributePeopleWithBalance(sceneIds, personnelItemsDict, count);
2024-12-02 01:46:57 +08:00
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD><EFBFBD> UI <20><>ʾ
foreach (var kvp in result)
2024-12-02 01:46:57 +08:00
{
2024-12-10 08:05:28 +08:00
if (personnelItemsDict.ContainsKey(kvp.Key))
2024-12-02 01:46:57 +08:00
{
2024-12-10 08:05:28 +08:00
personnelItemsDict[kvp.Key].SetInfo(kvp.Value.ToString()); // <20><><EFBFBD><EFBFBD>UI
personnelItemsDict[kvp.Key].personnelImage.gameObject.SetActive(true);
2024-12-02 01:46:57 +08:00
}
}
}
2024-12-10 08:05:28 +08:00
public Dictionary<int, int> DistributePeopleWithBalance(int[] scenes, Dictionary<int, PersonnelItem> personnelItemsDict, int totalPeople)
2024-12-02 01:46:57 +08:00
{
2024-12-10 08:05:28 +08:00
// 1. <20><><EFBFBD>㵱ǰÿ<C7B0><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> + <20>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Dictionary<int, int> totalPeoplePerScene = new Dictionary<int, int>();
2024-12-02 01:46:57 +08:00
foreach (var scene in scenes)
{
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD><EFBFBD> personnelItemsDict <20>а<EFBFBD><D0B0><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ 0
if (personnelItemsDict.ContainsKey(scene))
2024-12-02 01:46:57 +08:00
{
2024-12-10 08:05:28 +08:00
totalPeoplePerScene[scene] = personnelItemsDict[scene].Num; // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
2024-12-02 01:46:57 +08:00
}
else
{
2024-12-10 08:05:28 +08:00
totalPeoplePerScene[scene] = 0;
2024-12-02 01:46:57 +08:00
}
2024-12-10 08:05:28 +08:00
// Debug <20><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
Debug.Log($"Scene {scene}: Initial People = {totalPeoplePerScene[scene]}");
2024-12-02 01:46:57 +08:00
}
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Dictionary<int, int> initialPeoplePerScene = new Dictionary<int, int>(totalPeoplePerScene);
// 2. <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int remainingPeople = totalPeople;
while (remainingPeople > 0)
2024-12-02 01:46:57 +08:00
{
2024-12-10 08:05:28 +08:00
// <20>ҳ<EFBFBD><D2B3><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٵ<EFBFBD><D9B5><EFBFBD><EFBFBD><EFBFBD>
int minScene = -1; // <20><><EFBFBD>ڼ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٵij<D9B5><C4B3><EFBFBD> ID
int minPeople = int.MaxValue;
foreach (var scene in totalPeoplePerScene)
{
if (scene.Value < minPeople)
{
minPeople = scene.Value;
minScene = scene.Key;
}
}
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> NPC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٵ<EFBFBD><D9B5><EFBFBD><EFBFBD><EFBFBD>
if (minScene != -1) // ȷ<><C8B7><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Ч<EFBFBD>ij<EFBFBD><C4B3><EFBFBD>
{
totalPeoplePerScene[minScene]++;
remainingPeople--;
}
else
{
break; // <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Ч<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
}
2024-12-02 01:46:57 +08:00
}
2024-12-10 08:05:28 +08:00
// 3. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
Dictionary<int, int> allocatedPeople = new Dictionary<int, int>();
foreach (var scene in totalPeoplePerScene)
{
int initialPeople = initialPeoplePerScene.GetValueOrDefault(scene.Key, 0);
allocatedPeople[scene.Key] = scene.Value - initialPeople; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
}
2024-12-02 01:46:57 +08:00
2024-12-10 08:05:28 +08:00
return allocatedPeople;
}
2024-12-02 01:46:57 +08:00
2024-12-10 08:05:28 +08:00
//<2F><><EFBFBD><EFBFBD>
2024-12-10 18:14:08 +08:00
//private void ClearData()
//{
// jc.classItem.isSet = false;
// foreach (var item in classItemList)
// {
// item.isSet = false;
// item.setClassItem("");
// }
// jc.classMate.isBeSet = false;
// foreach(var item in jc.classMateList)
// {
// item.isBeSet = false;
// item.setName();
// }
//}
2024-12-01 19:24:07 +08:00
2024-12-10 08:05:28 +08:00
//<2F>ж<EFBFBD>NPC<50>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ơ<EFBFBD>
public List<int> GetNonZeroNpcRatioAreas()
2024-11-29 09:47:47 +08:00
{
2024-12-10 08:05:28 +08:00
List<int> nonZeroAreas = new List<int>();
foreach (var sceneEntry in panel.sceneDataDictionary)
{
foreach (var sceneInfo in sceneEntry.Value)
{
foreach (var npcData in js.locationDictionary)
{
LocationData locationData = npcData.Value;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID ƥ<>䵱ǰ NPC <20><> ID
2024-12-12 15:21:07 +08:00
if (locationData.ID == int.Parse(sceneInfo.sceneId))
2024-12-10 08:05:28 +08:00
{
// <20><>ȡÿ<C8A1><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NpcRatio <20>ֶ<EFBFBD>
string npcRatio = locationData.NpcRatio;
// <20><> NpcRatio <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD> '|' <20>ָ<D6B8><EEA3AC>ȡÿһ<C3BF><D2BB>
string[] npcRatioEntries = npcRatio.Split('|');
// <20><><EFBFBD><EFBFBD>ÿһ<C3BF><D2BB>
foreach (var entry in npcRatioEntries)
{
// <20><>ÿһ<C3BF> ',' <20>ָ<D6B8><EEA3AC>ȡ<EFBFBD>¹<EFBFBD>λ<EFBFBD>á<EFBFBD>NPCID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string[] entryData = entry.Split(',');
if (entryData.Length == 4)
{
string allocationRatio = entryData[3]; // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ϊ "0" <20><> "-1"
if (allocationRatio != "0" && allocationRatio != "-1")
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID <20><><EFBFBD>ӵ<EFBFBD><D3B5>б<EFBFBD>
nonZeroAreas.Add(locationData.ID);
Debug.Log("locationData.ID"+ locationData.ID);
break; // һ<><D2BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Ч<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2>ټ<EFBFBD><D9BC>鵱ǰ<E9B5B1><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
}
}
}
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID
foreach (var area in nonZeroAreas)
{
Debug.Log("<22><><EFBFBD><EFBFBD> ID<49><44>" + area);
}
// <20><><EFBFBD>ط<EFBFBD><D8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID <20>б<EFBFBD>
return nonZeroAreas;
2024-11-29 09:47:47 +08:00
}
2024-12-10 08:05:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0B3A1><EFBFBD><EFBFBD>ʾ
2024-11-29 09:47:47 +08:00
public void SetPersonnel()
{
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>UI<55><49>
2024-11-29 09:47:47 +08:00
foreach (Transform child in personnelContent)
{
Destroy(child.gameObject);
}
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>б<EFBFBD>
personnelItems.Clear();
2024-11-29 09:47:47 +08:00
foreach (var sceneEntry in panel.sceneDataDictionary)
{
2024-12-10 08:05:28 +08:00
foreach (var sceneInfo in sceneEntry.Value)
{
2024-12-12 15:21:07 +08:00
LocationData area = js.GetAreaDateById(int.Parse(sceneInfo.sceneId));
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD><EFBFBD>NpcRatio<69><6F>Ϊ"-1"<22><>ʾ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>Ч
if (area.NpcRatio != "-1")
{
// <20><><EFBFBD><EFBFBD> personnelItems <20>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sceneText.text
var existingItem = personnelItems.Find(item => item.sceneText.text == sceneEntry.Key);
if (existingItem != null)
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD> Num
existingItem.Num++;
}
else
{
// <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD> personnelItem<65><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GameObject item = GameObject.Instantiate(personnelPrefabs, personnelContent);
PersonnelItem personnelItem = item.GetComponent<PersonnelItem>();
Button button = personnelItem.transform.Find("sceneText").GetComponent<Button>();
personnelItem.sceneText.text = sceneEntry.Key;
personnelItem.sceneId = area.ID;
personnelItem.Num = 1; // <20><><EFBFBD>ó<EFBFBD>ʼֵΪ 1
button.onClick.AddListener(() =>
{
OnSceneItemClicked(item, Color.yellow, selectedScene);
2024-12-10 18:14:08 +08:00
foreach (Transform child in sceneCount)
{
Destroy(child.gameObject);
}
LocationData locationData = js.GetAreaDateById(personnelItem.sceneId);
if(locationData.Level.ToString() != "0")
{
GameObject levelItem = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
Button levelBtn = levelItem.transform.Find("chooseBtn2").GetComponent<Button>();
levelBtn.onClick.AddListener(() =>
{
2024-12-10 23:24:15 +08:00
JueseChoicePop jueseChoicePop= jueseChoicePanel.gameObject.GetComponent<JueseChoicePop>();
jueseChoicePop.SetClass(personnelItem.sceneId);
2024-12-11 01:32:11 +08:00
jueseChoicePanel.gameObject .SetActive(true);
2024-12-10 18:14:08 +08:00
});
ClassItem classItem = levelItem.GetComponent<ClassItem>();
classItem.classname.text = locationData.Level.ToString();
}
2024-12-10 08:05:28 +08:00
});
//Debug.Log("New PersonnelItem created. SceneId: " + personnelItem.sceneId + ", Num: " + personnelItem.Num);
personnelItems.Add(personnelItem);
}
}
else
{
break; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NpcRatioΪ-1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰѭ<C7B0><D1AD>
}
}
}
}
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>·<EFBFBD><C2B7>䰴ť<E4B0B4>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD>
public void IsRedistribution()
{
// <20><><EFBFBD><EFBFBD> personnelItemsDict<63><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>κ<EFBFBD> PersonnelItem <20><> gameObject <20><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>״̬
bool canRedistribute = false;
foreach (var kvp in personnelItemsDict)
{
if (kvp.Value.personnelImage.gameObject.activeSelf) // <20><><EFBFBD><EFBFBD> gameObject <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ
{
canRedistribute = true;
break;
}
2024-11-29 09:47:47 +08:00
}
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>䰴ť<E4B0B4>Ľ<EFBFBD><C4BD><EFBFBD>״̬
redistributeBtn.interactable = canRedistribute;
2024-11-29 09:47:47 +08:00
}
2024-12-10 15:02:05 +08:00
2024-11-30 17:43:21 +08:00
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>1
void CheckInput(string input)
{
// <20><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
if (float.TryParse(input, out float result))
{
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>1
if (result > 1)
{
CountsubmitBtn.GetComponent<Image>().sprite = rsprite;
2024-12-10 08:05:28 +08:00
CountsubmitBtn.onClick.AddListener(Countsubmit);
2024-12-04 16:37:51 +08:00
}
2024-11-30 17:43:21 +08:00
}
}
2024-12-10 15:02:05 +08:00
//Npc<70><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ð<EFBFBD>ť<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
2024-11-30 17:43:21 +08:00
public void Countsubmit()
{
//<2F><>ť<EFBFBD>û<EFBFBD>
CountsubmitBtn.GetComponent<Image>().sprite = fsprite;
StuCountInputField.text = string.Empty;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Npc<70><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CountsubmitBtn.onClick.RemoveAllListeners();
}
2024-12-10 08:05:28 +08:00
2024-11-30 17:43:21 +08:00
//<2F><><EFBFBD><EFBFBD>ID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void SettopText()
{
topText.text = "<22><><EFBFBD>°༶<C2B0><E0BCB6>Ҫ<EFBFBD><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʦ<EFBFBD><CAA6>";
topText.text = "<22><><EFBFBD><EFBFBD>¥<EFBFBD><C2A5><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD>ʦ<EFBFBD><CAA6>";
}
2024-12-10 08:05:28 +08:00
2024-11-30 17:43:21 +08:00
//ʵ<><CAB5><EFBFBD><EFBFBD>ClassItem
public void SetClass()
{
for (int i = 0; i < 10; i++)
{
GameObject item = GameObject.Instantiate<GameObject>(classPrefab, content);
ClassItem classItem = item.GetComponent<ClassItem>();
classItem.JuesechoicePop = JuesechoicePop;
2024-12-01 19:24:07 +08:00
classItemList.Add(classItem);
2024-11-30 17:43:21 +08:00
}
}
2024-12-10 08:05:28 +08:00
//<2F><><EFBFBD>·<EFBFBD><C2B7><EFBFBD>
public void RedistributeLogic()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD> NPC <20><><EFBFBD><EFBFBD>
int totalRedistributePeople = 0;
foreach (var kvp in personnelItemsDict)
{
PersonnelItem item = kvp.Value;
// <20><><EFBFBD><EFBFBD> gameObject <20>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>ʾ<EFBFBD><CABE>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD> NPC
if (item.personnelImage.gameObject.activeSelf)
{
totalRedistributePeople += item.Num; // <20>ۼ<EFBFBD><DBBC><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD> NPC <20><><EFBFBD><EFBFBD>
item.Num = 0; // <20><><EFBFBD>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NPC <20><><EFBFBD><EFBFBD>
2024-12-11 21:28:05 +08:00
item.SetInfo(""); // <20><><EFBFBD><EFBFBD> UI <20><>ʾ
2024-12-10 08:05:28 +08:00
item.personnelImage.gameObject.SetActive(false); // <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
excludedAreas.Add(kvp.Key); // <20><>¼<EFBFBD><C2BC><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD> ID
Debug.Log($"Cleared NPCs from Scene ID: {kvp.Key}");
}
}
// ׼<><D7BC><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD>ų<EFBFBD><C5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
List<int> validAreas = new List<int>();
foreach (var kvp in personnelItemsDict)
{
if (!excludedAreas.Contains(kvp.Key)) // <20>ų<EFBFBD><C5B3><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
{
validAreas.Add(kvp.Key);
}
}
// <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
if (validAreas.Count == 0)
{
Debug.LogWarning("No valid areas available for redistribution.");
return;
}
// <20><><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
int[] validSceneIds = validAreas.ToArray();
// <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><E4B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NPC <20><><EFBFBD><EFBFBD><E4B5BD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
var redistributionResult = DistributePeopleWithBalance(validSceneIds, personnelItemsDict, totalRedistributePeople);
// <20><><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UI
foreach (var kvp in redistributionResult)
{
if (personnelItemsDict.ContainsKey(kvp.Key))
{
personnelItemsDict[kvp.Key].Num += kvp.Value; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
personnelItemsDict[kvp.Key].SetInfo(personnelItemsDict[kvp.Key].Num.ToString()); // <20><><EFBFBD><EFBFBD> UI <20><>ʾ
personnelItemsDict[kvp.Key].personnelImage.gameObject.SetActive(true); // ȷ<><C8B7>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ʾ
personnelItemsDict[kvp.Key].personnelNum.gameObject.SetActive(true); // ȷ<><C8B7>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ʾ
Debug.Log($"Assigned {kvp.Value} NPCs to Scene ID: {kvp.Key}");
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
public void OnSceneItemClicked(GameObject clickedItem, Color color, GameObject select)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮ǰѡ<C7B0>еĽ<D0B5>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӿ<EFBFBD>Ч<EFBFBD><D0A7>
if (selectedScene != null && select != clickedItem)
{
Text prevText = selectedScene.GetComponentInChildren<Text>();
if (prevText != null)
{
prevText.fontSize = 32; // <20>ָ<EFBFBD>ԭʼ<D4AD>ֺ<EFBFBD>
prevText.color = Color.white; // <20>ָ<EFBFBD>ԭʼ<D4AD><CABC>ɫ
}
}
// <20><><EFBFBD>õ<EFBFBD>ǰѡ<C7B0>еĽ<D0B5>ɫΪѡ<CEAA><D1A1>״̬
selectedScene = clickedItem; // <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Text personText = clickedItem.GetComponentInChildren<Text>();
if (personText != null)
{
// <20>ֺű<D6BA><C5B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>״̬<D7B4><CCAC>
personText.fontSize = 36;
personText.color = color; // ѡ<><D1A1><EFBFBD><EFBFBD>ɫ
}
}
//<2F>жϷֹ<CFB7><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
public void IsOpen(int id)
{
if (selectScene.difficultyId > 3)
{
classCount.gameObject.SetActive(true);
}
else
{
classCount.gameObject.SetActive(false);
}
}
2024-12-11 21:28:05 +08:00
//// 1. <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NPC<50><43><EFBFBD><EFBFBD><E4B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//public void RedistributeNpc(int selectedAreaId)
//{
// // <20><>ȡ<EFBFBD><C8A1><EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>ID
// var availableAreas = GetNonZeroNpcRatioAreas().Where(areaId => areaId != selectedAreaId && !clearedAreas.Contains(areaId)).ToList();
// // <20><>ѡ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡNPC
// int npcToRedistribute = distributePeople[selectedAreaId.ToString()];
// if (npcToRedistribute == 0) return;
// // <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NPC
// distributePeople[selectedAreaId.ToString()] = 0;
// //personnelItemsDict[selectedAreaId].UpdateNpcCount(0); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI<55>ķ<EFBFBD><C4B7><EFBFBD>
// // <20><><EFBFBD><EFBFBD>ЩNPC<50><43><EFBFBD><EFBFBD><E4B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// DistributeNpcToOtherAreas(npcToRedistribute, availableAreas);
//}
//// 2. <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NPC<50>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID<49><44><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ʱ<EFBFBD><CAB1>Щ<EFBFBD><D0A9><EFBFBD>򲻲<EFBFBD><F2B2BBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//private void DistributeNpcToOtherAreas(int npcToRedistribute, List<int> availableAreas)
//{
// if (availableAreas.Count == 0) return;
2024-12-10 08:05:28 +08:00
2024-12-11 21:28:05 +08:00
// // <20>򵥵ľ<F2B5A5B5><C4BE>ַ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>޸ķ<DEB8><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// int npcPerArea = npcToRedistribute / availableAreas.Count;
// foreach (var areaId in availableAreas)
// {
// distributePeople[areaId.ToString()] += npcPerArea;
// //personnelItemsDict[areaId].UpdateNpcCount(distributePeople[areaId]);
// }
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD>NPC<50><43><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// int remainder = npcToRedistribute % availableAreas.Count;
// for (int i = 0; i < remainder; i++)
// {
// distributePeople[availableAreas[i]] += 1;
// //personnelItemsDict[availableAreas[i]].UpdateNpcCount(distributePeople[availableAreas[i]]);
// }
//}
//// <20><><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ô˷<C3B4><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//public void MarkAreaAsCleared(int areaId)
//{
// clearedAreas.Add(areaId);
//}
2024-11-29 09:47:47 +08:00
}