人物信息

This commit is contained in:
lq 2024-12-11 21:28:05 +08:00
parent 980e2e96ac
commit e29f7044df
4 changed files with 61 additions and 9 deletions

View File

@ -20,6 +20,7 @@ public class SelectedInfo
public string leader;//是否组长 public string leader;//是否组长
public int sceneId;//场景Id public int sceneId;//场景Id
public int dutyId;//职责的Id public int dutyId;//职责的Id
public string peopleId;//˝ÇÉŤId
} }
public class Panel : MonoBehaviour public class Panel : MonoBehaviour
@ -73,6 +74,7 @@ public class Panel : MonoBehaviour
[Header("数据")] [Header("数据")]
public string name, duty, scene; public string name, duty, scene;
public int dutyId; public int dutyId;
public string peopleId;
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; // 当前选中的角色
@ -113,10 +115,12 @@ public class Panel : MonoBehaviour
PlayerListResponse playerListResponse=await userInfo.GetPlayerList(); PlayerListResponse playerListResponse=await userInfo.GetPlayerList();
foreach(PlayerListData player in playerListResponse.data) foreach(PlayerListData player in playerListResponse.data)
{ {
Debug.Log("Player Name: " + player.UserName); Debug.Log("Player Name: " + player.Id);
GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent); GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent);
PeopleItem peopleItem = item.GetComponent<PeopleItem>(); PeopleItem peopleItem = item.GetComponent<PeopleItem>();
peopleItem.nameText.text = player.NickName; peopleItem.nameText.text = player.NickName;
peopleItem.peopleId = player.Id;
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);// 将每个实例化的角色添加到列表中
@ -325,9 +329,6 @@ public class Panel : MonoBehaviour
//处理点击确认按钮 //处理点击确认按钮
public void ClickSureBtn() public void ClickSureBtn()
{ {
Debug.LogError(">>>>>>>>>>>>>"+ isPersonSelected);
Debug.LogError(">>>>>>>>>>>>>"+ isDutySelected);
Debug.LogError(">>>>>>>>>>>>>"+ isSceneSelected);
// 只有在选择了人员、职责和场景的情况下,才会执行后续操作 // 只有在选择了人员、职责和场景的情况下,才会执行后续操作
if (isPersonSelected && isDutySelected && isSceneSelected) if (isPersonSelected && isDutySelected && isSceneSelected)
{ {
@ -364,7 +365,8 @@ public class Panel : MonoBehaviour
duty = selectedInfo.duty, duty = selectedInfo.duty,
scene = selectedInfo.scene, scene = selectedInfo.scene,
dutyId = selectedInfo.dutyId, dutyId = selectedInfo.dutyId,
sceneId = selectedInfo.sceneId sceneId = selectedInfo.sceneId,
peopleId=selectedInfo.peopleId
}; };
// 将当前选中的人员信息添加到对应场景的人员列表中 // 将当前选中的人员信息添加到对应场景的人员列表中
@ -429,9 +431,12 @@ public class Panel : MonoBehaviour
if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息 if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息
{ {
name = buttonText.text; name = buttonText.text;
Debug.LogError(name); PeopleItem peopleItem = buttonText.gameObject.GetComponent<PeopleItem>();
selectedInfo.name = name; selectedInfo.name = name;
//Debug.LogError("???????????????????"+ peopleItem.peopleId == null);
//selectedInfo.peopleId = peopleItem.peopleId;
isPersonSelected = true; // 选择了人员 isPersonSelected = true; // 选择了人员
Debug.LogError(">>>>>>>>>>>>>>>>" + selectedInfo.peopleId);
} }
else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息 else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息
{ {

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization; using System.Xml.Serialization;
using Unity.VisualScripting; using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
@ -56,6 +57,7 @@ public class EvacuationPanel : MonoBehaviour
Dictionary<int, PersonnelItem> personnelItemsDict = new Dictionary<int, PersonnelItem>(); Dictionary<int, PersonnelItem> personnelItemsDict = new Dictionary<int, PersonnelItem>();
private HashSet<int> excludedAreas = new HashSet<int>(); // 被清空的区域 ID private HashSet<int> excludedAreas = new HashSet<int>(); // 被清空的区域 ID
public SelectScenePanel selectScene; public SelectScenePanel selectScene;
private HashSet<int> clearedAreas = new HashSet<int>();
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
@ -298,7 +300,6 @@ public class EvacuationPanel : MonoBehaviour
} }
// 清空人员列表 // 清空人员列表
personnelItems.Clear(); personnelItems.Clear();
foreach (var sceneEntry in panel.sceneDataDictionary) foreach (var sceneEntry in panel.sceneDataDictionary)
{ {
foreach (var sceneInfo in sceneEntry.Value) foreach (var sceneInfo in sceneEntry.Value)
@ -429,13 +430,12 @@ public class EvacuationPanel : MonoBehaviour
foreach (var kvp in personnelItemsDict) foreach (var kvp in personnelItemsDict)
{ {
PersonnelItem item = kvp.Value; PersonnelItem item = kvp.Value;
// 如果 gameObject 是激活的,表示需要清空 NPC // 如果 gameObject 是激活的,表示需要清空 NPC
if (item.personnelImage.gameObject.activeSelf) if (item.personnelImage.gameObject.activeSelf)
{ {
totalRedistributePeople += item.Num; // 累加需要重新分配的 NPC 数量 totalRedistributePeople += item.Num; // 累加需要重新分配的 NPC 数量
item.Num = 0; // 清空该区域的 NPC 数量 item.Num = 0; // 清空该区域的 NPC 数量
item.SetInfo("0"); // 更新 UI 显示 item.SetInfo(""); // 更新 UI 显示
item.personnelImage.gameObject.SetActive(false); // 隐藏图标 item.personnelImage.gameObject.SetActive(false); // 隐藏图标
excludedAreas.Add(kvp.Key); // 记录清空的区域 ID excludedAreas.Add(kvp.Key); // 记录清空的区域 ID
Debug.Log($"Cleared NPCs from Scene ID: {kvp.Key}"); Debug.Log($"Cleared NPCs from Scene ID: {kvp.Key}");
@ -516,5 +516,50 @@ public class EvacuationPanel : MonoBehaviour
classCount.gameObject.SetActive(false); classCount.gameObject.SetActive(false);
} }
} }
//// 1. 把所选区域的NPC分配到其它区域
//public void RedistributeNpc(int selectedAreaId)
//{
// // 获取所有非已清空的区域ID
// var availableAreas = GetNonZeroNpcRatioAreas().Where(areaId => areaId != selectedAreaId && !clearedAreas.Contains(areaId)).ToList();
// // 从选中的区域获取NPC
// int npcToRedistribute = distributePeople[selectedAreaId.ToString()];
// if (npcToRedistribute == 0) return;
// // 移除该区域的NPC
// distributePeople[selectedAreaId.ToString()] = 0;
// //personnelItemsDict[selectedAreaId].UpdateNpcCount(0); // 假设你有一个更新UI的方法
// // 将这些NPC分配到其它区域
// DistributeNpcToOtherAreas(npcToRedistribute, availableAreas);
//}
//// 2. 记录被清空NPC分布的区域ID下次重新分配时这些区域不参与分配
//private void DistributeNpcToOtherAreas(int npcToRedistribute, List<int> availableAreas)
//{
// if (availableAreas.Count == 0) return;
// // 简单的均分方式,你可以根据自己的需要修改分配策略
// int npcPerArea = npcToRedistribute / availableAreas.Count;
// foreach (var areaId in availableAreas)
// {
// distributePeople[areaId.ToString()] += npcPerArea;
// //personnelItemsDict[areaId].UpdateNpcCount(distributePeople[areaId]);
// }
// // 如果有剩余的NPC可以将其分配到其他区域
// int remainder = npcToRedistribute % availableAreas.Count;
// for (int i = 0; i < remainder; i++)
// {
// distributePeople[availableAreas[i]] += 1;
// //personnelItemsDict[availableAreas[i]].UpdateNpcCount(distributePeople[availableAreas[i]]);
// }
//}
//// 重新分配前,清空区域时调用此方法,记录清空区域
//public void MarkAreaAsCleared(int areaId)
//{
// clearedAreas.Add(areaId);
//}
} }

View File

@ -6,6 +6,7 @@ using UnityEngine.UI;
public class PeopleItem : MonoBehaviour public class PeopleItem : MonoBehaviour
{ {
public Text nameText; // 人员名字显示 public Text nameText; // 人员名字显示
public string peopleId;
public Button button; // 按钮,用来选择人员 public Button button; // 按钮,用来选择人员
public Color defaultColor = Color.white; // 默认颜色 public Color defaultColor = Color.white; // 默认颜色
public Color addedColor = Color.gray; // 已添加颜色 public Color addedColor = Color.gray; // 已添加颜色

View File

@ -51,6 +51,7 @@ public class LoginPanel : MonoBehaviour
}; };
// 发送请求 // 发送请求
Debug.Log("되쩍흙꽝"+ JsonUtility.ToJson(loginBody));
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(loginBody)); string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(loginBody));
Debug.Log("登录" + response); Debug.Log("登录" + response);