This commit is contained in:
huyulong 2024-12-11 11:11:01 +08:00
commit e0275fd030
17 changed files with 5579 additions and 1049 deletions

View File

@ -115,7 +115,7 @@ MonoBehaviour:
sceneId: 0 sceneId: 0
sceneType: 0 sceneType: 0
sceneName: {fileID: 5207661254087907526} sceneName: {fileID: 5207661254087907526}
sceneImage: {fileID: 0} sceneImage: {fileID: 5207661254004645192}
maskImage: {fileID: 0} maskImage: {fileID: 0}
roleLimit: roleLimit:
limitNum: 0 limitNum: 0

View File

@ -140,6 +140,8 @@ MonoBehaviour:
sceneText: {fileID: 6013369223126947389} sceneText: {fileID: 6013369223126947389}
personnelImage: {fileID: 6013369224158235502} personnelImage: {fileID: 6013369224158235502}
personnelNum: {fileID: 6013369223785314021} personnelNum: {fileID: 6013369223785314021}
sceneId: 0
Num: 0
--- !u!1 &6013369223126947387 --- !u!1 &6013369223126947387
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -151,8 +153,9 @@ GameObject:
- component: {fileID: 6013369223126947388} - component: {fileID: 6013369223126947388}
- component: {fileID: 6013369223126947390} - component: {fileID: 6013369223126947390}
- component: {fileID: 6013369223126947389} - component: {fileID: 6013369223126947389}
- component: {fileID: 6166932461062257870}
m_Layer: 5 m_Layer: 5
m_Name: Text (Legacy) m_Name: sceneText
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -220,6 +223,50 @@ MonoBehaviour:
m_VerticalOverflow: 0 m_VerticalOverflow: 0
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: "\u53A8\u623F" m_Text: "\u53A8\u623F"
--- !u!114 &6166932461062257870
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6013369223126947387}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 6013369223126947389}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &6013369223785314019 --- !u!1 &6013369223785314019
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -299,7 +346,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 0 m_VerticalOverflow: 0
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: 5 m_Text:
--- !u!1 &6013369224158235500 --- !u!1 &6013369224158235500
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -317,7 +364,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &6013369224158235501 --- !u!224 &6013369224158235501
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1866,6 +1866,11 @@ RectTransform:
m_AnchoredPosition: {x: -700, y: 111} m_AnchoredPosition: {x: -700, y: 111}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &569417021 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 4764228632217023203, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
m_PrefabInstance: {fileID: 1799705458}
m_PrefabAsset: {fileID: 0}
--- !u!1 &580293850 --- !u!1 &580293850
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2133,7 +2138,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &618256459 --- !u!224 &618256459
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2206,7 +2211,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 618256458} m_GameObject: {fileID: 618256458}
m_Enabled: 1 m_Enabled: 0
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 05b11d619e5d88a439384d80484d6952, type: 3} m_Script: {fileID: 11500000, guid: 05b11d619e5d88a439384d80484d6952, type: 3}
m_Name: m_Name:
@ -2248,6 +2253,11 @@ MonoBehaviour:
jsonReader1: {fileID: 1417128757} jsonReader1: {fileID: 1417128757}
selectScenePanel: {fileID: 7468736064579811982} selectScenePanel: {fileID: 7468736064579811982}
datePanel: {fileID: 468742199} datePanel: {fileID: 468742199}
--- !u!224 &621287107 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 51007377463830339, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
m_PrefabInstance: {fileID: 1799705458}
m_PrefabAsset: {fileID: 0}
--- !u!1 &625672672 --- !u!1 &625672672
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3403,7 +3413,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &805990076 --- !u!224 &805990076
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -10119,10 +10129,30 @@ PrefabInstance:
propertyPath: panel propertyPath: panel
value: value:
objectReference: {fileID: 618256462} objectReference: {fileID: 618256462}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: classCount
value:
objectReference: {fileID: 569417021}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} - target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: jsonReader propertyPath: jsonReader
value: value:
objectReference: {fileID: 1417128757} objectReference: {fileID: 1417128757}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: sceneCount
value:
objectReference: {fileID: 621287107}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: scenePrefab
value:
objectReference: {fileID: 6833246911785287183, guid: eec456cfeada31d4b84c2ba45b21163e, type: 3}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: selectScene
value:
objectReference: {fileID: 7468736064579811982}
- target: {fileID: 2102021661377337229, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: jueseChoicePanel
value:
objectReference: {fileID: 1799705462}
- target: {fileID: 4764228630647718977, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} - target: {fileID: 4764228630647718977, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
value: 0 value: 0
@ -10307,6 +10337,14 @@ PrefabInstance:
propertyPath: m_IsActive propertyPath: m_IsActive
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 9196293257107006895, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: panel
value:
objectReference: {fileID: 618256462}
- target: {fileID: 9196293257107006895, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: jsonReader
value:
objectReference: {fileID: 1417128757}
- target: {fileID: 9196293257811847185, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3} - target: {fileID: 9196293257811847185, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
propertyPath: m_SizeDelta.x propertyPath: m_SizeDelta.x
value: -22.699951 value: -22.699951
@ -10334,6 +10372,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: da23ef65e616ad3499db22bf6ad52794, type: 3} m_Script: {fileID: 11500000, guid: da23ef65e616ad3499db22bf6ad52794, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!1 &1799705462 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 9196293257107006892, guid: 86668fbe8407a8741bb903177bc93fdb, type: 3}
m_PrefabInstance: {fileID: 1799705458}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1809649275 --- !u!1 &1809649275
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -14631,9 +14674,9 @@ RectTransform:
m_Father: {fileID: 7468736063934366934} m_Father: {fileID: 7468736063934366934}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 334.1322, y: -55}
m_SizeDelta: {x: 187, y: 110} m_SizeDelta: {x: 187, y: 110}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7468736064122132329 --- !u!1 &7468736064122132329
@ -14914,9 +14957,9 @@ RectTransform:
m_Father: {fileID: 7468736063934366934} m_Father: {fileID: 7468736063934366934}
m_RootOrder: 3 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 753.3966, y: -55}
m_SizeDelta: {x: 187, y: 110} m_SizeDelta: {x: 187, y: 110}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7468736064198941274 --- !u!1 &7468736064198941274
@ -15674,7 +15717,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 3.3229} m_AnchoredPosition: {x: 0, y: 3.3229}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 1834, y: 1070}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7468736064579811972 --- !u!1 &7468736064579811972
GameObject: GameObject:
@ -15696,7 +15739,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!114 &7468736064579811982 --- !u!114 &7468736064579811982
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -16154,9 +16197,9 @@ RectTransform:
m_Father: {fileID: 7468736063934366934} m_Father: {fileID: 7468736063934366934}
m_RootOrder: 2 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 543.7644, y: -55}
m_SizeDelta: {x: 187, y: 110} m_SizeDelta: {x: 187, y: 110}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7468736064659112359 --- !u!1 &7468736064659112359
@ -16360,9 +16403,9 @@ RectTransform:
m_Father: {fileID: 7468736064579811971} m_Father: {fileID: 7468736064579811971}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 917, y: -53.335}
m_SizeDelta: {x: 1834, y: 106.67} m_SizeDelta: {x: 1834, y: 106.67}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7468736064728012045 --- !u!1 &7468736064728012045
@ -16522,9 +16565,9 @@ RectTransform:
m_Father: {fileID: 7468736063934366934} m_Father: {fileID: 7468736063934366934}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 124.5, y: -55}
m_SizeDelta: {x: 187, y: 110} m_SizeDelta: {x: 187, y: 110}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7468736064820222392 --- !u!1 &7468736064820222392
@ -16935,9 +16978,9 @@ RectTransform:
m_Father: {fileID: 7468736064579811971} m_Father: {fileID: 7468736064579811971}
m_RootOrder: 4 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 917, y: -588.33496}
m_SizeDelta: {x: 1834, y: 498.685} m_SizeDelta: {x: 1834, y: 498.685}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7468736064937661071 --- !u!1 &7468736064937661071

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: a73dbc35051d4614a8e27d92a0830665 guid: 75b789f38488cba4c82fb551bfc6e463
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:

View File

@ -0,0 +1,57 @@
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
//获取房间玩家列表
public class getPlayerList : MonoBehaviour
{
private void Start()
{
GetPlayerList();
}
// 创建请求头,使用最新的 token
public Dictionary<string, string> CreateHeaders()
{
return new Dictionary<string, string>
{
{ "Authorization","Bearer "+GlobalData.ServerData.data.access_token },
{"clientId", "e5cd7e4891bf95d1d19206ce24a7b32e" }
};
}
//
public async Task<PlayerListResponse> GetPlayerList()
{
string response = await web.SendRequest(web.URL + "/admin/companyUser/player/list", "GET", "{}", CreateHeaders());
Debug.Log("获取演练账号列表" + response);
// 解析服务器返回的数据
PlayerListResponse playerListResponse = JsonConvert.DeserializeObject<PlayerListResponse>(response);
Debug.Log(playerListResponse.data[0].UserName);
return playerListResponse;
}
}
//=====================================================================================================================
public class PlayerListResponse : Response
{
public List<PlayerListData> data { get; set; }
}
public class PlayerListData
{
public string UserName { get; set; }
public string Id { get; set; }
public string CompanyId { get; set; }
public string UserId { get; set; }
public string IsAdmin { get; set; }
public string Status { get; set; }
public string Remark { get; set; } // 可以为null通常使用string类型
public string DepartmentName { get; set; }
public string PostName { get; set; }
public string NickName { get; set; }
public string CreateTime { get; set; }
}

View File

@ -241,6 +241,17 @@ public class JSONReader : MonoBehaviour
return null; // 如果没有找到符合条件的语言数据,返回 null return null; // 如果没有找到符合条件的语言数据,返回 null
} }
public LocationData GetAreaDateById(int id)
{
LocationData info = null;
if (locationDictionary.TryGetValue(id, out info))
{
return info;
}
else return null;
}
public SceneData GetSceneById(int id) public SceneData GetSceneById(int id)
{ {
SceneData info = null; SceneData info = null;

View File

@ -18,6 +18,7 @@ public class SelectedInfo
public string duty;//职责 public string duty;//职责
public string scene;//场景名 public string scene;//场景名
public string leader;//是否组长 public string leader;//是否组长
public int sceneId;//场景Id
public int dutyId;//职责的Id public int dutyId;//职责的Id
} }
@ -163,7 +164,6 @@ public class Panel : MonoBehaviour
} }
} }
} }
//动态加载场景 //动态加载场景
public void DynamicLoadingScene() public void DynamicLoadingScene()
{ {
@ -199,6 +199,7 @@ public class Panel : MonoBehaviour
Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>(); Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene)); scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene));
// 设置limitNum // 设置limitNum
sceneItem.sceneId = npcData.Key;
sceneItem.dutyId = int.Parse(roleLimits[1]); sceneItem.dutyId = int.Parse(roleLimits[1]);
sceneItem.limitNum = int.Parse(roleLimits[2]); sceneItem.limitNum = int.Parse(roleLimits[2]);
sceneItem.sceneName.text = npcData.Value.Note; sceneItem.sceneName.text = npcData.Value.Note;
@ -275,8 +276,21 @@ public class Panel : MonoBehaviour
{ {
GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount); GameObject item = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
SceneItem sceneItem = item.GetComponent<SceneItem>(); 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>(); Button scenebutton = item.transform.Find("TextBtn").GetComponent<Button>();
scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene)); scenebutton.onClick.AddListener(() => OnSceneItemClicked(item, Color.green, selectedScene));
sceneItem.sceneId = npcData.Key;
sceneItem.dutyId = accidentLocationId; sceneItem.dutyId = accidentLocationId;
sceneItem.limitNum = minRequired; sceneItem.limitNum = minRequired;
sceneItem.sceneName.text = npcData.Value.Note; sceneItem.sceneName.text = npcData.Value.Note;
@ -287,68 +301,84 @@ public class Panel : MonoBehaviour
} }
} }
} }
// 获取当前该位置该职业的已添加人数
private int GetCurrentPeopleCount(int accidentLocationId, int 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() public void ClickSureBtn()
{ {
// 只有在选择了人员、职责和场景的情况下,才会执行后续操作 // 只有在选择了人员、职责和场景的情况下,才会执行后续操作
if (isPersonSelected && isDutySelected && isSceneSelected) if (isPersonSelected && isDutySelected && isSceneSelected)
{
// 保存选中的人员信息到场景数据字典中
string sceneName = selectedInfo.scene;
// 如果场景字典中没有这个场景,先创建一个空列表
if (!sceneDataDictionary.ContainsKey(sceneName))
{ {
// 保存选中的人员信息到场景数据字典中 sceneDataDictionary[sceneName] = new List<SelectedInfo>();
string sceneName = selectedInfo.scene; }
// 如果场景字典中没有这个场景,先创建一个空列表 // 需要判断是否达到了职责的人员上限
if (!sceneDataDictionary.ContainsKey(sceneName)) 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个此职责的人选
{ {
sceneDataDictionary[sceneName] = new List<SelectedInfo>(); isLimitReached = true; // 标记限制已达
}
// 需要判断是否达到了职责的人员上限
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,
dutyId= selectedInfo.dutyId
};
// 将当前选中的人员信息添加到对应场景的人员列表中
currentSceneInfo.Add(newSelectedInfo);
// 禁用确认按钮并清空选择标志
sureBtn.interactable = false;
isPersonSelected = false;
isDutySelected = false;
isSceneSelected = false;
// 改变已添加人员的显示颜色
UpdatePeopleListVisual();
} }
} }
else // 如果没有达到上限,则可以添加人员信息
if (!isLimitReached)
{ {
Debug.LogError("请确保选择了人员、职责和场景!"); Debug.Log(">>>>>>>>>>>>>>>>>>>"+ selectedInfo.dutyId);
// 通过创建一个新的 SelectedInfo 实例来避免引用同一个对象
SelectedInfo newSelectedInfo = new SelectedInfo
{
name = selectedInfo.name,
duty = selectedInfo.duty,
scene = selectedInfo.scene,
dutyId = selectedInfo.dutyId,
sceneId = selectedInfo.sceneId
};
// 将当前选中的人员信息添加到对应场景的人员列表中
currentSceneInfo.Add(newSelectedInfo);
// 禁用确认按钮并清空选择标志
sureBtn.interactable = false;
isPersonSelected = false;
isDutySelected = false;
isSceneSelected = false;
// 改变已添加人员的显示颜色
UpdatePeopleListVisual();
} }
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() public void ClickCloseBtn()
@ -358,67 +388,78 @@ public class Panel : MonoBehaviour
//获取鼠标点击位置的信息 //获取鼠标点击位置的信息
public void GetData() public void GetData()
{ {
ManagerPanel managerPanel = new ManagerPanel(); ManagerPanel managerPanel = new ManagerPanel();
// 当鼠标左键按下时进行检测 // 当鼠标左键按下时进行检测
if (Input.GetMouseButtonDown(0)) if (Input.GetMouseButtonDown(0))
{
// 确保 raycaster 和 eventSystem 不为空
if (raycaster == null || eventSystem == null)
{ {
// 确保 raycaster 和 eventSystem 不为空 Debug.LogError("Raycaster 或 EventSystem 未正确分配,请在 Inspector 中进行分配。");
if (raycaster == null || eventSystem == null) 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)
{ {
Debug.LogError("Raycaster 或 EventSystem 未正确分配,请在 Inspector 中进行分配。"); Text buttonText = clickedButton.GetComponentInChildren<Text>();
return; if (buttonText != null && buttonText.tag == Tags.people) // 获取标签为人员的信息
} {
name = buttonText.text;
// 创建 PointerEventData 来记录点击事件的数据 Debug.Log(name);
PointerEventData pointerData = new PointerEventData(eventSystem); selectedInfo.name = name;
pointerData.position = Input.mousePosition; // 获取鼠标点击的位置 isPersonSelected = true; // 选择了人员
}
// 用于存储射线检测的结果 else if (buttonText != null && buttonText.tag == Tags.scene) // 获取标签为场景的信息
List<RaycastResult> results = new List<RaycastResult>(); {
scene = buttonText.text;
// 射线检测 UI SceneItem sceneItem = buttonText.gameObject.GetComponentInParent<SceneItem>();
raycaster.Raycast(pointerData, results); selectedInfo.scene = scene;
selectedInfo.sceneId= sceneItem.sceneId;
// 遍历射线检测的结果 isSceneSelected = true; // 选择了场景
foreach (RaycastResult result in results) }
{ else if (buttonText != null && buttonText.tag == Tags.duty) // 获取标签为职责的信息
// 检测到点击了按钮
Button clickedButton = result.gameObject.GetComponent<Button>();
if (clickedButton != null)
{ {
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) // 获取标签为职责的信息
{
DutyItem item = clickedButton.GetComponentInParent<DutyItem>();
duty = buttonText.text; duty = buttonText.text;
dutyId = item.dutyId; DutyItem item = clickedButton.GetComponentInParent<DutyItem>();
selectedInfo.duty = duty; if(duty=="主持人")
{
isDutySelected = true; // 选择了职责 isDutySelected = true; // 选择了职责
isSceneSelected = true;
} }
else
{
isDutySelected = true;
isSceneSelected = false;
}
dutyId = item.dutyId;
selectedInfo.duty = duty;
selectedInfo.dutyId = dutyId;
} }
} }
// 根据选择情况,启用或禁用确认按钮
UpdateConfirmButtonState();
} }
// 根据选择情况,启用或禁用确认按钮
UpdateConfirmButtonState();
} }
}
//==========================================================功能=========================================== //==========================================================功能===========================================
@ -448,6 +489,7 @@ public class Panel : MonoBehaviour
//判断确认按钮是否可以点击 //判断确认按钮是否可以点击
private void UpdateConfirmButtonState() private void UpdateConfirmButtonState()
{ {
if(isDutySelected)
// 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用 // 如果人员、职责和场景都已选择,则启用确认按钮,否则禁用
sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected; sureBtn.interactable = isPersonSelected && isDutySelected && isSceneSelected;
} }

View File

@ -2,22 +2,29 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml.Serialization; using System.Xml.Serialization;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking.Types;
using UnityEngine.UI; using UnityEngine.UI;
using static System.Collections.Specialized.BitVector32; using static System.Collections.Specialized.BitVector32;
using static UnityEditor.Progress; using static UnityEditor.Progress;
public class EvacuationPanel : MonoBehaviour public class EvacuationPanel : MonoBehaviour
{ {
public Dictionary<string, int> distributePeople = new Dictionary<string, int>(); public Dictionary<string, int> distributePeople = new Dictionary<string, int>();// 分配给各个场景的人数
public List<PersonnelItem> personnelItems; public List<PersonnelItem> personnelItems;
public Transform personnelContent; public Transform personnelContent;
public Panel panel; public Panel panel;
public GameObject personnelPrefabs; public GameObject personnelPrefabs;
public GameObject classPrefab; public GameObject classPrefab;
public GameObject classCount;//
public GameObject scenePrefab;//区域预制体
public Transform sceneCount;//区域预制体的容器
public GameObject jueseChoicePanel;
public Transform content; public Transform content;
public Text topText; public Text topText;
private GameObject selectedScene = null;//当前选中场景
public List<ClassItem> classItemList = new List<ClassItem>(); public List<ClassItem> classItemList = new List<ClassItem>();
public List<ClassMate> classMateList = new List<ClassMate>(); public List<ClassMate> classMateList = new List<ClassMate>();
@ -43,21 +50,40 @@ public class EvacuationPanel : MonoBehaviour
public string npcType; public string npcType;
public string roleid; public string roleid;
[Header("可分配列表")]
List<int> nonZeroAreas = new List<int>();
Dictionary<int, PersonnelItem> personnelItemsDict = new Dictionary<int, PersonnelItem>();
private HashSet<int> excludedAreas = new HashSet<int>(); // 被清空的区域 ID
public SelectScenePanel selectScene;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
SetNpcType(); SetNpcType();
nonZeroAreas= GetNonZeroNpcRatioAreas();
jc = JuesechoicePop.GetComponent<JueseChoicePop>(); jc = JuesechoicePop.GetComponent<JueseChoicePop>();
//redistributeBtn.onClick.AddListener(ClearData);
redistributeBtn.onClick.AddListener(ClearData); redistributeBtn.onClick.AddListener(() =>
{
if (redistributeBtn.interactable)
{
Debug.Log("Redistribute button clicked!");
RedistributeLogic();
}
});
CountsubmitBtn.onClick.AddListener(Submit); CountsubmitBtn.onClick.AddListener(Submit);
submitBtn.onClick.AddListener(totalSubmit); submitBtn.onClick.AddListener(totalSubmit);
StuCountInputField.onEndEdit.AddListener(CheckInput); StuCountInputField.onEndEdit.AddListener(CheckInput);
SetClass(); SetClass();
} }
void Update()
{
CheckInput(StuCountInputField.text);
IsRedistribution();
IsOpen(selectScene.difficultyId);
}
//上传数据
public void totalSubmit() public void totalSubmit()
{ {
Debug.Log(createTemplateInfo.Instance.auth_CreateTemplate + "==============="); Debug.Log(createTemplateInfo.Instance.auth_CreateTemplate + "===============");
@ -66,23 +92,16 @@ public class EvacuationPanel : MonoBehaviour
nPC.roleId = roleid; nPC.roleId = roleid;
createTemplateInfo.Instance.auth_CreateTemplate.npcList = new List<NpcList>(); createTemplateInfo.Instance.auth_CreateTemplate.npcList = new List<NpcList>();
createTemplateInfo.Instance.auth_CreateTemplate.npcList.Add(nPC); createTemplateInfo.Instance.auth_CreateTemplate.npcList.Add(nPC);
//foreach(NpcList item in createTemplateInfo.Instance.auth_CreateTemplate.npcList)
//{
// Debug.Log("npcType>>>>>>>>>>>>>>>>>" + item.userId);
// Debug.Log("roleid>>>>>>>>>>>>>>>>>" + item.roleId);
//}
} }
public void SetNpcType() public void SetNpcType()
{ {
foreach (var scene in panel.sceneDataDictionary) foreach (var scene in panel.sceneDataDictionary)
{ {
Debug.Log("+++++++++++");
foreach (var npcData in js.locationDictionary) foreach (var npcData in js.locationDictionary)
{ {
// 解析角色限制字段 // 解析角色限制字段
string roleLimit = npcData.Value.NpcRatio; string roleLimit = npcData.Value.NpcRatio;
if(npcData.Value.NpcRatio=="-1") if(npcData.Value.NpcRatio=="-1")
{ {
continue; continue;
@ -98,190 +117,260 @@ public class EvacuationPanel : MonoBehaviour
roleid = roleLimitSections[0]; roleid = roleLimitSections[0];
} }
} }
} }
} }
} }
//private void Submit()
//{
// //int count = int.Parse(StuCountInputField.text);//总人数
// //StuCountInputField.text = "";
// //int initialPeople = panel.sceneDataDictionary.Keys.Count* panel.sceneDataDictionary.Values.Count;//已经分了的人
// //string[] sceneNames = { };
// //for(int i = 0; i< panel.sceneDataDictionary.Keys.Count;i++)//拿场景名称
// //{
// // foreach(var item in panel.sceneDataDictionary.Keys)
// // {
// // sceneNames[i] = item;
// // }
// //}
// //distributePeople = DistributePeople(sceneNames, initialPeople, count);
// //foreach(var item in distributePeople)
// //{
// // Debug.Log(item.Value);
// //}
// int count = int.Parse(StuCountInputField.text); // 总人数
// StuCountInputField.text = "";
// // 已经分配的人员数量
// int initialPeople = panel.sceneDataDictionary.Keys.Count * panel.sceneDataDictionary.Values.Count;
// // 动态创建sceneNames数组大小为场景数量
// string[] sceneNames = new string[panel.sceneDataDictionary.Keys.Count];
// // 遍历场景数据字典并填充sceneNames数组
// int i = 0;
// foreach (var item in panel.sceneDataDictionary.Keys)
// {
// sceneNames[i] = item;
// i++;
// }
// // 调用分配人员函数
// distributePeople = DistributePeople(sceneNames, initialPeople, count);
// // 输出分配结果
// foreach (var item in distributePeople)
// {
// //Debug.Log(item.Value);
// foreach(var a in personnelItems)
// {
// a.SetInfo(item.Value.ToString());
// }
// }
//}
private void Submit() private void Submit()
{ {
// 获取输入的总人数 // 获取输入的总人数
int count = int.Parse(StuCountInputField.text); // 总人数 int count = int.Parse(StuCountInputField.text); // 总人数
StuCountInputField.text = ""; StuCountInputField.text = "";
// 计算已分配的人员数量 foreach (var item in personnelItems)
int initialPeople = 0;
foreach (var item in panel.sceneDataDictionary.Values)
{ {
initialPeople += item.Count; // 假设每个场景的Value是一个List或类似的结构其中包含该场景下的所有人员 personnelItemsDict[item.sceneId] = item; // 使用 sceneId 作为键
} }
// 动态创建sceneNames数组大小为场景数量 // 将 nonZeroAreas 转换为场景 ID 数组
string[] sceneNames = new string[panel.sceneDataDictionary.Keys.Count]; int[] sceneIds = nonZeroAreas.ToArray();
// 填充sceneNames数组 // 调用分配方法
int i = 0; var result = DistributePeopleWithBalance(sceneIds, personnelItemsDict, count);
foreach (var item in panel.sceneDataDictionary.Keys)
// 更新 UI 显示
foreach (var kvp in result)
{ {
sceneNames[i] = item; if (personnelItemsDict.ContainsKey(kvp.Key))
i++;
}
// 调用分配人员函数(假设该函数处理人员分配的逻辑)
distributePeople = DistributePeople(sceneNames, initialPeople, count);
// 输出分配结果
foreach (var item in distributePeople)
{
// 假设 personnelItems 是存储UI元素的列表
foreach (var a in personnelItems)
{ {
a.SetInfo(item.Value.ToString()); personnelItemsDict[kvp.Key].SetInfo(kvp.Value.ToString()); // 更新UI
personnelItemsDict[kvp.Key].personnelImage.gameObject.SetActive(true);
} }
} }
} }
public Dictionary<int, int> DistributePeopleWithBalance(int[] scenes, Dictionary<int, PersonnelItem> personnelItemsDict, int totalPeople)
public static Dictionary<string, int> DistributePeople(string[] scenes, int initialPeople, int totalPeople)
{ {
// 1. 计算已分配的人员数 // 1. 计算当前每个区域的总人数(初始人数 + 已分配人数)
int totalAssigned = initialPeople; Dictionary<int, int> totalPeoplePerScene = new Dictionary<int, int>();
//foreach (var scene in scenes)
//{
// if (initialPeople.ContainsKey(scene))
// {
// totalAssigned += initialPeople[scene];
// }
//}
// 2. 计算剩余人员数
int remainingPeople = totalPeople - totalAssigned;
// 3. 将剩余人员平均分配到所有场景中
Dictionary<string, int> finalDistribution = new Dictionary<string, int>(initialPeople);
int peoplePerScene = remainingPeople / scenes.Length;
int extraPeople = remainingPeople % scenes.Length; // 计算余数
// 4. 每个场景分配均等的人员
foreach (var scene in scenes) foreach (var scene in scenes)
{ {
if (finalDistribution.ContainsKey(scene)) // 如果 personnelItemsDict 中包含该场景,取其初始人数;否则设为 0
if (personnelItemsDict.ContainsKey(scene))
{ {
finalDistribution[scene] += peoplePerScene; // 均分的人员 totalPeoplePerScene[scene] = personnelItemsDict[scene].Num; // 初始人数
} }
else else
{ {
finalDistribution[scene] = peoplePerScene; // 新场景初始化 totalPeoplePerScene[scene] = 0;
}
// Debug 输出每个场景的初始人数
Debug.Log($"Scene {scene}: Initial People = {totalPeoplePerScene[scene]}");
}
// 保存初始人数以便后续计算
Dictionary<int, int> initialPeoplePerScene = new Dictionary<int, int>(totalPeoplePerScene);
// 2. 分配剩余人数
int remainingPeople = totalPeople;
while (remainingPeople > 0)
{
// 找出当前人数最少的区域
int minScene = -1; // 用于记录人数最少的场景 ID
int minPeople = int.MaxValue;
foreach (var scene in totalPeoplePerScene)
{
if (scene.Value < minPeople)
{
minPeople = scene.Value;
minScene = scene.Key;
}
}
// 分配一个 NPC 到人数最少的区域
if (minScene != -1) // 确保找到有效的场景
{
totalPeoplePerScene[minScene]++;
remainingPeople--;
}
else
{
break; // 如果没有找到有效的场景,终止分配
} }
} }
// 5. 随机分配余数人员 // 3. 计算分配结果,减去初始人数
System.Random rand = new System.Random(); Dictionary<int, int> allocatedPeople = new Dictionary<int, int>();
for (int i = 0; i < extraPeople; i++) foreach (var scene in totalPeoplePerScene)
{ {
string randomScene = scenes[rand.Next(scenes.Length)]; int initialPeople = initialPeoplePerScene.GetValueOrDefault(scene.Key, 0);
finalDistribution[randomScene]++; allocatedPeople[scene.Key] = scene.Value - initialPeople; // 分配人数 = 总人数 - 初始人数
} }
return finalDistribution; return allocatedPeople;
} }
//清除
//private void ClearData()
//{
// jc.classItem.isSet = false;
// foreach (var item in classItemList)
// {
// item.isSet = false;
// item.setClassItem("");
// }
// jc.classMate.isBeSet = false;
// foreach(var item in jc.classMateList)
// {
// item.isBeSet = false;
// item.setName();
// }
//}
private void ClearData() //判断NPC的比例字段列出分配比例不为0的所有区域名称。
public List<int> GetNonZeroNpcRatioAreas()
{ {
jc.classItem.isSet = false; List<int> nonZeroAreas = new List<int>();
foreach (var item in classItemList)
foreach (var sceneEntry in panel.sceneDataDictionary)
{ {
item.isSet = false; foreach (var sceneInfo in sceneEntry.Value)
item.setClassItem(""); {
foreach (var npcData in js.locationDictionary)
{
LocationData locationData = npcData.Value;
// 如果场景的 ID 匹配当前 NPC 的 ID
if (locationData.ID == sceneInfo.sceneId)
{
// 获取每个区域的 NpcRatio 字段
string npcRatio = locationData.NpcRatio;
// 将 NpcRatio 字符串按 '|' 分割,获取每一项
string[] npcRatioEntries = npcRatio.Split('|');
// 遍历每一项
foreach (var entry in npcRatioEntries)
{
// 将每一项按 ',' 分割获取事故位置、NPCID、归属和分配比例
string[] entryData = entry.Split(',');
if (entryData.Length == 4)
{
string allocationRatio = entryData[3]; // 获取分配比例
// 检查分配比例是否不为 "0" 和 "-1"
if (allocationRatio != "0" && allocationRatio != "-1")
{
// 如果比例不为0将该区域 ID 添加到列表
nonZeroAreas.Add(locationData.ID);
Debug.Log("locationData.ID"+ locationData.ID);
break; // 一旦找到有效的分配比例,就不再检查当前区域的其他项
}
}
}
}
}
}
} }
jc.classMate.isBeSet = false; // 输出所有分配比例不为0的区域 ID
foreach (var area in nonZeroAreas)
foreach(var item in jc.classMateList)
{ {
item.isBeSet = false; Debug.Log("区域 ID" + area);
item.setName();
} }
// 返回符合条件的区域 ID 列表
return nonZeroAreas;
} }
// Update is called once per frame //设置左侧场景显示
void Update()
{
CheckInput(StuCountInputField.text);
}
public void SetPersonnel() public void SetPersonnel()
{ {
// 清空现有的UI项
foreach (Transform child in personnelContent) foreach (Transform child in personnelContent)
{ {
Destroy(child.gameObject); Destroy(child.gameObject);
} }
// 清空人员列表
personnelItems.Clear();
foreach (var sceneEntry in panel.sceneDataDictionary) foreach (var sceneEntry in panel.sceneDataDictionary)
{ {
GameObject item = GameObject.Instantiate<GameObject>(personnelPrefabs, personnelContent); foreach (var sceneInfo in sceneEntry.Value)
PersonnelItem personnelItem=item.GetComponent<PersonnelItem>(); {
personnelItems.Add(personnelItem); LocationData area = js.GetAreaDateById(sceneInfo.sceneId);
personnelItem.sceneText.text = sceneEntry.Key; // 如果NpcRatio不为"-1"表示该场景有效
personnelItem.personnelNum.text = sceneEntry.Value.Count.ToString(); if (area.NpcRatio != "-1")
{
// 检查 personnelItems 是否已经包含该 sceneText.text
var existingItem = personnelItems.Find(item => item.sceneText.text == sceneEntry.Key);
if (existingItem != null)
{
// 如果已经存在,增加 Num
existingItem.Num++;
}
else
{
// 如果没有重复的 personnelItem创建并添加
GameObject item = GameObject.Instantiate(personnelPrefabs, personnelContent);
PersonnelItem personnelItem = item.GetComponent<PersonnelItem>();
Button button = personnelItem.transform.Find("sceneText").GetComponent<Button>();
personnelItem.sceneText.text = sceneEntry.Key;
personnelItem.sceneId = area.ID;
personnelItem.Num = 1; // 设置初始值为 1
button.onClick.AddListener(() =>
{
OnSceneItemClicked(item, Color.yellow, selectedScene);
foreach (Transform child in sceneCount)
{
Destroy(child.gameObject);
}
LocationData locationData = js.GetAreaDateById(personnelItem.sceneId);
if(locationData.Level.ToString() != "0")
{
GameObject levelItem = GameObject.Instantiate<GameObject>(scenePrefab, sceneCount);
Button levelBtn = levelItem.transform.Find("chooseBtn2").GetComponent<Button>();
levelBtn.onClick.AddListener(() =>
{
JueseChoicePop jueseChoicePop= jueseChoicePanel.gameObject.GetComponent<JueseChoicePop>();
jueseChoicePop.SetClass(personnelItem.sceneId);
jueseChoicePanel.gameObject .SetActive(true);
});
ClassItem classItem = levelItem.GetComponent<ClassItem>();
classItem.classname.text = locationData.Level.ToString();
}
});
//Debug.Log("New PersonnelItem created. SceneId: " + personnelItem.sceneId + ", Num: " + personnelItem.Num);
personnelItems.Add(personnelItem);
}
}
else
{
break; // 如果遇到无效场景NpcRatio为-1跳出当前循环
}
}
} }
} }
// 判断重新分配按钮是否可以点击
public void IsRedistribution()
{
// 遍历 personnelItemsDict检查是否有任何 PersonnelItem 的 gameObject 处于激活状态
bool canRedistribute = false;
foreach (var kvp in personnelItemsDict)
{
if (kvp.Value.personnelImage.gameObject.activeSelf) // 检查 gameObject 是否显示
{
canRedistribute = true;
break;
}
}
// 设置重新分配按钮的交互状态
redistributeBtn.interactable = canRedistribute;
}
//判断输入框的数字是否大于1 //判断输入框的数字是否大于1
void CheckInput(string input) void CheckInput(string input)
{ {
@ -292,27 +381,29 @@ public class EvacuationPanel : MonoBehaviour
if (result > 1) if (result > 1)
{ {
CountsubmitBtn.GetComponent<Image>().sprite = rsprite; CountsubmitBtn.GetComponent<Image>().sprite = rsprite;
CountsubmitBtn.onClick.AddListener(Countsubmit); CountsubmitBtn.onClick.AddListener(Countsubmit);
} }
} }
} }
//Npc数量设置按钮置灰设置
public void Countsubmit() public void Countsubmit()
{ {
//按钮置灰 //按钮置灰
CountsubmitBtn.GetComponent<Image>().sprite = fsprite; CountsubmitBtn.GetComponent<Image>().sprite = fsprite;
StuCountInputField.text = string.Empty; StuCountInputField.text = string.Empty;
//按配置对输入的Npc数量进行 分配 //按配置对输入的Npc数量进行 分配
//取消监听 //取消监听
CountsubmitBtn.onClick.RemoveAllListeners(); CountsubmitBtn.onClick.RemoveAllListeners();
} }
//场景ID进行配置 //场景ID进行配置
public void SettopText() public void SettopText()
{ {
topText.text = "以下班级需要设定班主任老师:"; topText.text = "以下班级需要设定班主任老师:";
topText.text = "以下楼层需要设定搜救老师:"; topText.text = "以下楼层需要设定搜救老师:";
} }
//实例化ClassItem //实例化ClassItem
public void SetClass() public void SetClass()
{ {
@ -324,4 +415,102 @@ public class EvacuationPanel : MonoBehaviour
classItemList.Add(classItem); classItemList.Add(classItem);
} }
} }
//重新分配
public void RedistributeLogic()
{
// 计算需要重新分配的 NPC 总数
int totalRedistributePeople = 0;
foreach (var kvp in personnelItemsDict)
{
PersonnelItem item = kvp.Value;
// 如果 gameObject 是激活的,表示需要清空 NPC
if (item.personnelImage.gameObject.activeSelf)
{
totalRedistributePeople += item.Num; // 累加需要重新分配的 NPC 数量
item.Num = 0; // 清空该区域的 NPC 数量
item.SetInfo("0"); // 更新 UI 显示
item.personnelImage.gameObject.SetActive(false); // 隐藏图标
excludedAreas.Add(kvp.Key); // 记录清空的区域 ID
Debug.Log($"Cleared NPCs from Scene ID: {kvp.Key}");
}
}
// 准备有效分配区域列表(排除被清空的区域)
List<int> validAreas = new List<int>();
foreach (var kvp in personnelItemsDict)
{
if (!excludedAreas.Contains(kvp.Key)) // 排除清空的区域
{
validAreas.Add(kvp.Key);
}
}
// 如果没有有效区域,则提示
if (validAreas.Count == 0)
{
Debug.LogWarning("No valid areas available for redistribution.");
return;
}
// 将有效区域转换为数组
int[] validSceneIds = validAreas.ToArray();
// 调用分配方法,将清空区域的 NPC 分配到有效区域
var redistributionResult = DistributePeopleWithBalance(validSceneIds, personnelItemsDict, totalRedistributePeople);
// 更新分配结果到 UI
foreach (var kvp in redistributionResult)
{
if (personnelItemsDict.ContainsKey(kvp.Key))
{
personnelItemsDict[kvp.Key].Num += kvp.Value; // 更新人数
personnelItemsDict[kvp.Key].SetInfo(personnelItemsDict[kvp.Key].Num.ToString()); // 更新 UI 显示
personnelItemsDict[kvp.Key].personnelImage.gameObject.SetActive(true); // 确保图标显示
personnelItemsDict[kvp.Key].personnelNum.gameObject.SetActive(true); // 确保图标显示
Debug.Log($"Assigned {kvp.Value} NPCs to Scene ID: {kvp.Key}");
}
}
}
//设置文字颜色
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; // 选中颜色
}
}
//判断分管区域是否打开
public void IsOpen(int id)
{
if (selectScene.difficultyId > 3)
{
classCount.gameObject.SetActive(true);
}
else
{
classCount.gameObject.SetActive(false);
}
}
} }

View File

@ -126,15 +126,7 @@ public class ManagerPanel : MonoBehaviour
foreach(var item in panelInfo.peopleList) foreach(var item in panelInfo.peopleList)
scenetext.personelPanelText.text = sceneEntry.Key; scenetext.personelPanelText.text = sceneEntry.Key;
scenetext.personelNumText.text = sceneEntry.Value.Count.ToString(); scenetext.personelNumText.text = sceneEntry.Value.Count.ToString();
//foreach (var item in panelInfo.peopleList) scenetext.CreatePeopleItem(sceneEntry.Value);
//{
// SceneItem sceneItem = item.GetComponent<SceneItem>();
// if(sceneItem.sceneName.text== scenetext.personelPanelText.text)
// {
// if(sceneEntry.Value.duty==)
// }
//}
scenetext.CreatePeopleItem(sceneEntry.Value);
} }
//CreatePeopleItem(); //CreatePeopleItem();
} }

View File

@ -257,12 +257,16 @@ public class SelectScenePanel : MonoBehaviour
//点击继续按钮后更换场景图片及名称 //点击继续按钮后更换场景图片及名称
public void InstantiateEventPrefab(int id) public void InstantiateEventPrefab(int id)
{ {
// 清空事件列表
incidentInfos.Clear(); incidentInfos.Clear();
foreach (Transform child in incidentList) foreach (Transform child in incidentList)
{ {
Destroy(child.gameObject); Destroy(child.gameObject);
} }
// 更新场景名称
text20008.text = sceneName; text20008.text = sceneName;
// 通过 id 获取对应的 sceneData // 通过 id 获取对应的 sceneData
if (jsonReader.sceneDictionary.TryGetValue(id, out var sceneData)) if (jsonReader.sceneDictionary.TryGetValue(id, out var sceneData))
{ {
@ -272,54 +276,63 @@ public class SelectScenePanel : MonoBehaviour
// 遍历每个分隔出来的 id // 遍历每个分隔出来的 id
foreach (string incidentIdStr in incidentIds) foreach (string incidentIdStr in incidentIds)
{ {
//Debug.Log("incidentIdStr" + incidentIdStr);
// 转换字符串为 int 类型 // 转换字符串为 int 类型
if (int.TryParse(incidentIdStr, out int incidentId)) if (int.TryParse(incidentIdStr, out int incidentId))
{ {
// 根据 incidentId 获取对应的事件数据 // 根据 incidentId 获取对应的事件数据
EventData eventData=jsonReader.GetEvenById(incidentId); EventData eventData = jsonReader.GetEvenById(incidentId);
string[] incidentIds2 = eventData.DisasterLocation.Split('|'); string[] incidentIds2 = eventData.DisasterLocation.Split('|');
// 动态加载 slot
GameObject slot = GameObject.Instantiate<GameObject>(eventPrefab, eventList); GameObject slot = GameObject.Instantiate<GameObject>(eventPrefab, eventList);
EventInfo item = slot.GetComponent<EventInfo>(); EventInfo item = slot.GetComponent<EventInfo>();
item.eventId = eventData.ID; item.eventId = eventData.ID;
item.eventName.text = eventData.Note; item.eventName.text = eventData.Note;
if (item.IsOpen)
{ // 显示或隐藏遮罩
item.maskImage.gameObject.SetActive(false); item.maskImage.gameObject.SetActive(!item.IsOpen);
}
else // 获取 Toggle 组件并配置
{
item.maskImage.gameObject.SetActive(true);
}
Toggle toggle = slot.GetComponent<Toggle>(); Toggle toggle = slot.GetComponent<Toggle>();
if (toggle != null) if (toggle != null)
{ {
toggle.group = eventGroup; toggle.group = eventGroup;
eventInfoList.Add(item); eventInfoList.Add(item);
evnetsceneList.Add(toggle); evnetsceneList.Add(toggle);
}
//添加点击事件 // 添加点击事件
toggle.onValueChanged.AddListener((isSelected) => toggle.onValueChanged.AddListener((isSelected) =>
{
if (isSelected) // 只有当Toggle被选中时才调用SelectEventBtn
{ {
// 清空事件列表 if (isSelected) // 只有当Toggle被选中时才调用逻辑
incidentInfos.Clear();
foreach (Transform child in incidentList)
{ {
Destroy(child.gameObject); // 清空事件列表
incidentInfos.Clear();
foreach (Transform child in incidentList)
{
Destroy(child.gameObject);
}
// 加载事件数据
this.eventName = item.eventName.text; // 获取 Text 组件的文本
this.eventId = item.eventId;
EventData selectedEventData = jsonReader.GetEvenById(this.eventId);
foreach (string disasterLocation in incidentIds2)
{
InstantiateIncidentPrefab(int.Parse(disasterLocation));
OnRandomEventClick();
}
// 设置模板信息
createTemplateInfo.Instance.auth_CreateTemplate.sceneId = item.eventId.ToString();
} }
this.eventName = item.eventName.text; // 获取 Text 组件的文本 });
this.eventId = item.eventId; if (toggle.isOn)
EventData eventData = jsonReader.GetEvenById(this.eventId); {
foreach (string disasterLocation in incidentIds2) // 模拟触发点击事件
{ toggle.onValueChanged.Invoke(true);
InstantiateIncidentPrefab(int.Parse(disasterLocation));
OnRandomEventClick();
}
createTemplateInfo.Instance.auth_CreateTemplate.sceneId = item.eventId.ToString();
} }
}); }
} }
else else
{ {
@ -333,6 +346,7 @@ public class SelectScenePanel : MonoBehaviour
} }
} }
//事件及难度选择 //事件及难度选择
public void SelectEvent() public void SelectEvent()
{ {
@ -353,7 +367,6 @@ public class SelectScenePanel : MonoBehaviour
// 随机选择一个事件 // 随机选择一个事件
if (eventInfoList.Count > 1) if (eventInfoList.Count > 1)
{ {
int randomIndex = Random.Range(0, eventInfoList.Count); int randomIndex = Random.Range(0, eventInfoList.Count);
// 取消所有Toggle的选中状态 // 取消所有Toggle的选中状态
foreach (Toggle toggle in eventToggleList) foreach (Toggle toggle in eventToggleList)
@ -370,6 +383,7 @@ public class SelectScenePanel : MonoBehaviour
{ {
eventToggleList[randomIndex].isOn = true; eventToggleList[randomIndex].isOn = true;
this.eventName = eventInfoList[randomIndex].eventName.text; // 设置随机选择的事件名称 this.eventName = eventInfoList[randomIndex].eventName.text; // 设置随机选择的事件名称
this.eventId = eventInfoList[randomIndex].eventId; // 更新事件 ID
Debug.Log("已选择随机事件: " + this.eventName); Debug.Log("已选择随机事件: " + this.eventName);
} }
else else
@ -493,7 +507,6 @@ public class SelectScenePanel : MonoBehaviour
else else
{ {
continueBtn.interactable = isOk; continueBtn.interactable = isOk;
Debug.LogError("ContinueBtn 按钮组件未找到!");
} }
} }

View File

@ -8,8 +8,8 @@ public class PersonnelItem : MonoBehaviour
public Text sceneText; public Text sceneText;
public Image personnelImage; public Image personnelImage;
public Text personnelNum; public Text personnelNum;
public int sceneId;
public int Num = 0;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {

View File

@ -64,6 +64,11 @@ public class loginData
public int expire_in;//toling剩余时间 public int expire_in;//toling剩余时间
public string isCreater;//是否是模板创建者Y是则跳蓝湖预定演练01页面开始创建模板N否则跳蓝狐回放1页面 public string isCreater;//是否是模板创建者Y是则跳蓝湖预定演练01页面开始创建模板N否则跳蓝狐回放1页面
} }
public static class GlobalData
{
// 静态变量用于存储登录响应数据
public static loginResponse ServerData;
}
//==================================================== //====================================================
//public class TemplateListData: Response //public class TemplateListData: Response
//{ //{

View File

@ -354,7 +354,7 @@ GameObject:
- component: {fileID: 8299270741119412921} - component: {fileID: 8299270741119412921}
- component: {fileID: 8299270741119412922} - component: {fileID: 8299270741119412922}
m_Layer: 5 m_Layer: 5
m_Name: chooseBtn (1) m_Name: chooseBtn2
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0

View File

@ -13,41 +13,37 @@ public class ClassItem : MonoBehaviour
public GameObject JuesechoicePop; public GameObject JuesechoicePop;
public bool isSet = false; public bool isSet = false;
// Start is called before the first frame update // Start is called before the first frame update
void Start() //void Start()
{ //{
// NoSelectedBtn.onClick.AddListener(OpenJueseChoicePop);
NoSelectedBtn.onClick.AddListener(OpenJueseChoicePop); // setClassItem("");
//SelectedBtn.onClick.AddListener(OpenJueseChoicePop); //}
setClassItem(""); //public void setClassItem(string s)
} //{
public void setClassItem(string s) // if(!isSet)
{ // {
if(!isSet) // NoSelectedBtn.gameObject.SetActive(true);
{ // SelectedBtn.gameObject.SetActive(false);
NoSelectedBtn.gameObject.SetActive(true); // }
SelectedBtn.gameObject.SetActive(false); // else
} // {
else // //NoSelectedBtn.gameObject.SetActive(true);
{ // //SelectedBtn.gameObject.SetActive(false);
//NoSelectedBtn.gameObject.SetActive(true);
//SelectedBtn.gameObject.SetActive(false);
SelectedBtn.gameObject.SetActive(true); // SelectedBtn.gameObject.SetActive(true);
SelectedBtntext.text = s; // SelectedBtntext.text = s;
NoSelectedBtn.gameObject.SetActive(false); // NoSelectedBtn.gameObject.SetActive(false);
} // }
} //}
void OpenJueseChoicePop() //void OpenJueseChoicePop()
{ //{
JuesechoicePop.SetActive(true); // JuesechoicePop.SetActive(true);
JueseChoicePop jueseChoicePop = JuesechoicePop.GetComponent<JueseChoicePop>(); // JueseChoicePop jueseChoicePop = JuesechoicePop.GetComponent<JueseChoicePop>();
jueseChoicePop.SetClassItem(this); // jueseChoicePop.SetClassItem(this);
//}
//// Update is called once per frame
} //void Update()
// Update is called once per frame //{
void Update()
{
} //}
} }

View File

@ -17,39 +17,39 @@ public class ClassMate : MonoBehaviour
public bool isBeSet = false; public bool isBeSet = false;
// Start is called before the first frame update // Start is called before the first frame update
void Start() //void Start()
{ //{
button.onClick.AddListener(Click); // button.onClick.AddListener(Click);
s = classmatename.text; // s = classmatename.text;
} //}
public void Click() //public void Click()
{ //{
if(isBeSet == false) // if(isBeSet == false)
{ // {
jueseChoicePop.SetClassMate(this); // jueseChoicePop.SetClassMate(this);
} // }
else // else
{ // {
jueseChoicePop.ChangeClassMate(); // //jueseChoicePop.ChangeClassMate();
} // }
} //}
public void SetJc(JueseChoicePop jc) //public void SetJc(JueseChoicePop jc)
{ //{
jueseChoicePop = jc; // jueseChoicePop = jc;
} //}
public void setName() //public void setName()
{ //{
classmatename.text = s; // classmatename.text = s;
} //}
// Update is called once per frame //// Update is called once per frame
void Update() //void Update()
{ //{
} //}
} }

View File

@ -1,7 +1,9 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Unity.VisualScripting; using Unity.VisualScripting;
using UnityEditor.Experimental.GraphView;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking.Types;
using UnityEngine.UI; using UnityEngine.UI;
public class JueseChoicePop : MonoBehaviour public class JueseChoicePop : MonoBehaviour
@ -16,15 +18,17 @@ public class JueseChoicePop : MonoBehaviour
public List<ClassMate> classMateList = new List<ClassMate> (); public List<ClassMate> classMateList = new List<ClassMate> ();
//public string s; public string s;
// Start is called before the first frame update public JSONReader jsonReader;
public Panel panel;
//Start is called before the first frame update
void Start() void Start()
{ {
this.gameObject.SetActive(false); this.gameObject.SetActive(false);
CloseBtn.onClick.AddListener(CLosePop); CloseBtn.onClick.AddListener(CLosePop);
Surebtn.onClick.AddListener(CLosePop); Surebtn.onClick.AddListener(CLosePop);
Surebtn.onClick.AddListener(SetFenguan); //Surebtn.onClick.AddListener(SetFenguan);
SetClass(); //SetClass();
} }
void CLosePop() void CLosePop()
{ {
@ -43,48 +47,70 @@ public class JueseChoicePop : MonoBehaviour
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
} }
public void SetClass() public void SetClass(int id)
{ {
for (int i = 0; i < 10; i++) // 清除当前内容
foreach (Transform child in content)
{ {
GameObject item = GameObject.Instantiate<GameObject>(classmatePrefab, content); Destroy(child.gameObject);
}
ClassMate classMate = item.GetComponent<ClassMate>();
classMateList.Add(classMate); // 获取指定 ID 的 LocationData
classMate.SetJc(this); LocationData locationData = jsonReader.GetAreaDateById(id);
// 判断 Oversee 字段
if (locationData.Oversee == "-1")
{
Debug.Log($"Skipping ID {id}: Oversee is -1.");
return; // 跳过
}
// 分割 Oversee 字段
string[] overseeParts = locationData.Oversee.Split(',');
string firstElement = overseeParts[0];
string lastElement = overseeParts[1];
if (overseeParts.Length > 0)
{
// 判断第一个元素是否为 "1"
if (lastElement == "1")
{
foreach (var pair in panel.sceneDataDictionary)
{
foreach (var selectedInfo in pair.Value)
{
Debug.Log("+++++++++++++++++++++++"+ int.Parse(firstElement));
Debug.Log("-------------------------"+ selectedInfo.dutyId);
if (selectedInfo.dutyId == int.Parse(firstElement))
{
GameObject item = GameObject.Instantiate(classmatePrefab, content);
ClassMate classMate = item.GetComponent<ClassMate>();
classMate.classmatename.text = selectedInfo.name;
}
}
}
Debug.Log($"Instantiated ClassMate for ID {id} with name {locationData.Name}");
}
} }
} }
public void SetClassItem(ClassItem classItem) public void SetClassItem(ClassItem classItem)
{ {
this.classItem = classItem; this.classItem = classItem;
} }
public void SetClassMate(ClassMate classMate,string a = "") public void SetClassMate(ClassMate classMate, string a = "")
{ {
classMate.isBeSet = true; classMate.isBeSet = true;
classItem.isSet = true; classItem.isSet = true;
this.classMate = classMate; this.classMate = classMate;
classItem.setClassItem(classMate.classmatename.text); //classItem.setClassItem(classMate.classmatename.text);
//s = classMate.classmatename.text; //s = classMate.classmatename.text;
this.classMate.classmatename.text = classMate.classmatename.text + "(" + classItem.classname.text + ")"; this.classMate.classmatename.text = classMate.classmatename.text + "(" + classItem.classname.text + ")";
} }
public void ClearClassMate()
{
}
public void ChangeClassMate()
{
}
} }