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

460 lines
16 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-12-17 22:55:13 +08:00
using UnityEditor.Experimental.GraphView;
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-13 15:30:41 +08:00
public List<PersonnelItem> personnelItems;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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-17 22:55:13 +08:00
public Sprite[] showImage;
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-17 17:04:12 +08:00
public int isHere;
2024-12-10 08:05:28 +08:00
[Header("<22>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD>б<EFBFBD>")]
List<int> nonZeroAreas = new List<int>();
public SelectScenePanel selectScene;
2024-12-17 22:55:13 +08:00
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public List<int> clearRegion=new List<int>();
2024-11-29 09:47:47 +08:00
// Start is called before the first frame update
void Start()
{
2024-12-17 17:44:06 +08:00
redistributeBtn.interactable = false;
2024-12-17 22:55:13 +08:00
ChangeImage(redistributeBtn.interactable);
2024-12-01 19:24:07 +08:00
jc = JuesechoicePop.GetComponent<JueseChoicePop>();
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);
2024-12-17 16:01:03 +08:00
SetScene();
2024-11-30 17:43:21 +08:00
SetClass();
2024-11-29 09:47:47 +08:00
}
2024-12-10 08:05:28 +08:00
void Update()
{
CheckInput(StuCountInputField.text);
2024-12-17 17:04:12 +08:00
//IsRedistribution();
2024-12-10 08:05:28 +08:00
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
createTemplateInfo.Instance.auth_CreateTemplate.npcList = new List<NpcList>();
2024-12-17 17:44:06 +08:00
foreach(var npcInfo in personnelItems)
{
NpcList nPC = new NpcList();
nPC.npcId = npcInfo.npcId.ToString();
nPC.areaId = npcInfo.sceneId.ToString();
nPC.isHere=npcInfo.isHere;
nPC.npcNum = npcInfo.NpcNum;
2024-12-17 17:44:06 +08:00
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
}
2024-12-16 15:57:15 +08:00
//<2F><><EFBFBD><EFBFBD>Npc<70><63><EFBFBD><EFBFBD>
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
2024-12-13 15:30:41 +08:00
//<2F><><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD><E1BDBB>ť
public void Submit()
2024-12-02 01:46:57 +08:00
{
2024-12-17 16:01:03 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
int count;
if (!int.TryParse(StuCountInputField.text, out count) || count <= 0)
2024-12-02 01:46:57 +08:00
{
2024-12-17 16:01:03 +08:00
Debug.LogError("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return;
2024-12-02 01:46:57 +08:00
}
2024-12-17 16:01:03 +08:00
2024-12-17 22:55:13 +08:00
//StuCountInputField.text = "";
2024-12-17 16:01:03 +08:00
2024-12-10 08:05:28 +08:00
// <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><E4B7BD>
2024-12-17 16:01:03 +08:00
var result = DistributeNpcByRatio(personnelItems, count);
// <20><><EFBFBD><EFBFBD> UI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-10 08:05:28 +08:00
foreach (var kvp in result)
2024-12-02 01:46:57 +08:00
{
2024-12-17 16:01:03 +08:00
PersonnelItem item = personnelItems.Find(p => p.sceneId == kvp.Key);
if (item != null)
2024-12-02 01:46:57 +08:00
{
2024-12-17 16:01:03 +08:00
item.SetInfo(kvp.Value.ToString()); // <20><><EFBFBD><EFBFBD>UI<55><49>ʾ
item.NpcNum = kvp.Value; // <20><><EFBFBD><EFBFBD>Npc<70><63><EFBFBD><EFBFBD>
2024-12-17 17:44:06 +08:00
2024-12-17 16:01:03 +08:00
item.personnelImage.gameObject.SetActive(true); // <20><>ʾͼ<CABE><CDBC>
Debug.Log($"Scene ID: {kvp.Key}, Assigned NPC Count: {kvp.Value}");
2024-12-02 01:46:57 +08:00
}
}
}
2024-12-17 16:01:03 +08:00
//Npc<70><63><EFBFBD><EFBFBD>
public Dictionary<int, int> DistributeNpcByRatio(List<PersonnelItem> personnelItems, int totalNpcCount)
2024-12-02 01:46:57 +08:00
{
2024-12-17 16:01:03 +08:00
Dictionary<int, float> sceneRatios = new Dictionary<int, float>(); // <20><EFBFBD><E6B4A2><EFBFBD><EFBFBD>ID<49>ͱ<EFBFBD><CDB1><EFBFBD>
float totalRatio = 0; // <20><><EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>֮<EFBFBD><D6AE>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򣬽<EFBFBD><F2A3ACBD><EFBFBD>NpcRatio<69><6F><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach (var item in personnelItems)
2024-12-02 01:46:57 +08:00
{
2024-12-17 16:01:03 +08:00
LocationData locationData = js.GetAreaDateById(item.sceneId);
string[] allLimits = locationData.NpcRatio.Split('|'); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach (string limit in allLimits)
2024-12-10 08:05:28 +08:00
{
2024-12-17 16:01:03 +08:00
string[] parts = limit.Split(',');
if (parts.Length >= 5) // ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
2024-12-10 08:05:28 +08:00
{
2024-12-17 16:01:03 +08:00
int sceneId = item.sceneId; // ʹ<><CAB9> PersonnelItem <20><> sceneId
float ratio = float.Parse(parts[4]); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-17 17:44:06 +08:00
item.npcId = int.Parse(parts[2]);
item .isHere=int.Parse(parts[3]);
2024-12-17 16:01:03 +08:00
if (!sceneRatios.ContainsKey(sceneId))
{
sceneRatios.Add(sceneId, ratio);
totalRatio += ratio; // <20>ۼ<EFBFBD><DBBC><EFBFBD><EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
}
2024-12-10 08:05:28 +08:00
}
}
2024-12-02 01:46:57 +08:00
}
2024-12-17 16:01:03 +08:00
// <20><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>Ч<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7>ؿս<D8BF><D5BD><EFBFBD>
if (sceneRatios.Count == 0 || totalRatio == 0)
2024-12-10 08:05:28 +08:00
{
2024-12-17 16:01:03 +08:00
Debug.LogError(<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Ч<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return new Dictionary<int, int>();
2024-12-10 08:05:28 +08:00
}
2024-12-02 01:46:57 +08:00
2024-12-17 16:01:03 +08:00
// <20><><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Dictionary<int, int> finalDistribution = new Dictionary<int, int>();
int remainingNpc = totalNpcCount;
2024-12-10 08:05:28 +08:00
2024-12-17 16:01:03 +08:00
foreach (var entry in sceneRatios)
2024-12-10 08:05:28 +08:00
{
2024-12-17 16:01:03 +08:00
int allocatedNpc = Mathf.FloorToInt(totalNpcCount * (entry.Value / totalRatio)); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
finalDistribution[entry.Key] = allocatedNpc; // <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
remainingNpc -= allocatedNpc; // <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3>NPC<50><43><EFBFBD><EFBFBD>
2024-12-10 08:05:28 +08:00
}
2024-12-17 16:01:03 +08:00
// <20><>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٵij<D9B5><C4B3><EFBFBD>
while (remainingNpc > 0)
2024-12-10 08:05:28 +08:00
{
2024-12-17 16:01:03 +08:00
int minScene = finalDistribution.OrderBy(kvp => kvp.Value).First().Key; // <20>ҵ<EFBFBD><D2B5><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٵij<D9B5><C4B3><EFBFBD>
finalDistribution[minScene]++;
remainingNpc--;
2024-12-10 08:05:28 +08:00
}
2024-12-17 16:01:03 +08:00
return finalDistribution;
2024-11-29 09:47:47 +08:00
}
2024-12-16 15:57:15 +08:00
2024-12-16 17:11:22 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0B3A1><EFBFBD><EFBFBD>ʾ2.0
public void SetScene()
{
foreach (var item in js.locationDictionary)
{
2024-12-17 16:01:03 +08:00
2024-12-16 17:11:22 +08:00
if(item.Value.NpcRatio=="-1")
{
2024-12-17 16:01:03 +08:00
continue;
2024-12-16 17:11:22 +08:00
}
else
{
string[] npcratio = item.Value.NpcRatio.Split('|');
foreach(var npcLimit in npcratio)
{
string[] limit = npcLimit.Split(',');
2024-12-17 16:01:03 +08:00
if (limit[0] == selectScene.idcidentId.ToString()&& limit[1] == selectScene.difficultyId.ToString())
2024-12-16 17:11:22 +08:00
{
2024-12-16 17:56:27 +08:00
GameObject sceneitem = GameObject.Instantiate(personnelPrefabs, personnelContent);
PersonnelItem personnelItem = sceneitem.GetComponent<PersonnelItem>();
2024-12-10 08:05:28 +08:00
Button button = personnelItem.transform.Find("sceneText").GetComponent<Button>();
2024-12-17 16:01:03 +08:00
personnelItem.sceneText.text = js.SetUIText(item.Value.Name);
2024-12-16 17:56:27 +08:00
personnelItem.sceneId = item.Key;
2024-12-10 08:05:28 +08:00
personnelItem.Num = 1; // <20><><EFBFBD>ó<EFBFBD>ʼֵΪ 1
2024-12-13 15:30:41 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
2024-12-10 08:05:28 +08:00
button.onClick.AddListener(() =>
{
2024-12-13 15:30:41 +08:00
// <20><><EFBFBD>ǵ<EFBFBD>ǰѡ<C7B0><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-16 17:56:27 +08:00
OnSceneItemClicked(sceneitem, Color.yellow, selectedScene);
2024-12-13 15:30:41 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>Ա
2024-12-13 20:17:37 +08:00
if (personnelItem.NpcNum > 0)
2024-12-13 15:30:41 +08:00
{
2024-12-17 17:04:12 +08:00
redistributeBtn.interactable=true;
2024-12-17 22:55:13 +08:00
ChangeImage(redistributeBtn.interactable);
redistributeBtn.transform.GetComponent<Image>().sprite = showImage[1];
2024-12-16 17:56:27 +08:00
redistributeBtn.onClick.AddListener(() =>
{
2024-12-13 15:30:41 +08:00
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>
2024-12-16 17:56:27 +08:00
RedistributeLogic(personnelItem.sceneId, personnelItem.NpcNum);
2024-12-17 17:04:12 +08:00
redistributeBtn.interactable = false ;
2024-12-17 22:55:13 +08:00
ChangeImage(redistributeBtn.interactable);
2024-12-13 15:30:41 +08:00
});
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԱUI
2024-12-10 18:14:08 +08:00
foreach (Transform child in sceneCount)
{
Destroy(child.gameObject);
}
2024-12-13 15:30:41 +08:00
// ִ<>к<EFBFBD><D0BA><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-10 18:14:08 +08:00
LocationData locationData = js.GetAreaDateById(personnelItem.sceneId);
2024-12-13 15:30:41 +08:00
if (locationData.Level.ToString() != "0")
2024-12-10 18:14:08 +08:00
{
2024-12-13 15:30:41 +08:00
GameObject levelItem = GameObject.Instantiate(scenePrefab, sceneCount);
2024-12-10 18:14:08 +08:00
Button levelBtn = levelItem.transform.Find("chooseBtn2").GetComponent<Button>();
levelBtn.onClick.AddListener(() =>
{
2024-12-13 15:30:41 +08:00
JueseChoicePop jueseChoicePop = jueseChoicePanel.GetComponent<JueseChoicePop>();
2024-12-10 23:24:15 +08:00
jueseChoicePop.SetClass(personnelItem.sceneId);
2024-12-13 15:30:41 +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
});
personnelItems.Add(personnelItem);
}
}
}
}
}
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>·<EFBFBD><C2B7>䰴ť<E4B0B4>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD>
public void IsRedistribution()
{
2024-12-17 16:01:03 +08:00
// <20><><EFBFBD><EFBFBD> personnelItems<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>κ<EFBFBD> PersonnelItem <20><> gameObject <20><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>״̬
bool canRedistribute = personnelItems.Any(item =>
item.personnelImage != null && item.personnelImage.gameObject.activeSelf);
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>
2024-12-13 15:30:41 +08:00
public void RedistributeLogic(int excludedSceneId, int excludedNum)
2024-12-10 08:05:28 +08:00
{
2024-12-17 16:01:03 +08:00
// 1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD> NPC <20><><EFBFBD><EFBFBD>
2024-12-13 15:30:41 +08:00
int totalRedistributePeople = excludedNum;
2024-12-10 08:05:28 +08:00
2024-12-17 16:01:03 +08:00
// 2. <20><> personnelItems <20><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
PersonnelItem excludedItem = personnelItems.FirstOrDefault(item => item.sceneId == excludedSceneId);
if (excludedItem != null)
2024-12-10 08:05:28 +08:00
{
2024-12-17 16:01:03 +08:00
excludedItem.NpcNum = 0; // <20><><EFBFBD><EFBFBD> NPC <20><><EFBFBD><EFBFBD>
excludedItem.SetInfo(""); // <20><><EFBFBD><EFBFBD> UI <20><>ʾΪ<CABE><CEAA>
excludedItem.personnelImage.gameObject.SetActive(false); // <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
personnelItems.Remove(excludedItem); // <20><><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD>Ƴ<EFBFBD>
Debug.Log($"Cleared NPCs from Scene ID: {excludedSceneId}");
}
else
{
Debug.LogWarning($"Scene ID {excludedSceneId} not found in personnelItems.");
return;
2024-12-10 08:05:28 +08:00
}
2024-12-17 16:01:03 +08:00
2024-12-17 17:04:12 +08:00
// 3. ɸѡ<C9B8><D1A1>Ч<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD> personnelItems<6D><73>
2024-12-17 16:01:03 +08:00
List<PersonnelItem> validAreas = personnelItems.Where(item => item.NpcNum >= 0).ToList();
2024-12-10 08:05:28 +08:00
if (validAreas.Count == 0)
{
Debug.LogWarning("No valid areas available for redistribution.");
return;
}
2024-12-17 16:01:03 +08:00
2024-12-17 17:04:12 +08:00
// 4. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
System.Random random = new System.Random(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-17 16:01:03 +08:00
Dictionary<int, int> redistributionResult = new Dictionary<int, int>();
2024-12-17 17:04:12 +08:00
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-17 16:01:03 +08:00
foreach (var item in validAreas)
2024-12-13 20:17:37 +08:00
{
2024-12-17 17:04:12 +08:00
redistributionResult[item.sceneId] = 0;
2024-12-13 20:17:37 +08:00
}
2024-12-10 08:05:28 +08:00
2024-12-17 17:04:12 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NPC
int remainingNpc = totalRedistributePeople;
2024-12-17 16:01:03 +08:00
while (remainingNpc > 0)
{
2024-12-17 17:04:12 +08:00
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int randomIndex = random.Next(0, validAreas.Count);
PersonnelItem targetItem = validAreas[randomIndex];
// <20><><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
redistributionResult[targetItem.sceneId]++;
remainingNpc--;
2024-12-17 16:01:03 +08:00
}
2024-12-17 17:04:12 +08:00
2024-12-17 16:01:03 +08:00
// 5. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UI <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-10 08:05:28 +08:00
foreach (var kvp in redistributionResult)
{
2024-12-17 16:01:03 +08:00
PersonnelItem targetItem = validAreas.FirstOrDefault(item => item.sceneId == kvp.Key);
if (targetItem != null)
2024-12-10 08:05:28 +08:00
{
2024-12-17 16:01:03 +08:00
targetItem.NpcNum += kvp.Value; // <20><><EFBFBD><EFBFBD> NPC <20><><EFBFBD><EFBFBD>
targetItem.SetInfo(targetItem.NpcNum.ToString()); // <20><><EFBFBD><EFBFBD> UI <20><>ʾ
targetItem.personnelImage.gameObject.SetActive(true); // ȷ<><C8B7>ͼ<EFBFBD><CDBC><EFBFBD>ɼ<EFBFBD>
2024-12-10 08:05:28 +08:00
}
}
}
//<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-17 22:55:13 +08:00
//<2F><><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>İ<EFBFBD>ťͼƬ<CDBC>޸<EFBFBD>
public void ChangeImage(bool isSure)
{
if (isSure)
{
redistributeBtn.transform.GetComponent<Image>().sprite = showImage[1];
}
else
{
redistributeBtn.transform.GetComponent<Image>().sprite = showImage[0];
}
}
2024-11-29 09:47:47 +08:00
}