Merge branch 'main' of http://shu.sheziwanglo.cn:3000/wulongxiao/_xiaofang
This commit is contained in:
commit
46ec56f0f6
@ -2232,7 +2232,7 @@ MonoBehaviour:
|
||||
eventSystem: {fileID: 1579865912}
|
||||
ManagerPanel: {fileID: 617308871}
|
||||
peopleCountent: {fileID: 667280287}
|
||||
peoplePrefab: {fileID: 0}
|
||||
peoplePrefab: {fileID: 4204671800070690484, guid: 5e14c4abba3cf1a4099ba76ddf50a689, type: 3}
|
||||
panelContent: {fileID: 1145997501}
|
||||
dutyPrefab: {fileID: 3344224972021141760, guid: 4f774e025e4a15442aedb0588ab62396, type: 3}
|
||||
dutyCount: {fileID: 1034927193}
|
||||
@ -2504,7 +2504,7 @@ RectTransform:
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -193.59004, y: 309.8263}
|
||||
m_SizeDelta: {x: 388.1544, y: 58.599}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0, y: 1}
|
||||
--- !u!114 &667280288
|
||||
MonoBehaviour:
|
||||
@ -5861,6 +5861,10 @@ PrefabInstance:
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: -62
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7468736064052287473, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7468736064090762255, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
|
||||
propertyPath: eventName
|
||||
value:
|
||||
@ -5887,12 +5891,16 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7468736064090762355, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 564.5
|
||||
value: 206
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7468736064090762355, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: -62
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7468736064090762356, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7468736064179597218, guid: 90919b88a71f0054bb1cf84429cb3a1e, type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
|
@ -31,15 +31,9 @@ public class JSONReader : MonoBehaviour
|
||||
NPCDictionary = NPCParseJSON(incidentSiteJosnFile.text);
|
||||
foreach (var npc in locationDictionary)
|
||||
{
|
||||
//.Log($"Scene ID: {npc.Value.ID}");
|
||||
//Debug.Log("===========================");
|
||||
|
||||
}
|
||||
|
||||
//打印 NPC 数据
|
||||
//PrintNPCData(npcDictionary);
|
||||
|
||||
// 打印 Location 数据
|
||||
////PrintLocationData(locationDictionary);
|
||||
GetNpcDataByID(8001);
|
||||
}
|
||||
|
||||
// 解析 JSON 字符串为 NPC 数据
|
||||
@ -134,43 +128,26 @@ public class JSONReader : MonoBehaviour
|
||||
return locationDictionary;
|
||||
}
|
||||
|
||||
// 打印 NPC 数据
|
||||
//void PrintNPCData(Dictionary<int, NPCData> npcDictionary)
|
||||
//{
|
||||
// foreach (var npc in npcDictionary)
|
||||
// {
|
||||
// Debug.Log($"NPC ID: {npc.Value.ID}");
|
||||
// Debug.Log($"Note: {npc.Value.Note}");
|
||||
// Debug.Log($"Name: {npc.Value.Name}");
|
||||
// Debug.Log($"ActionMode: {npc.Value.ActionMode}");
|
||||
// Debug.Log($"Group: {npc.Value.Group}");
|
||||
// Debug.Log($"GroupLeader: {npc.Value.GroupLeader}");
|
||||
// Debug.Log($"IsLeadingNPC: {npc.Value.IsLeadingNPC}");
|
||||
// Debug.Log($"ICON: {npc.Value.ICON}");
|
||||
// Debug.Log($"WeightLimit: {npc.Value.WeightLimit}");
|
||||
// Debug.Log($"Stats: {npc.Value.Stats}");
|
||||
// Debug.Log($"Skills: {npc.Value.Skills}");
|
||||
// Debug.Log($"ResPath: {npc.Value.ResPath}");
|
||||
// Debug.Log("------------------------------------");
|
||||
// }
|
||||
//}
|
||||
//将所有的数据都拿出来方便调用
|
||||
// 根据给定的ID获取对应的NPC数据,并返回字典中所有数据
|
||||
public void GetNpcDataByID(int id)
|
||||
{
|
||||
// 例如,获取 NPC 字典中对应 ID 的数据
|
||||
if (npcDictionary.ContainsKey(id))
|
||||
{
|
||||
NPCData npcData = npcDictionary[id];
|
||||
|
||||
// // 打印 Location 数据
|
||||
//void PrintLocationData(Dictionary<int, LocationData> locationDictionary)
|
||||
//{
|
||||
// foreach (var location in locationDictionary)
|
||||
// {
|
||||
// Debug.Log($"Location ID: {location.Value.ID}");
|
||||
// Debug.Log($"Note: {location.Value.Note}");
|
||||
// Debug.Log($"Name: {location.Value.Name}");
|
||||
// Debug.Log($"Scene: {location.Value.Scene}");
|
||||
// Debug.Log($"NpcRatio: {location.Value.NpcRatio}");
|
||||
// Debug.Log($"Oversee: {location.Value.Oversee}");
|
||||
// Debug.Log($"RoleLimit: {location.Value.RoleLimit}");
|
||||
// Debug.Log($"Level: {location.Value.Level}");
|
||||
// Debug.Log("===========================");
|
||||
// }
|
||||
//}
|
||||
// 遍历并输出字典中的所有数据
|
||||
foreach (var npc in npcDictionary)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"No NPC found with ID: {id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 帮助类,用于解析 JSON 数组
|
||||
|
@ -13,13 +13,13 @@ using UnityEngine.UI;
|
||||
|
||||
public class SelectedInfo
|
||||
{
|
||||
public string name;
|
||||
public string duty;
|
||||
public string scene;
|
||||
public string leader;
|
||||
public string name;//角色名
|
||||
public string duty;//职责
|
||||
public string scene;//场景名
|
||||
public string leader;//是否组长
|
||||
public int dutyId;//职责的Id
|
||||
}
|
||||
|
||||
|
||||
public class Panel : MonoBehaviour
|
||||
{
|
||||
[Header("组件")]
|
||||
@ -52,6 +52,7 @@ public class Panel : MonoBehaviour
|
||||
|
||||
[Header("数据")]
|
||||
public string name, duty, scene;
|
||||
public int dutyId;
|
||||
public List<GameObject> peopleList = new List<GameObject>(); // 存储所有已加载的人员预制体
|
||||
private List<GameObject> filteredPeopleList = new List<GameObject>(); // 存储筛选后的人员列表
|
||||
private GameObject selectedPerson = null; // 当前选中的角色
|
||||
@ -69,47 +70,48 @@ public class Panel : MonoBehaviour
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
selectedInfo = new SelectedInfo();
|
||||
DynamicLoadingPeople();
|
||||
DynamicLoadingDuty();
|
||||
DynamicLoadingScene();
|
||||
}
|
||||
{
|
||||
selectedInfo = new SelectedInfo();
|
||||
DynamicLoadingPeople();
|
||||
DynamicLoadingDuty();
|
||||
DynamicLoadingScene();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
GetData();
|
||||
SetText();
|
||||
//SetInputFile();
|
||||
}
|
||||
{
|
||||
GetData();
|
||||
SetText();
|
||||
//SetInputFile();
|
||||
}
|
||||
|
||||
//==================================================================动态加载=======================================================
|
||||
//动态加载人员
|
||||
//动态加载人员
|
||||
public void DynamicLoadingPeople()
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent);
|
||||
PeopleItem peopleItem = item.GetComponent<PeopleItem>();
|
||||
Button peoplebutton = item.transform.Find("TextBtn").GetComponent<Button>();
|
||||
peoplebutton.onClick.AddListener(() => OnPeopleItemClicked(item,Color.yellow, selectedPerson));
|
||||
peopleList.Add(item);// 将每个实例化的角色添加到列表中
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
GameObject item = GameObject.Instantiate<GameObject>(peoplePrefab, peopleCountent);
|
||||
PeopleItem peopleItem = item.GetComponent<PeopleItem>();
|
||||
Button peoplebutton = item.transform.Find("TextBtn").GetComponent<Button>();
|
||||
peoplebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.yellow, selectedPerson));
|
||||
peopleList.Add(item);// 将每个实例化的角色添加到列表中
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//动态加载职责
|
||||
public void DynamicLoadingDuty()
|
||||
{
|
||||
Debug.Log("||||||||||||||||||||||||||||"+ selectScenePanel.eventId);
|
||||
foreach (var npcData in jsonReader1.npcDictionary)
|
||||
{
|
||||
string[] nameSections = npcData.Value.Name.Split('|');
|
||||
foreach (var section in nameSections)
|
||||
{
|
||||
string[] sectionParts = section.Split(',');
|
||||
if (int.Parse(sectionParts[0])== 2001)
|
||||
|
||||
//判断事件然后确定有哪些职责
|
||||
if (int.Parse(sectionParts[0]) == 2001)
|
||||
{
|
||||
int key = int.Parse(sectionParts[1]);
|
||||
if (jsonReader1.npcDictionary.ContainsKey(key))
|
||||
@ -122,17 +124,13 @@ public class Panel : MonoBehaviour
|
||||
GameObject item = GameObject.Instantiate(dutyPrefab, dutyCount);
|
||||
DutyItem dutyItem = item.GetComponent<DutyItem>();
|
||||
Button dutuybutton = item.transform.Find("TextBtn").GetComponent<Button>();
|
||||
dutuybutton.onClick.AddListener(() => OnPeopleItemClicked(item,Color.red,selectedDuty));
|
||||
dutuybutton.onClick.AddListener(() => OnPeopleItemClicked (item, Color.red, selectedDuty));
|
||||
dutyItem.dutyNameText.text = npcData.Value.Note;
|
||||
dutyItem.leader = npcData.Value.GroupLeader;
|
||||
dutyItem.dutyId = npcData.Value.ID;
|
||||
peopleList.Add(item);
|
||||
}
|
||||
}
|
||||
//GameObject item = GameObject.Instantiate<GameObject>(dutyPrefab, dutyCount);
|
||||
//DutyItem dutyItem = item.GetComponent<DutyItem>();
|
||||
//dutyItem.dutyNameText.text = npcData.Value.Note;
|
||||
//dutyItem.leader = npcData.Value.GroupLeader;
|
||||
//peopleList.Add(item);// 将每个实例化的角色添加到列表中
|
||||
}
|
||||
|
||||
}
|
||||
@ -140,259 +138,254 @@ public class Panel : MonoBehaviour
|
||||
|
||||
//动态加载场景
|
||||
public void DynamicLoadingScene()
|
||||
{
|
||||
foreach (var npcData in jsonReader1.locationDictionary)
|
||||
{
|
||||
// 解析角色限制字段
|
||||
string roleLimit = npcData.Value.RoleLimit;
|
||||
|
||||
if (!string.IsNullOrEmpty(roleLimit))
|
||||
foreach (var npcData in jsonReader1.locationDictionary)
|
||||
{
|
||||
// 先按“|”分隔
|
||||
string[] roleLimitSections = roleLimit.Split('|');
|
||||
// 遍历每个部分(按“|”分隔后得到的数组)
|
||||
bool shouldInstantiate = true; // 用于判断是否需要实例化
|
||||
foreach (string section in roleLimitSections)
|
||||
// 解析角色限制字段
|
||||
string roleLimit = npcData.Value.RoleLimit;
|
||||
|
||||
if (!string.IsNullOrEmpty(roleLimit))
|
||||
{
|
||||
string[] roleLimits = section.Split(',');
|
||||
// 判断当前部分是否包含 "-1" 来决定是否跳过实例化
|
||||
if (section.Contains("-1"))
|
||||
// 先按“|”分隔
|
||||
string[] roleLimitSections = roleLimit.Split('|');
|
||||
// 遍历每个部分(按“|”分隔后得到的数组)
|
||||
bool shouldInstantiate = true; // 用于判断是否需要实例化
|
||||
foreach (string section in roleLimitSections)
|
||||
{
|
||||
if (roleLimits[0] == "-1")
|
||||
string[] roleLimits = section.Split(',');
|
||||
// 判断当前部分是否包含 "-1" 来决定是否跳过实例化
|
||||
if (section.Contains("-1"))
|
||||
{
|
||||
shouldInstantiate = false; // 不实例化该NPC
|
||||
break; // 跳出循环,直接处理下一个NPC
|
||||
if (roleLimits[0] == "-1")
|
||||
{
|
||||
shouldInstantiate = false; // 不实例化该NPC
|
||||
break; // 跳出循环,直接处理下一个NPC
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
|
||||
SceneItem sceneItem = item.GetComponent<SceneItem>();
|
||||
Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
|
||||
scenebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.green, selectedScene));
|
||||
|
||||
// 设置limitNum
|
||||
sceneItem.dutyId = int.Parse(roleLimits[1]);
|
||||
sceneItem.limitNum = int.Parse(roleLimits[2]);
|
||||
sceneItem.sceneName.text = npcData.Value.Note;
|
||||
// 将每个实例化的角色添加到列表中
|
||||
peopleList.Add(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
// 如果不满足实例化条件,跳过当前NPC的实例化
|
||||
if (!shouldInstantiate)
|
||||
{
|
||||
GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
|
||||
SceneItem sceneItem = item.GetComponent<SceneItem>();
|
||||
Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
|
||||
scenebutton.onClick.AddListener(() => OnPeopleItemClicked(item, Color.green, selectedScene));
|
||||
|
||||
// 设置limitNum
|
||||
sceneItem.dutyId = int.Parse(roleLimits[1]);
|
||||
sceneItem.limitNum = int.Parse(roleLimits[2]);
|
||||
sceneItem.sceneName.text = npcData.Value.Note;
|
||||
// 将每个实例化的角色添加到列表中
|
||||
peopleList.Add(item);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 如果不满足实例化条件,跳过当前NPC的实例化
|
||||
if (!shouldInstantiate)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//=============================================================按钮和点击事件==================================================
|
||||
//处理人员管理按钮
|
||||
//处理人员管理按钮
|
||||
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));
|
||||
//ManagerPanel managerPanelScript = managerPanelInstance.GetComponentInParent<ManagerPanel>();
|
||||
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);
|
||||
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 ClickSureBtn()
|
||||
{
|
||||
// 只有在选择了人员、职责和场景的情况下,才会执行后续操作
|
||||
if (isPersonSelected && isDutySelected && isSceneSelected)
|
||||
{
|
||||
// 保存选中的人员信息到场景数据字典中
|
||||
string sceneName = selectedInfo.scene;
|
||||
|
||||
// 如果场景字典中没有这个场景,先创建一个空列表
|
||||
if (!sceneDataDictionary.ContainsKey(sceneName))
|
||||
// 只有在选择了人员、职责和场景的情况下,才会执行后续操作
|
||||
if (isPersonSelected && isDutySelected && isSceneSelected)
|
||||
{
|
||||
sceneDataDictionary[sceneName] = new List<SelectedInfo>();
|
||||
}
|
||||
// 保存选中的人员信息到场景数据字典中
|
||||
string sceneName = selectedInfo.scene;
|
||||
|
||||
// 需要判断是否达到了职责的人员上限
|
||||
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个此职责的人选
|
||||
// 如果场景字典中没有这个场景,先创建一个空列表
|
||||
if (!sceneDataDictionary.ContainsKey(sceneName))
|
||||
{
|
||||
Debug.LogError($"{selectedInfo.duty} 已达最大人数限制");
|
||||
isLimitReached = true; // 标记限制已达
|
||||
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个此职责的人选
|
||||
{
|
||||
Debug.LogError($"{selectedInfo.duty} 已达最大人数限制");
|
||||
isLimitReached = true; // 标记限制已达
|
||||
}
|
||||
}
|
||||
// 如果没有达到上限,则可以添加人员信息
|
||||
if (!isLimitReached)
|
||||
{
|
||||
// 通过创建一个新的 SelectedInfo 实例来避免引用同一个对象
|
||||
SelectedInfo newSelectedInfo = new SelectedInfo
|
||||
{
|
||||
name = selectedInfo.name,
|
||||
duty = selectedInfo.duty,
|
||||
scene = selectedInfo.scene
|
||||
};
|
||||
|
||||
// 将当前选中的人员信息添加到对应场景的人员列表中
|
||||
currentSceneInfo.Add(newSelectedInfo);
|
||||
|
||||
// 禁用确认按钮并清空选择标志
|
||||
sureBtn.interactable = false;
|
||||
isPersonSelected = false;
|
||||
isDutySelected = false;
|
||||
isSceneSelected = false;
|
||||
|
||||
// 改变已添加人员的显示颜色
|
||||
UpdatePeopleListVisual();
|
||||
}
|
||||
}
|
||||
// 如果没有达到上限,则可以添加人员信息
|
||||
if (!isLimitReached)
|
||||
else
|
||||
{
|
||||
// 通过创建一个新的 SelectedInfo 实例来避免引用同一个对象
|
||||
SelectedInfo newSelectedInfo = new SelectedInfo
|
||||
{
|
||||
name = selectedInfo.name,
|
||||
duty = selectedInfo.duty,
|
||||
scene = selectedInfo.scene
|
||||
};
|
||||
|
||||
// 将当前选中的人员信息添加到对应场景的人员列表中
|
||||
currentSceneInfo.Add(newSelectedInfo);
|
||||
|
||||
// 打印当前场景人员信息
|
||||
//Debug.Log($"场景: {sceneName},选中的人员: {selectedInfo.name},职责: {selectedInfo.duty}");
|
||||
|
||||
// 禁用确认按钮并清空选择标志
|
||||
sureBtn.interactable = false; // 禁用确认按钮
|
||||
isPersonSelected = false;
|
||||
isDutySelected = false;
|
||||
isSceneSelected = false;
|
||||
|
||||
// 改变已添加人员的显示颜色
|
||||
UpdatePeopleListVisual();
|
||||
Debug.LogError("请确保选择了人员、职责和场景!");
|
||||
}
|
||||
datePanel.NumberText.text = "共" + (sceneDataDictionary.Keys.Count * sceneDataDictionary.Values.Count).ToString() + "人参与";
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("请确保选择了人员、职责和场景!");
|
||||
}
|
||||
datePanel.NumberText.text ="共"+(sceneDataDictionary.Keys.Count * sceneDataDictionary.Values.Count).ToString()+"人参与";
|
||||
// 可以在这里根据需求继续处理选中的数据
|
||||
}
|
||||
|
||||
//处理界面关闭按钮
|
||||
public void ClickCloseBtn()
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
//获取鼠标点击位置的信息
|
||||
public void GetData()
|
||||
{
|
||||
ManagerPanel managerPanel = new ManagerPanel();
|
||||
|
||||
// 当鼠标左键按下时进行检测
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
// 确保 raycaster 和 eventSystem 不为空
|
||||
if (raycaster == null || eventSystem == null)
|
||||
ManagerPanel managerPanel = new ManagerPanel();
|
||||
|
||||
// 当鼠标左键按下时进行检测
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
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)
|
||||
// 确保 raycaster 和 eventSystem 不为空
|
||||
if (raycaster == null || eventSystem == null)
|
||||
{
|
||||
Text buttonText = clickedButton.GetComponentInChildren<Text>();
|
||||
if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息
|
||||
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>();
|
||||
DutyItem item = clickedButton.GetComponentInParent<DutyItem>();
|
||||
if (clickedButton != null)
|
||||
{
|
||||
name = buttonText.text;
|
||||
Debug.Log(name);
|
||||
selectedInfo.name = name;
|
||||
isPersonSelected = true; // 选择了人员
|
||||
}
|
||||
else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息
|
||||
{
|
||||
scene = buttonText.text;
|
||||
Debug.Log(scene);
|
||||
selectedInfo.scene = scene;
|
||||
isSceneSelected = true; // 选择了场景
|
||||
}
|
||||
else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息
|
||||
{
|
||||
duty = buttonText.text;
|
||||
Debug.Log(duty);
|
||||
selectedInfo.duty = duty;
|
||||
isDutySelected = true; // 选择了职责
|
||||
Text buttonText = clickedButton.GetComponentInChildren<Text>();
|
||||
if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息
|
||||
{
|
||||
name = buttonText.text;
|
||||
Debug.Log(name);
|
||||
selectedInfo.name = name;
|
||||
isPersonSelected = true; // 选择了人员
|
||||
}
|
||||
else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息
|
||||
{
|
||||
scene = buttonText.text;
|
||||
Debug.Log(scene);
|
||||
selectedInfo.scene = scene;
|
||||
isSceneSelected = true; // 选择了场景
|
||||
}
|
||||
else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息
|
||||
{
|
||||
duty = buttonText.text;
|
||||
dutyId = item.dutyId;
|
||||
selectedInfo.duty = duty;
|
||||
isDutySelected = true; // 选择了职责
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 根据选择情况,启用或禁用确认按钮
|
||||
UpdateConfirmButtonState();
|
||||
// 根据选择情况,启用或禁用确认按钮
|
||||
UpdateConfirmButtonState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================功能===========================================
|
||||
|
||||
//判断是否能够点击按钮
|
||||
//判断是否能够点击按钮
|
||||
private void UpdateConfirmButtonState()
|
||||
{
|
||||
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
|
||||
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
|
||||
}
|
||||
{
|
||||
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
|
||||
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
|
||||
}
|
||||
|
||||
//设置安排文字
|
||||
public void SetText()
|
||||
{
|
||||
arrangeText.text = "[" + name + "]担任[" + duty + "],位于[" + scene + "]";
|
||||
}
|
||||
{
|
||||
arrangeText.text = "[" + name + "]担任[" + duty + "],位于[" + scene + "]";
|
||||
}
|
||||
|
||||
//筛选
|
||||
public void SetInputFile()
|
||||
{
|
||||
// 获取输入框内容
|
||||
string filterText = shaixuaninputField.text.Trim();
|
||||
|
||||
// 遍历所有已实例化的人员预制体
|
||||
foreach (Transform child in peopleCountent)
|
||||
{
|
||||
// 获取该子物体上的 Text 组件
|
||||
Text personNameText = child.GetComponentInChildren<Text>();
|
||||
// 获取输入框内容
|
||||
string filterText = shaixuaninputField.text.Trim();
|
||||
|
||||
if (personNameText != null)
|
||||
// 遍历所有已实例化的人员预制体
|
||||
foreach (Transform child in peopleCountent)
|
||||
{
|
||||
// 比较输入框中的内容与人员姓名
|
||||
if (personNameText.text.Contains(filterText))
|
||||
// 获取该子物体上的 Text 组件
|
||||
Text personNameText = child.GetComponentInChildren<Text>();
|
||||
|
||||
if (personNameText != null)
|
||||
{
|
||||
// 如果匹配,显示该人员
|
||||
child.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果不匹配,隐藏该人员
|
||||
child.gameObject.SetActive(false);
|
||||
// 比较输入框中的内容与人员姓名
|
||||
if (personNameText.text.Contains(filterText))
|
||||
{
|
||||
// 如果匹配,显示该人员
|
||||
child.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果不匹配,隐藏该人员
|
||||
child.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 点击选中角色,改变视觉效果(可复用)
|
||||
public void OnPeopleItemClicked(GameObject clickedItem,Color color,GameObject select)
|
||||
public void OnPeopleItemClicked(GameObject clickedItem, Color color, GameObject select)
|
||||
{
|
||||
// 如果有之前选中的角色,重置其视觉效果
|
||||
if (select != null)
|
||||
if (select != null && select != clickedItem)
|
||||
{
|
||||
Text prevText = select.GetComponentInChildren<Text>();
|
||||
if (prevText != null)
|
||||
@ -403,7 +396,7 @@ public class Panel : MonoBehaviour
|
||||
}
|
||||
|
||||
// 设置当前选中的角色为选中状态
|
||||
select = clickedItem;
|
||||
select = clickedItem; // 更新选中人物
|
||||
Text personText = clickedItem.GetComponentInChildren<Text>();
|
||||
if (personText != null)
|
||||
{
|
||||
@ -415,29 +408,30 @@ public class Panel : MonoBehaviour
|
||||
|
||||
// 更新人员列表的显示颜色
|
||||
private void UpdatePeopleListVisual()
|
||||
{
|
||||
// 遍历所有已加载的人员预制体,检查是否已添加到场景
|
||||
foreach (GameObject personItem in peopleList)
|
||||
{
|
||||
// 获取人员的名字和显示文本
|
||||
Text personText = personItem.GetComponentInChildren<Text>();
|
||||
|
||||
if (personText != null)
|
||||
// 遍历所有已加载的人员预制体,检查是否已添加到场景
|
||||
foreach (GameObject personItem in peopleList)
|
||||
{
|
||||
// 检查该人员是否已经添加到当前场景
|
||||
bool isPersonAdded = sceneDataDictionary[selectedInfo.scene].Any(info => info.name == personText.text);
|
||||
// 获取人员的名字和显示文本
|
||||
Text personText = personItem.GetComponentInChildren<Text>();
|
||||
|
||||
// 如果该人员已经被添加到场景,改变颜色为灰色
|
||||
if (isPersonAdded)
|
||||
if (personText != null)
|
||||
{
|
||||
personText.color = Color.blue; // 已添加人员的颜色
|
||||
}
|
||||
else
|
||||
{
|
||||
personText.color = Color.white; // 未添加人员的颜色
|
||||
// 检查该人员是否已经添加到当前场景
|
||||
bool isPersonAdded = sceneDataDictionary[selectedInfo.scene].Any(info => info.name == personText.text);
|
||||
|
||||
// 如果该人员已经被添加到场景,改变颜色为灰色
|
||||
if (isPersonAdded)
|
||||
{
|
||||
personText.color = Color.blue; // 已添加人员的颜色
|
||||
}
|
||||
else
|
||||
{
|
||||
personText.color = Color.white; // 未添加人员的颜色
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ public class DutyItem : MonoBehaviour
|
||||
public Text dutyNameText;
|
||||
public Button button;
|
||||
public int leader;
|
||||
public int dutyId;
|
||||
public Color defaultColor = Color.white; // 默认颜色
|
||||
public Color addedColor = Color.gray; // 已添加颜色
|
||||
public Color selectedColor = Color.yellow; // 选中颜色
|
||||
|
@ -104,9 +104,6 @@ public class EvacuationPanel : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//private void Submit()
|
||||
//{
|
||||
// //int count = int.Parse(StuCountInputField.text);//×ÜÈËÊý
|
||||
@ -298,9 +295,7 @@ public class EvacuationPanel : MonoBehaviour
|
||||
CountsubmitBtn.onClick.AddListener(Countsubmit);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public void Countsubmit()
|
||||
{
|
||||
@ -329,9 +324,4 @@ public class EvacuationPanel : MonoBehaviour
|
||||
classItemList.Add(classItem);
|
||||
}
|
||||
}
|
||||
//Npc分配
|
||||
public void NpcDistribution()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ public class ManagerPanel : MonoBehaviour
|
||||
// 实例化一个人员项并将其作为场景面板的子物体
|
||||
GameObject item = Instantiate(personItemPrefab, contentTransform);
|
||||
ArrangementItem arrangementItem = item.GetComponent<ArrangementItem>();
|
||||
|
||||
arrangementItem.name.text = person.name; // 设置姓名
|
||||
arrangementItem.duty.text = person.duty; // 设置职责
|
||||
}
|
||||
@ -84,6 +83,7 @@ public class ManagerPanel : MonoBehaviour
|
||||
// 使当前选中的项居中显示
|
||||
//CenterOnItem(clickedItemRT);
|
||||
}
|
||||
|
||||
// 使选中的项居中显示
|
||||
private void CenterOnItem(RectTransform item)
|
||||
{
|
||||
|
@ -157,10 +157,6 @@ public class SelectScenePanel : MonoBehaviour
|
||||
// 将 Toggle 添加到 ToggleGroup 中
|
||||
toggle.group = eventGroup;
|
||||
toggle.isOn = false;
|
||||
|
||||
// 将 Toggle 添加到 schooltoggleList 中
|
||||
|
||||
// 将 SchoolInfo 对象添加到 schoolInfos 列表中
|
||||
eventInfoList.Add(item);
|
||||
Debug.Log("!!!!!!!!!!!!!!!!!!!!!" + eventInfoList.Count);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user