Compare commits

...

2 Commits

4 changed files with 219 additions and 65 deletions

View File

@ -10315,6 +10315,18 @@ PrefabInstance:
propertyPath: jueseChoicePanel
value:
objectReference: {fileID: 1799705462}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: showImage.Array.size
value: 2
objectReference: {fileID: 0}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: showImage.Array.data[0]
value:
objectReference: {fileID: 21300000, guid: 586c4520a2c6c8d4e9bac48ed427f617, type: 3}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: showImage.Array.data[1]
value:
objectReference: {fileID: 21300000, guid: 0905bd7a17d75af4985c19c47bfe7fc7, type: 3}
- target: {fileID: 4764228630647718977, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: m_AnchorMax.y
value: 0

View File

@ -10,6 +10,7 @@ using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.SocialPlatforms;
using UnityEngine.UI;
public class SelectedInfo
@ -96,6 +97,8 @@ public class Panel : MonoBehaviour
// Start is called before the first frame update
void Start()
{
sureBtn.interactable = false;
ChangeImage(sureBtn.interactable);
selectedInfo = new SelectedInfo();
InstantiateToggle();
}
@ -112,18 +115,29 @@ public class Panel : MonoBehaviour
//动态加载人员
public async void DynamicLoadingPeople()
{
PlayerListResponse playerListResponse=await userInfo.GetPlayerList();
foreach(PlayerListData player in playerListResponse.data)
for(int i=0;i<10;i++)
{
GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent);
PeopleItem peopleItem = item.GetComponent<PeopleItem>();
peopleItem.nameText.text = player.NickName;
peopleItem.peopleId = player.UserId;
peopleItem.nameText.text = "角色1";
peopleItem.peopleId = "0";
Button peoplebutton = item.transform.Find("TextBtn").GetComponent<Button>();
peoplebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.yellow, selectedPerson));
peopleList.Add(item);// 将每个实例化的角色添加到列表中
}
//PlayerListResponse playerListResponse=await userInfo.GetPlayerList();
//foreach(PlayerListData player in playerListResponse.data)
//{
// GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent);
// PeopleItem peopleItem = item.GetComponent<PeopleItem>();
// peopleItem.nameText.text = player.NickName;
// peopleItem.peopleId = player.UserId;
// Button peoplebutton = item.transform.Find("TextBtn").GetComponent<Button>();
// peoplebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.yellow, selectedPerson));
// peopleList.Add(item);// 将每个实例化的角色添加到列表中
//}
}
//动态加载职责
public void DynamicLoadingDuty(int id,int idcidentId)
{
@ -180,6 +194,7 @@ public class Panel : MonoBehaviour
}
}
}
//动态加载场景
public void DynamicLoadingScene()
{
@ -276,24 +291,24 @@ public class Panel : MonoBehaviour
//=============================================================按钮和点击事件==================================================
//处理人员管理按钮
public void ClickPersonnelManagement()
{
foreach (Transform child in panelContent)
{
foreach (Transform child in panelContent)
{
Destroy(child.gameObject);
}
foreach (var sceneEntry in sceneDataDictionary)
{
//Debug.Log($"场景: {sceneEntry.Key},人数: {sceneEntry.Value.Count}");
GameObject managerPanelInstance = Instantiate(ManagerPanelPrefab, panelContent);
Button button = managerPanelInstance.GetComponent<Button>();
button.onClick.AddListener(() => managerPanel1.OnItemClicked(managerPanelInstance));
Text sceneText = managerPanelInstance.transform.Find("top/sceneName").GetComponent<Text>();
sceneText.text = sceneEntry.Key;
managerPanel1.CreateScenePanel(sceneEntry.Key, sceneEntry.Value, managerPanelInstance);
//managerPanel1.SetPlate();
ManagerPanel.gameObject.SetActive(true);
}
Destroy(child.gameObject);
}
foreach (var sceneEntry in sceneDataDictionary)
{
//Debug.Log($"场景: {sceneEntry.Key},人数: {sceneEntry.Value.Count}");
GameObject managerPanelInstance = Instantiate(ManagerPanelPrefab, panelContent);
Button button = managerPanelInstance.GetComponent<Button>();
button.onClick.AddListener(() => managerPanel1.OnItemClicked(managerPanelInstance));
Text sceneText = managerPanelInstance.transform.Find("top/sceneName").GetComponent<Text>();
sceneText.text = sceneEntry.Key;
managerPanel1.CreateScenePanel(sceneEntry.Key, sceneEntry.Value, managerPanelInstance);
//managerPanel1.SetPlate();
ManagerPanel.gameObject.SetActive(true);
}
}
//根据选择的职责加载出对应场景
public void SetScene(int id)
{
@ -377,37 +392,126 @@ public class Panel : MonoBehaviour
return count;
}
//处理点击确认按钮
//public void ClickSureBtn()
//{
// // 只有在选择了人员、职责和场景的情况下,才会执行后续操作
// if (isPersonSelected && isDutySelected && isSceneSelected)
// {
// // 保存选中的人员信息到场景数据字典中
// string sceneName = selectedInfo.scene;
// // 如果场景字典中没有这个场景,先创建一个空列表
// if (!sceneDataDictionary.ContainsKey(sceneName))
// {
// sceneDataDictionary[sceneName] = new List<SelectedInfo>();
// }
// // 需要判断是否达到了职责的人员上限
// 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个此职责的人选
// {
// isLimitReached = true; // 标记限制已达
// }
// }
// // 如果没有达到上限,则可以添加人员信息
// if (!isLimitReached)
// {
// // 通过创建一个新的 SelectedInfo 实例来避免引用同一个对象
// SelectedInfo newSelectedInfo = new SelectedInfo
// {
// name = selectedInfo.name,
// duty = selectedInfo.duty,
// scene = selectedInfo.scene,
// dutyId = selectedInfo.dutyId,
// sceneId = selectedInfo.sceneId,
// peopleId=selectedInfo.peopleId
// };
// // 将当前选中的人员信息添加到对应场景的人员列表中
// currentSceneInfo.Add(newSelectedInfo);
// // 禁用确认按钮并清空选择标志
// sureBtn.interactable = false;
// ChangeImage(sureBtn.interactable);
// isPersonSelected = false;
// isDutySelected = false;
// isSceneSelected = false;
// UploadData(peopleId = selectedInfo.peopleId, selectedInfo.dutyId.ToString(), selectedInfo.sceneId.ToString());
// // 改变已添加人员的显示颜色
// UpdatePeopleListVisual();
// }
// }
// else
// {
// Debug.LogError("请确保选择了人员、职责和场景!");
// }
// datePanel.NumberText.text = "共" + (sceneDataDictionary.Keys.Count * sceneDataDictionary.Values.Count).ToString() + "人参与";
//}
public void ClickSureBtn()
{
// 只有在选择了人员、职责和场景的情况下,才会执行后续操作
// 只有在选择了人员、职责和场景的情况下,才会执行后续操作
if (isPersonSelected && isDutySelected && isSceneSelected)
{
// 保存选中的人员信息到场景数据字典中
string sceneName = selectedInfo.scene;
// 如果场景字典中没有这个场景,先创建一个空列表
if (!sceneDataDictionary.ContainsKey(sceneName))
{
sceneDataDictionary[sceneName] = new List<SelectedInfo>();
}
// 需要判断是否达到了职责的人员上限
// 1. 判断整个 sceneDataDictionary 中是否存在相同的人名
SelectedInfo existingPerson = null;
string existingSceneName = null;
foreach (var sceneEntry in sceneDataDictionary)
{
existingPerson = sceneEntry.Value.FirstOrDefault(info => info.name == selectedInfo.name);
if (existingPerson != null)
{
existingSceneName = sceneEntry.Key;
break; // 找到后立即退出循环
}
}
// 2. 如果找到了相同的人名,删除旧的记录
if (existingPerson != null)
{
sceneDataDictionary[existingSceneName].Remove(existingPerson);
Debug.Log($"Removed existing person: {existingPerson.name} from scene: {existingSceneName}");
// 判断该场景是否还有剩余的角色,如果没有,删除该场景
if (sceneDataDictionary[existingSceneName].Count == 0)
{
sceneDataDictionary.Remove(existingSceneName);
Debug.Log($"Removed empty scene: {existingSceneName} because it has no more roles.");
}
}
// 3. 需要判断是否达到了职责的人员上限(当前场景)
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个此职责的人选
{
isLimitReached = true; // 标记限制已达
}
}
// 如果没有达到上限,则可以添加人员信息
// 4. 如果没有达到上限,则可以添加人员信息
if (!isLimitReached)
{
// 通过创建一个新的 SelectedInfo 实例来避免引用同一个对象
// 创建一个新的 SelectedInfo 实例
SelectedInfo newSelectedInfo = new SelectedInfo
{
name = selectedInfo.name,
@ -415,7 +519,7 @@ public class Panel : MonoBehaviour
scene = selectedInfo.scene,
dutyId = selectedInfo.dutyId,
sceneId = selectedInfo.sceneId,
peopleId=selectedInfo.peopleId
peopleId = selectedInfo.peopleId
};
// 将当前选中的人员信息添加到对应场景的人员列表中
@ -423,21 +527,34 @@ public class Panel : MonoBehaviour
// 禁用确认按钮并清空选择标志
sureBtn.interactable = false;
ChangeImage(sureBtn.interactable);
isPersonSelected = false;
isDutySelected = false;
isSceneSelected = false;
UploadData(peopleId = selectedInfo.peopleId, selectedInfo.dutyId.ToString(), selectedInfo.sceneId.ToString());
// 改变已添加人员的显示颜色
// 上传数据
UploadData(selectedInfo.peopleId, selectedInfo.dutyId.ToString(), selectedInfo.sceneId.ToString());
// 更新已添加人员的显示颜色
UpdatePeopleListVisual();
Debug.Log($"Added new person: {newSelectedInfo.name} to scene: {sceneName}");
}
else
{
Debug.LogWarning("当前职责人数已达上限,无法添加新的人员!");
}
}
else
{
Debug.LogError("请确保选择了人员、职责和场景!");
}
datePanel.NumberText.text = "共" + (sceneDataDictionary.Keys.Count * sceneDataDictionary.Values.Count).ToString() + "人参与";
// 更新统计人数的文本显示
datePanel.NumberText.text = "共" + sceneDataDictionary.Sum(kvp => kvp.Value.Count).ToString() + "人参与";
}
//处理界面关闭按钮
public void ClickCloseBtn()
{
@ -514,7 +631,6 @@ public class Panel : MonoBehaviour
}
}
}
// 根据选择情况,启用或禁用确认按钮
UpdateConfirmButtonState();
}
@ -545,11 +661,12 @@ public class Panel : MonoBehaviour
//判断确认按钮是否可以点击
private void UpdateConfirmButtonState()
{
if(isDutySelected)
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
}
{
if(isDutySelected)
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
ChangeImage(sureBtn.interactable);
}
//设置安排文字
public void SetText()
@ -663,30 +780,31 @@ public class Panel : MonoBehaviour
// 更新人员列表的显示颜色
private void UpdatePeopleListVisual()
{
// 遍历所有已加载的人员预制体,检查是否已添加到场景
foreach (GameObject personItem in peopleList)
{
// 遍历所有已加载的人员预制体,检查是否已添加到场景
foreach (GameObject personItem in peopleList)
{
// 获取人员的名字和显示文本
Text personText = personItem.GetComponentInChildren<Text>();
// 获取人员的名字和显示文本
Text personText = personItem.GetComponentInChildren<Text>();
if (personText != null)
if (personText != null)
{Debug.LogError("INININNIININININININININININININININININININI");
// 检查该人员是否已经添加到当前场景
bool isPersonAdded = sceneDataDictionary[selectedInfo.scene].Any(info => info.name == personText.text);
// 如果该人员已经被添加到场景,改变颜色为灰色
if (isPersonAdded)
{
// 检查该人员是否已经添加到当前场景
bool isPersonAdded = sceneDataDictionary[selectedInfo.scene].Any(info => info.name == personText.text);
// 如果该人员已经被添加到场景,改变颜色为灰色
if (isPersonAdded)
{
personText.color = Color.blue; // 已添加人员的颜色
}
else
{
personText.color = Color.white; // 未添加人员的颜色
}
personText.color = Color.blue; // 已添加人员的颜色
}
else
{
personText.color = Color.white; // 未添加人员的颜色
}
}
}
}
//上传人员数据
public void UploadData(string userId,string roleId,string areaId)
@ -705,6 +823,19 @@ public class Panel : MonoBehaviour
}
}
}
//确定的按钮图片修改
public void ChangeImage(bool isSure)
{
if (isSure)
{
sureBtn.transform.GetComponent<Image>().sprite = toggleImage[1];
}
else
{
sureBtn.transform.GetComponent<Image>().sprite = toggleImage[0];
}
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Unity.VisualScripting;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.Networking.Types;
using UnityEngine.UI;
@ -12,7 +13,6 @@ using static UnityEditor.Progress;
public class EvacuationPanel : MonoBehaviour
{
public Dictionary<string, int> distributePeople = new Dictionary<string, int>();// 分配给各个场景的人数
public List<PersonnelItem> personnelItems;//左侧区域
public Transform personnelContent;
public Panel panel;
@ -25,6 +25,7 @@ public class EvacuationPanel : MonoBehaviour
public Transform content;
public Text topText;
private GameObject selectedScene = null;//当前选中场景
public Sprite[] showImage;
public List<ClassItem> classItemList = new List<ClassItem>();
public List<ClassMate> classMateList = new List<ClassMate>();
@ -53,16 +54,13 @@ public class EvacuationPanel : MonoBehaviour
[Header("可分配列表")]
List<int> nonZeroAreas = new List<int>();
public SelectScenePanel selectScene;
private HashSet<int> clearedAreas = new HashSet<int>();
public List<int> clearRegion=new List<int>();//被清除的区域
[Header("被清除的区域")] public List<int> clearRegion=new List<int>();
// Start is called before the first frame update
void Start()
{
redistributeBtn.interactable = false;
//SetNpcType();
//nonZeroAreas= GetNonZeroNpcRatioAreas();
ChangeImage(redistributeBtn.interactable);
jc = JuesechoicePop.GetComponent<JueseChoicePop>();
CountsubmitBtn.onClick.AddListener(Submit);
submitBtn.onClick.AddListener(totalSubmit);
@ -137,7 +135,7 @@ public class EvacuationPanel : MonoBehaviour
return;
}
StuCountInputField.text = "";
//StuCountInputField.text = "";
// 调用分配方法
var result = DistributeNpcByRatio(personnelItems, count);
@ -232,7 +230,6 @@ public class EvacuationPanel : MonoBehaviour
foreach(var npcLimit in npcratio)
{
string[] limit = npcLimit.Split(',');
if (limit[0] == selectScene.idcidentId.ToString()&& limit[1] == selectScene.difficultyId.ToString())
{
GameObject sceneitem = GameObject.Instantiate(personnelPrefabs, personnelContent);
@ -250,11 +247,14 @@ public class EvacuationPanel : MonoBehaviour
if (personnelItem.NpcNum > 0)
{
redistributeBtn.interactable=true;
ChangeImage(redistributeBtn.interactable);
redistributeBtn.transform.GetComponent<Image>().sprite = showImage[1];
redistributeBtn.onClick.AddListener(() =>
{
// 清除选定区域的人员数据
RedistributeLogic(personnelItem.sceneId, personnelItem.NpcNum);
redistributeBtn.interactable = false ;
ChangeImage(redistributeBtn.interactable);
});
}
// 清空现有场景下的所有人员UI
@ -446,4 +446,17 @@ public class EvacuationPanel : MonoBehaviour
classCount.gameObject.SetActive(false);
}
}
//重新分配的按钮图片修改
public void ChangeImage(bool isSure)
{
if (isSure)
{
redistributeBtn.transform.GetComponent<Image>().sprite = showImage[1];
}
else
{
redistributeBtn.transform.GetComponent<Image>().sprite = showImage[0];
}
}
}

View File

@ -47,10 +47,8 @@ public class MaterialPanel : MonoBehaviour
{
MaterialList materialList = new MaterialList();
materialList.materialId = materialItem.materialId;
Debug.Log("materialList.materialId--------------------" + materialList.materialId);
materialList.num = materialItem.materialNum;
createTemplateInfo.Instance.auth_CreateTemplate.materialList.Add(materialList);
Debug.Log(materialItem.materialName + " ÊýÁ¿: " + materialItem.GetMaterialNum());
}
}
}