场景选中事件出现

This commit is contained in:
lq 2024-12-06 15:43:36 +08:00
parent 93501dd2b0
commit 3d8b063137
3 changed files with 73 additions and 962 deletions

View File

@ -1,8 +1,8 @@
[ [
{ {
"ID": "2001", "ID": 2001,
"Note": "厨房起火", "Note": "厨房起火",
"Name": "2001", "Name": 2001,
"Scene": "9003", "Scene": "9003",
"Position": "36,1,2", "Position": "36,1,2",
"Volume": "-1", "Volume": "-1",
@ -12,9 +12,9 @@
"GeneralRole": "8000,8001,8002,8003,8004,8005,8006,8008,8009,8010" "GeneralRole": "8000,8001,8002,8003,8004,8005,8006,8008,8009,8010"
}, },
{ {
"ID": "2002", "ID": 2002,
"Note": "学生宿舍起火", "Note": "学生宿舍起火",
"Name": "2002", "Name": 2002,
"Scene": "9002", "Scene": "9002",
"Position": "0,0,0", "Position": "0,0,0",
"Volume": "-1", "Volume": "-1",

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,7 @@ public class SelectScenePanel : MonoBehaviour
public List<SceneItem> sceneItemList = new List<SceneItem>();//场景信息 public List<SceneItem> sceneItemList = new List<SceneItem>();//场景信息
public List<Toggle> difficultyList = new List<Toggle>();//游戏难度 public List<Toggle> difficultyList = new List<Toggle>();//游戏难度
public Button continueBtn; public Button continueBtn;
public Button submitBtn;
public List<Toggle> scenetoggleList = new List<Toggle>(); public List<Toggle> scenetoggleList = new List<Toggle>();
public List<Toggle> schooltoggleList = new List<Toggle>(); public List<Toggle> schooltoggleList = new List<Toggle>();
public List<Toggle> eventToggleList = new List<Toggle>(); public List<Toggle> eventToggleList = new List<Toggle>();
@ -75,6 +76,7 @@ public class SelectScenePanel : MonoBehaviour
void Update() void Update()
{ {
IsClick(); IsClick();
IsSubmit();
} }
//动态加载场景选择预制体 //动态加载场景选择预制体
@ -160,17 +162,17 @@ public class SelectScenePanel : MonoBehaviour
if (toggle != null) if (toggle != null)
{ {
// 将 Toggle 添加到 ToggleGroup 中 // 将 Toggle 添加到 ToggleGroup 中
toggle.group = eventGroup; toggle.group = incidentGroup;
toggle.isOn = false; toggle.isOn = false;
incidentInfos.Add(item); incidentInfos.Add(item);
} }
}
else else
{ {
break; break;
} }
} }
} }
}
//点击继续按钮后更换场景图片及名称 //点击继续按钮后更换场景图片及名称
public void InstantiateEventPrefab(int id) public void InstantiateEventPrefab(int id)
@ -194,7 +196,6 @@ public class SelectScenePanel : MonoBehaviour
Debug.Log("eventData.ID:" + eventData.ID); Debug.Log("eventData.ID:" + eventData.ID);
Debug.Log("eventData.DisasterLocation:" + eventData.DisasterLocation); Debug.Log("eventData.DisasterLocation:" + eventData.DisasterLocation);
string[] incidentIds2 = eventData.DisasterLocation.Split('|'); string[] incidentIds2 = eventData.DisasterLocation.Split('|');
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;
@ -210,8 +211,9 @@ public class SelectScenePanel : MonoBehaviour
Toggle toggle = slot.GetComponent<Toggle>(); Toggle toggle = slot.GetComponent<Toggle>();
if (toggle != null) if (toggle != null)
{ {
toggle.group = sceneGroup; toggle.group = eventGroup;
eventInfoList.Add(item); eventInfoList.Add(item);
evnetsceneList.Add(toggle);
} }
toggle.onValueChanged.AddListener((isSelected) => toggle.onValueChanged.AddListener((isSelected) =>
{ {
@ -230,6 +232,7 @@ public class SelectScenePanel : MonoBehaviour
{ {
Debug.Log("disasterLocation>>>>>>>"+ disasterLocation); Debug.Log("disasterLocation>>>>>>>"+ disasterLocation);
InstantiateIncidentPrefab(int.Parse(disasterLocation)); InstantiateIncidentPrefab(int.Parse(disasterLocation));
OnRandomEventClick();
} }
createTemplateInfo.Instance.auth_CreateTemplate.sceneId = item.eventId.ToString(); createTemplateInfo.Instance.auth_CreateTemplate.sceneId = item.eventId.ToString();
@ -307,11 +310,12 @@ public class SelectScenePanel : MonoBehaviour
//随机事件 //随机事件
public void OnRandomEventClick() public void OnRandomEventClick()
{ {
// 随机选择一个事件 // 随机选择一个事件
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)
{ {
@ -336,8 +340,8 @@ public class SelectScenePanel : MonoBehaviour
} }
else else
{ {
Debug.LogWarning("只有一个事件!!!");
randomEventBtn.gameObject.SetActive(false); randomEventBtn.gameObject.SetActive(false);
Debug.LogWarning("事件列表为空!");
} }
} }
@ -353,7 +357,6 @@ public class SelectScenePanel : MonoBehaviour
auth_CreateTemplate.mode = this.difficulty;//给结构体“难度”赋值 auth_CreateTemplate.mode = this.difficulty;//给结构体“难度”赋值
} }
} }
//Debug.Log("%%%%%%%%%%%%%3:" + this.difficulty);
} }
//继续按钮,点击后上传数据 //继续按钮,点击后上传数据
@ -362,7 +365,7 @@ public class SelectScenePanel : MonoBehaviour
SelectSchoolBtn(); SelectSchoolBtn();
SelectSceneBtn(); SelectSceneBtn();
InstantiateEventPrefab(this.scnenId); InstantiateEventPrefab(this.scnenId);
SetFirstChoise(scenetoggleList); SetFirstChoise(evnetsceneList);
if (continueBtn.interactable) if (continueBtn.interactable)
{ {
sceneLable.gameObject.SetActive(false); sceneLable.gameObject.SetActive(false);
@ -441,6 +444,40 @@ public class SelectScenePanel : MonoBehaviour
} }
} }
//通过判断EventSceneList里面的IsOn是否打开判断提交按钮是否置灰
public void IsSubmit()
{
bool anyToggleSelected = false;
bool anyeventSelected = false;
Debug.Log("evnetsceneList>>>>"+ evnetsceneList.Count());
// 检查场景选择
foreach (Toggle toggle in evnetsceneList)
{
if (toggle.isOn)
{
anyToggleSelected = true;
break; // 如果有一个场景 Toggle 被选中,停止检查
}
}
foreach (Toggle toggle in eventToggleList)
{
if (toggle.isOn)
{
anyeventSelected = true;
break; // 如果有一个场景 Toggle 被选中,停止检查
}
}
// 根据是否有 Toggle 被选中,设置 ContinueBtn 是否可交互
if (submitBtn != null && anyToggleSelected == true&& anyeventSelected==true)
{
submitBtn.interactable = anyToggleSelected; // 如果有选中的 Toggle继续按钮可交互否则不可交互
}
else
{
Debug.LogWarning("提交按钮组件未找到!");
}
}
//默认选择第一个Toggle //默认选择第一个Toggle
public void SetFirstChoise(List<Toggle> toggles) public void SetFirstChoise(List<Toggle> toggles)
{ {