This commit is contained in:
huyulong 2024-12-01 19:28:30 +08:00
commit 20120af3ed
4 changed files with 28 additions and 44 deletions

View File

@ -318,7 +318,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 &4451807876351416332 --- !u!224 &4451807876351416332
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -414,7 +414,5 @@ public class Panel : MonoBehaviour
} }
} }
} }
} }

View File

@ -8,7 +8,7 @@ public class EventInfo : MonoBehaviour
public int eventId; public int eventId;
public Text eventName; public Text eventName;
public Image maskImage; public Image maskImage;
public bool isOpen; public bool isOpen=true;
void Start() void Start()
{ {

View File

@ -28,9 +28,10 @@ public class SelectScenePanel : MonoBehaviour
public List<Toggle> difficultyList = new List<Toggle>();//游戏难度 public List<Toggle> difficultyList = new List<Toggle>();//游戏难度
public Button continueBtn; public Button continueBtn;
public List<Toggle> toggleList=new List<Toggle>(); public List<Toggle> toggleList=new List<Toggle>();
public List<Toggle> eventToggleList = new List<Toggle>();
//public Toggle[] toggleList; //public Toggle[] toggleList;
public Toggle[] schooltoggleList; public Toggle[] schooltoggleList;
public Toggle[] eventToggleList; //public Toggle[] eventToggleList;
public ToggleGroup toggleGroup; public ToggleGroup toggleGroup;
[Header("数据")] [Header("数据")]
@ -111,29 +112,6 @@ public class SelectScenePanel : MonoBehaviour
sceneItemList.Add(item); sceneItemList.Add(item);
} }
} }
//for (int i = 0; i < 6; i++)
//{
// GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList);
// SceneItem item = slot.GetComponent<SceneItem>();
// item.sceneName.text = "场景" + i;
// if (item.IsOpen)
// {
// item.maskImage.gameObject.SetActive(false);
// }
// else
// {
// item.maskImage.gameObject.SetActive(true);
// }
// Toggle toggle = slot.GetComponent<Toggle>();
// if (toggle != null)
// {
// toggle.group = sceneGroup;
// toggleList[i] = toggle;
// sceneItemList.Add(item);
// }
//}
} }
//动态加载学校选择预制体(这里面的东西需要判断场景的Id来加载对应的场景) //动态加载学校选择预制体(这里面的东西需要判断场景的Id来加载对应的场景)
@ -166,7 +144,7 @@ public class SelectScenePanel : MonoBehaviour
{ {
foreach(var eventData in jsonReader.eventDictionary) foreach(var eventData in jsonReader.eventDictionary)
{ {
int i=2;
GameObject slot = GameObject.Instantiate<GameObject>(eventPrefab, eventList); GameObject slot = GameObject.Instantiate<GameObject>(eventPrefab, eventList);
EventInfo item = slot.GetComponent<EventInfo>(); EventInfo item = slot.GetComponent<EventInfo>();
@ -181,11 +159,10 @@ public class SelectScenePanel : MonoBehaviour
toggle.isOn = false; toggle.isOn = false;
// 将 Toggle 添加到 schooltoggleList 中 // 将 Toggle 添加到 schooltoggleList 中
eventToggleList[i] = toggle;
i++;
// 将 SchoolInfo 对象添加到 schoolInfos 列表中 // 将 SchoolInfo 对象添加到 schoolInfos 列表中
eventInfoList.Add(item); eventInfoList.Add(item);
Debug.Log("!!!!!!!!!!!!!!!!!!!!!"+eventInfoList.Count);
} }
} }
} }
@ -193,11 +170,6 @@ public class SelectScenePanel : MonoBehaviour
//点击继续按钮后更换场景图片及名称 //点击继续按钮后更换场景图片及名称
public void InstantiateEventPrefab(int id) public void InstantiateEventPrefab(int id)
{ {
// 清空所有的子物体
foreach (Transform child in sceneList)
{
Destroy(child.gameObject);
}
// 通过 id 获取对应的 sceneData // 通过 id 获取对应的 sceneData
if (jsonReader.sceneDictionary.TryGetValue(id, out var sceneData)) if (jsonReader.sceneDictionary.TryGetValue(id, out var sceneData))
@ -214,9 +186,6 @@ public class SelectScenePanel : MonoBehaviour
// 根据 incidentId 获取对应的事件数据 // 根据 incidentId 获取对应的事件数据
if (jsonReader.eventDictionary.TryGetValue(incidentId, out var eventData)) if (jsonReader.eventDictionary.TryGetValue(incidentId, out var eventData))
{ {
// 在这里你可以根据 eventData 做进一步操作
Debug.Log($"Found event for Incident ID {incidentId}: {eventData.Note}");
// 你可以继续处理相关逻辑,比如创建 UI 或设置属性等 // 你可以继续处理相关逻辑,比如创建 UI 或设置属性等
GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList); GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList);
SceneItem item = slot.GetComponent<SceneItem>(); SceneItem item = slot.GetComponent<SceneItem>();
@ -235,7 +204,7 @@ 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;
//toggleList.Add(toggle); //toggleList.Add(toggle);
sceneItemList.Add(item); sceneItemList.Add(item);
} }
@ -257,7 +226,6 @@ public class SelectScenePanel : MonoBehaviour
} }
} }
//学校选择 //学校选择
public void SelectSchoolBtn() public void SelectSchoolBtn()
{ {
@ -336,6 +304,7 @@ public class SelectScenePanel : MonoBehaviour
//随机事件 //随机事件
public void OnRandomEventClick() public void OnRandomEventClick()
{ {
// 随机选择一个事件 // 随机选择一个事件
if (eventInfoList.Count > 0) if (eventInfoList.Count > 0)
{ {
@ -350,7 +319,7 @@ public class SelectScenePanel : MonoBehaviour
toggle.isOn = false; toggle.isOn = false;
} }
} }
Debug.Log("=++++++++++++++++++++++=" + eventToggleList[randomIndex].GetComponent<EventInfo>());
// 选中随机事件 // 选中随机事件
if (eventToggleList[randomIndex] != null&& eventToggleList[randomIndex].GetComponent<EventInfo>().isOpen!=false) if (eventToggleList[randomIndex] != null&& eventToggleList[randomIndex].GetComponent<EventInfo>().isOpen!=false)
{ {
@ -388,6 +357,10 @@ public class SelectScenePanel : MonoBehaviour
public void OnClickContinueBtn() public void OnClickContinueBtn()
{ {
//IsClick(); // 调用 IsClick 检查是否选中学校和场景 //IsClick(); // 调用 IsClick 检查是否选中学校和场景
foreach (Transform child in sceneList)
{
child.gameObject.SetActive(false);
}
SelectSchoolBtn(); SelectSchoolBtn();
SelectSceneBtn(); SelectSceneBtn();
InstantiateEventPrefab(this.scnenId); InstantiateEventPrefab(this.scnenId);
@ -402,7 +375,6 @@ public class SelectScenePanel : MonoBehaviour
Debug.Log("没有选择场景或学校,继续按钮不可用!"); Debug.Log("没有选择场景或学校,继续按钮不可用!");
} }
} }
//提交按钮,点击上传数据和隐藏界面 //提交按钮,点击上传数据和隐藏界面
public void SubmitBtn() public void SubmitBtn()
{ {
@ -416,7 +388,21 @@ public class SelectScenePanel : MonoBehaviour
//关闭按钮 //关闭按钮
public void OnClickCloseBtn() public void OnClickCloseBtn()
{ {
transform.gameObject.SetActive(false); if (schoolChoiceLable.gameObject.active==false)
{
foreach (Transform child in sceneList)
{
child.gameObject.SetActive(false);
}
eventChoiceLable.gameObject.SetActive(false);
schoolChoiceLable.gameObject.SetActive(true);
InstantiateScenePrefab();
}
else
{
transform.gameObject.SetActive(false);
}
} }
//通过判断Toggle的IsOn是否被打开来判断继续按钮是否置灰 //通过判断Toggle的IsOn是否被打开来判断继续按钮是否置灰