_xiaofang/xiaofang/Assets/Script/Scheduled_03/Panel.cs
2024-12-23 14:28:02 +08:00

841 lines
34 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.SocialPlatforms;
using UnityEngine.UI;
public class SelectedInfo
{
public string name;//角色名
public string duty;//职责
public string scene;//场景名
public string leader;//是否组长
public string sceneId;//场景Id
public string dutyId;//职责的Id
public string peopleId;//角色Id
}
public class Panel : Base
{
[Header("组件")]
[Header("设置人员")]
public Button setName;//设置人员
[Header("设置职责")]
public Button setDuty;//设置职责
[Header("设置场景")]
public Button setScene;//设置场景
[Header("整体安排")]
public Text arrangeText;//整体安排
[Header("确认信息按钮")]
public Button sureBtn;//确认信息按钮
[Header("场景的ToggleGroup")]
public ToggleGroup scenetoggleGroup;//场景的ToggleGroup
[Header("筛选输入框")]
public InputField shaixuaninputField;//筛选输入框
[Header("画布上的射线投射器")]
public GraphicRaycaster raycaster; // 画布上的射线投射器
[Header("事件系统")]
public EventSystem eventSystem; // 事件系统
public ToggleGroup chooseGroup;
[Header("面板选择")]
public Toggle[] panelToggle;//面板选择Toggle
public Sprite[] toggleImage;//面板选择图片
[Header("物体")]
[Header("人员管理界面")]
public GameObject ManagerPanel;//人员管理界面
[Header("人员的窗口")]
public Transform peopleCountent;//人员的窗口
[Header("人员的预制体")]
public GameObject peoplePrefab;//人员的预制体
[Header("物体")]
public Transform panelContent;
[Header("职责预制体")]
public GameObject dutyPrefab;//职责预制体
[Header("职责的窗口")]
public Transform dutyCount;//职责的窗口
[Header("场景预制体")]
public GameObject scenePrefab;//场景预制体
[Header("存放场景预制体")]
public Transform sceneCount;//存放场景预制体的地方
[Header("人员管理面板")]
public GameObject ManagerPanelPrefab; // 预制体,包含人员管理面板
[Header("数据")]
public string name, duty, scene;
public int dutyId;
public string peopleId;
public List<GameObject> peopleList = new List<GameObject>(); // 存储所有已加载的人员预制体
private List<GameObject> filteredPeopleList = new List<GameObject>(); // 存储筛选后的人员列表
private GameObject selectedPerson = null; // 当前选中的角色
private GameObject selectedDuty = null;//当前选中职责
private GameObject selectedScene = null;//当前选中场景
public SelectedInfo selectedInfo;
public Dictionary<string, List<SelectedInfo>> sceneDataDictionary = new Dictionary<string, List<SelectedInfo>>();//不同的场景存取不同的人员数据
public List<PlayerListData> userInfoList = new List<PlayerListData>();
public getPlayerList userInfo;
public ManagerPanel managerPanel1;
public JSONReader jsonReader1;
public SelectScenePanel selectScenePanel;
public DatePanel datePanel;
private bool isPersonSelected = false; // 标志是否选择了人员
private bool isDutySelected = false; // 标志是否选择了职责
private bool isSceneSelected = false; // 标志是否选择了场景
// Start is called before the first frame update
void Start()
{
sureBtn.interactable = false;
ChangeImage(sureBtn.interactable);
selectedInfo = new SelectedInfo();
InstantiateToggle();
}
// Update is called once per frame
void Update()
{
GetData();
SetText();
PanelToggelSet();
//SetInputFile();
}
//==================================================================动态加载=======================================================
//动态加载人员
public async void DynamicLoadingPeople()
{
for (int i = 0; i < 10; i++)
{
GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent);
PeopleItem peopleItem = item.GetComponent<PeopleItem>();
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)
{
if (selectScenePanel.difficultyToRoles.ContainsKey(id))
{
List<string> rolesForSelectedDifficulty = selectScenePanel.difficultyToRoles[id];
// 遍历角色并做相关处理
foreach (var role in rolesForSelectedDifficulty)
{
int roleId = int.Parse(role);
NPCData npcData = jsonReader1.GetRoleDateById(roleId);
if (jsonReader1.npcDictionary.ContainsKey(roleId))
{
var npcInfo = jsonReader1.npcDictionary[roleId];
// 创建DutyItem实例
string[] roleLimitSections = npcData.Name.Split('|');
foreach(string plopleInfo in roleLimitSections)
{
string[] peopleLimit = plopleInfo.Split(',');
if (peopleLimit[0] == idcidentId.ToString() && peopleLimit[1]==id.ToString())
{
GameObject item = GameObject.Instantiate(dutyPrefab, dutyCount);
DutyItem dutyItem = item.GetComponent<DutyItem>();
Button dutuybutton = item.transform.Find("TextBtn").GetComponent<Button>();
string showText = jsonReader1.SetUIText(int.Parse(peopleLimit[2]));
dutuybutton.onClick.AddListener(() =>
{
OnDutyItemClicked(item, Color.red, selectedDuty);
if(dutyItem.dutyNameText.text=="主持人")
{
peopleList.Clear();
foreach (Transform child in sceneCount)
{
Destroy(child.gameObject);
}
Debug.Log("无需指定位置");
}
else
{
SetScene(dutyItem.dutyId);
}
});
dutyItem.dutyNameText.text = showText;
dutyItem.leader = npcData.GroupLeader;
dutyItem.dutyId = npcData.ID;
dutyItem.dutyImage.sprite = Resources.Load<Sprite>(npcData.ICON);
peopleList.Add(item);
}
}
}
}
}
}
//动态加载场景
public void DynamicLoadingScene()
{
foreach (var region in jsonReader1.sceneDictionary)
{
string[] roleLimitSections = region.Value.AreaList.Split('|');
foreach(string npcData in roleLimitSections)
{
GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
SceneItem sceneItem = item.GetComponent<SceneItem>();
Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene));
// 设置limitNum
sceneItem.sceneId = npcData.ToString();
LocationData locationData= jsonReader1.GetAreaDateById(int.Parse(npcData));
sceneItem.sceneName.text = jsonReader1.SetUIText(locationData.Name);
//Debug.LogError(sceneItem.sceneId);
// 将每个实例化的角色添加到列表中
peopleList.Add(item);
}
}
//foreach (var npcData in jsonReader1.locationDictionary)
//{
// // 解析角色限制字段
// string roleLimit = npcData.Value.RoleLimit;
// int sceneLimit = npcData.Value.Scene;
// Debug.Log("npcData.Value.Scene"+ npcData.Value.Scene);
// if(selectScenePanel.scnenId== sceneLimit)
// {
// GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
// SceneItem sceneItem = item.GetComponent<SceneItem>();
// Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
// scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene));
// // 设置limitNum
// sceneItem.sceneId = npcData.Key.ToString();
// //sceneItem.dutyId = roleLimits[1];
// //sceneItem.limitNum = int.Parse(roleLimits[2]);
// sceneItem.sceneName.text = npcData.Value.Note;
// // 将每个实例化的角色添加到列表中
// peopleList.Add(item);
// }
//if (!string.IsNullOrEmpty(roleLimit))
//{
// // 先按“|”分隔
// string[] roleLimitSections = roleLimit.Split('|');
// // 遍历每个部分(按“|”分隔后得到的数组)
// bool shouldInstantiate = true; // 用于判断是否需要实例化
// foreach (string section in roleLimitSections)
// {
// string[] roleLimits = section.Split(',');
// // 判断当前部分是否包含 "-1" 来决定是否跳过实例化
// if (section.Contains("-1"))
// {
// if (roleLimits[0] == "-1")
// {
// shouldInstantiate = false; // 不实例化该NPC
// break; // 跳出循环直接处理下一个NPC
// }
// }
// else
// {
// if (selectScenePanel.scnenId== sceneLimit)
// {
// if(selectScenePanel.difficultyId == int.Parse(roleLimits[1]))
// {
// Debug.LogWarning("roleLimits[0]"+ roleLimits[0]);
// Debug.LogWarning("roleLimits[1]" + roleLimits[1]);
// Debug.LogWarning("roleLimits[2]" + roleLimits[2]);
// Debug.LogWarning("roleLimits[3]" + roleLimits[3]);
// GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
// SceneItem sceneItem = item.GetComponent<SceneItem>();
// Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
// scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene));
// // 设置limitNum
// sceneItem.sceneId = npcData.Key.ToString();
// sceneItem.dutyId = roleLimits[1];
// sceneItem.limitNum = int.Parse(roleLimits[2]);
// sceneItem.sceneName.text = npcData.Value.Note;
// // 将每个实例化的角色添加到列表中
// peopleList.Add(item);
// }
// }
// }
// }
// // 如果不满足实例化条件跳过当前NPC的实例化
// if (!shouldInstantiate)
// {
// continue;
// }
//}
}
//=============================================================按钮和点击事件==================================================
//处理人员管理按钮
public void ClickPersonnelManagement()
{
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);
}
}
//根据选择的职责加载出对应场景
public void SetScene(int id)
{
peopleList.Clear();
foreach(Transform child in sceneCount)
{
Destroy(child.gameObject);
}
// 遍历所有的 NPC 数据
foreach (var npcData in jsonReader1.locationDictionary)
{
// 判断是否属于当前选择的场景
if (npcData.Value.Scene == selectScenePanel.scnenId)
{
// 按“|”分隔不同的角色限制部分
string[] roleLimitSections = npcData.Value.RoleLimit.Split('|');
bool shouldInstantiate = true;
if(npcData.Value.RoleLimit=="-1")
{
continue;
}
else
{
foreach (var section in roleLimitSections)
{
// 按“,”分隔出事故位置ID、职业ID和最低要求人数
string[] roleLimits = section.Split(',');
string accidentLocationId = roleLimits[0]; // 事故位置ID
string difficultyId = roleLimits[1];
string roleId = roleLimits[2]; // 职业ID
int minRequired = int.Parse(roleLimits[3]); // 最低要求人数
if (accidentLocationId == selectScenePanel.idcidentId.ToString() && roleId == id.ToString() && difficultyId == selectScenePanel.difficultyId.ToString())
{
GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
SceneItem sceneItem = item.GetComponent<SceneItem>();
// 获取当前该位置该职业的人数
int currentPeopleCount = GetCurrentPeopleCount(accidentLocationId, roleId);
// 设置推荐标记(如果人数不足)
if (minRequired > currentPeopleCount)
{
sceneItem.sceneImage.gameObject.SetActive(true); // 显示推荐标记
}
else
{
sceneItem.sceneImage.gameObject.SetActive(false); // 隐藏推荐标记
}
Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene));
sceneItem.sceneId = npcData.Key.ToString();
sceneItem.dutyId = accidentLocationId;
sceneItem.limitNum = minRequired;
sceneItem.sceneName.text = npcData.Value.Note;
peopleList.Add(item);
}
}
}
// 遍历每个角色限制部分
}
}
}
// 获取当前该位置该职业的已添加人数
private int GetCurrentPeopleCount(string accidentLocationId, string roleId)
{
int count = 0;
// 遍历场景数据字典,统计该事故位置和职业的人员数量
foreach (var sceneData in sceneDataDictionary)
{
foreach (var selectedInfo in sceneData.Value)
{
if (selectedInfo.sceneId == accidentLocationId && selectedInfo.dutyId == roleId)
{
count++;
}
}
}
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 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(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.Sum(kvp => kvp.Value.Count).ToString() + "人参与";
}
//处理界面关闭按钮
public void ClickCloseBtn()
{
transform.gameObject.SetActive(false);
}
//获取鼠标点击位置的信息
public void GetData()
{
ManagerPanel managerPanel = new ManagerPanel();
// 当鼠标左键按下时进行检测
if (Input.GetMouseButtonDown(0))
{
// 确保 raycaster 和 eventSystem 不为空
if (raycaster == null || eventSystem == null)
{
Debug.LogError("Raycaster 或 EventSystem 未正确分配,请在 Inspector 中进行分配。");
return;
}
// 创建 PointerEventData 来记录点击事件的数据
PointerEventData pointerData = new PointerEventData(eventSystem);
pointerData.position = Input.mousePosition; // 获取鼠标点击的位置
// 用于存储射线检测的结果
List<RaycastResult> results = new List<RaycastResult>();
// 射线检测 UI
raycaster.Raycast(pointerData, results);
// 遍历射线检测的结果
foreach (RaycastResult result in results)
{
// 检测到点击了按钮
Button clickedButton = result.gameObject.GetComponent<Button>();
if (clickedButton != null)
{
Text buttonText = clickedButton.GetComponentInChildren<Text>();
if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息
{
name = buttonText.text;
PeopleItem peopleItem = buttonText.gameObject.GetComponentInParent<PeopleItem>();
selectedInfo.name = name;
selectedInfo.peopleId = peopleItem.peopleId;
isPersonSelected = true; // 选择了人员
}
else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息
{
scene = buttonText.text;
SceneItem sceneItem = buttonText.gameObject.GetComponentInParent<SceneItem>();
selectedInfo.scene = scene;
selectedInfo.sceneId= sceneItem.sceneId;
isSceneSelected = true; // 选择了场景
}
else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息
{
duty = buttonText.text;
DutyItem item = clickedButton.GetComponentInParent<DutyItem>();
if(duty=="主持人")
{
isDutySelected = true; // 选择了职责
isSceneSelected = true;
}
else
{
isDutySelected = true;
isSceneSelected = false;
}
dutyId = item.dutyId;
selectedInfo.duty = duty;
selectedInfo.dutyId = dutyId.ToString();
}
}
}
// 根据选择情况,启用或禁用确认按钮
UpdateConfirmButtonState();
}
}
//==========================================================功能===========================================
//判断是否能够点击按钮
public void PanelToggelSet()
{
if(selectScenePanel.isSure)
{
panelToggle[1].interactable = selectScenePanel.isSure; // 启用第二个Toggle
panelToggle[1].gameObject.transform.GetComponent<Image>().sprite = toggleImage[1];
panelToggle[2].interactable = selectScenePanel.isSure; // 启用第三个Toggle
panelToggle[2].gameObject.transform.GetComponent<Image>().sprite = toggleImage[1];
}
}
//设置最初的时候Toggle的状态
public void InstantiateToggle()
{
for (int i = 1; i < panelToggle.Length; i++)
{
panelToggle[i].interactable = false;
panelToggle[i].gameObject.transform.GetComponent<Image>().sprite = toggleImage[0];
}
}
//判断确认按钮是否可以点击
private void UpdateConfirmButtonState()
{
if(isDutySelected)
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
ChangeImage(sureBtn.interactable);
}
//设置安排文字
public void SetText()
{
arrangeText.text = "[" + name + "]担任[" + duty + "],位于[" + scene + "]";
}
//筛选
public void SetInputFile()
{
// 获取输入框内容
string filterText = shaixuaninputField.text.Trim();
// 遍历所有已实例化的人员预制体
foreach (Transform child in peopleCountent)
{
// 获取该子物体上的 Text 组件
Text personNameText = child.GetComponentInChildren<Text>();
if (personNameText != null)
{
// 比较输入框中的内容与人员姓名
if (personNameText.text.Contains(filterText))
{
// 如果匹配,显示该人员
child.gameObject.SetActive(true);
}
else
{
// 如果不匹配,隐藏该人员
child.gameObject.SetActive(false);
}
}
}
}
// 点击选中角色,改变视觉效果
public void OnPeopleItemClicked(GameObject clickedItem, Color color, GameObject select)
{
// 如果有之前选中的角色,重置其视觉效果
if (selectedPerson != null && select != clickedItem)
{
Text prevText = selectedPerson.GetComponentInChildren<Text>();
if (prevText != null)
{
prevText.fontSize = 32; // 恢复原始字号
prevText.color = Color.white; // 恢复原始颜色
}
}
// 设置当前选中的角色为选中状态
selectedPerson = clickedItem; // 更新选中人物
Text personText = clickedItem.GetComponentInChildren<Text>();
if (personText != null)
{
// 字号变大和颜色变更(选中状态)
personText.fontSize = 36;
personText.color = color; // 选中颜色
}
}
// 点击选中职责,改变视觉效果
public void OnDutyItemClicked(GameObject clickedItem, Color color, GameObject select)
{
// 如果有之前选中的角色,重置其视觉效果
if (selectedDuty != null && select != clickedItem)
{
Text prevText = selectedDuty.GetComponentInChildren<Text>();
if (prevText != null)
{
prevText.fontSize = 32; // 恢复原始字号
prevText.color = Color.white; // 恢复原始颜色
}
}
// 设置当前选中的角色为选中状态
selectedDuty = clickedItem; // 更新选中人物
Text personText = clickedItem.GetComponentInChildren<Text>();
if (personText != null)
{
// 字号变大和颜色变更(选中状态)
personText.fontSize = 36;
personText.color = color; // 选中颜色
}
}
// 点击选中角色,改变视觉效果
public void OnSceneItemClicked(GameObject clickedItem, Color color, GameObject select)
{
// 如果有之前选中的角色,重置其视觉效果
if (selectedScene != null && select != clickedItem)
{
Text prevText = selectedScene.GetComponentInChildren<Text>();
if (prevText != null)
{
prevText.fontSize = 32; // 恢复原始字号
prevText.color = Color.white; // 恢复原始颜色
}
}
// 设置当前选中的角色为选中状态
selectedScene = clickedItem; // 更新选中人物
Text personText = clickedItem.GetComponentInChildren<Text>();
if (personText != null)
{
// 字号变大和颜色变更(选中状态)
personText.fontSize = 36;
personText.color = color; // 选中颜色
}
}
// 更新人员列表的显示颜色
private void UpdatePeopleListVisual()
{
// 遍历所有已加载的人员预制体,检查是否已添加到场景
foreach (GameObject personItem in peopleList)
{
// 获取人员的名字和显示文本
Text personText = personItem.GetComponentInChildren<Text>();
if (personText != null)
{
// 检查该人员是否已经添加到当前场景
bool isPersonAdded = sceneDataDictionary[selectedInfo.scene].Any(info => info.name == personText.text);
// 如果该人员已经被添加到场景,改变颜色为灰色
if (isPersonAdded)
{
personText.color = Color.blue; // 已添加人员的颜色
}
else
{
personText.color = Color.white; // 未添加人员的颜色
}
}
}
}
//上传人员数据
public void UploadData()
{
createTemplateInfo.Instance.auth_CreateTemplate.playerList = new List<PlayerList>();
foreach (var peopleItem in sceneDataDictionary)
{
foreach (var peopleInfo in peopleItem.Value)
{
PlayerList playerList = new PlayerList();
playerList.userId = peopleInfo.peopleId;
playerList.roleId = peopleInfo.dutyId;
playerList.birthAreaId = peopleInfo.sceneId;
playerList.chargeAreaId = peopleInfo.sceneId;
createTemplateInfo.Instance.auth_CreateTemplate.playerList.Add(playerList);
}
}
}
//确定的按钮图片修改
public void ChangeImage(bool isSure)
{
if (isSure)
{
sureBtn.transform.GetComponent<Image>().sprite = toggleImage[1];
}
else
{
sureBtn.transform.GetComponent<Image>().sprite = toggleImage[0];
}
}
}