_xiaofang/xiaofang/Assets/Script/UI/PanelUI/SelectScenePanel.cs

413 lines
12 KiB
C#
Raw Normal View History

2024-11-25 17:15:16 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
2024-11-25 17:15:16 +08:00
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class SelectScenePanel : MonoBehaviour
{
[Header("<22><><EFBFBD><EFBFBD>")]
public GameObject scenePrefab;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼԤ<CDBC><D4A4><EFBFBD><EFBFBD>
public Transform sceneList;//Ԥ<><D4A4><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
public GameObject schoolPrefab;//ѧУ<D1A7><D0A3>ťԤ<C5A5><D4A4><EFBFBD><EFBFBD>
public Transform schoolList;//ѧУԤ<D0A3><D4A4><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
public GameObject eventPrefab;//<2F>¼<EFBFBD><C2BC><EFBFBD>ťԤ<C5A5><D4A4><EFBFBD><EFBFBD>
public Transform eventList;//ѧУԤ<D0A3><D4A4><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
public ToggleGroup schoolGroup;//ѧУToggleGroup
public ToggleGroup sceneGroup;//<2F><><EFBFBD><EFBFBD>ToggleGroup
public ToggleGroup eventGroup;//<2F>¼<EFBFBD>ToggleGroup
2024-11-25 17:15:16 +08:00
public GameObject scoolSelectBtn;//ѧУѡ<D0A3><D1A1><EFBFBD><EFBFBD>ť
public GameObject schoolChoiceLable;//ѧУѡ<D0A3><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public GameObject eventChoiceLable;//<2F>¼<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-30 16:19:19 +08:00
public GameObject mainPanel;
public List<SchoolInfo> schoolInfoList = new List<SchoolInfo>();//ѧУ<D1A7><D0A3>Ϣ
public List<EventInfo> eventInfoList = new List<EventInfo>();//<2F>¼<EFBFBD><C2BC><EFBFBD>Ϣ
public List<SceneItem> sceneItemList = new List<SceneItem>();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
public List<Toggle> difficultyList = new List<Toggle>();//<2F><>Ϸ<EFBFBD>Ѷ<EFBFBD>
2024-11-27 02:11:27 +08:00
public Button continueBtn;
public Toggle[] toggleList;
public Toggle[] schooltoggleList;
public Toggle[] eventToggleList;
2024-11-29 14:44:18 +08:00
public ToggleGroup toggleGroup;
[Header("<22><><EFBFBD><EFBFBD>")]
2024-11-30 16:19:19 +08:00
public DatePanel datePanel;
2024-11-25 17:15:16 +08:00
public int schoolId;
public string schoolName;
public string sceneName;
2024-11-25 17:15:16 +08:00
public int eventId;
public string eventName;
public string difficulty;
public string isBuy;
2024-11-30 23:32:17 +08:00
public JSONReader jsonReader;
2024-11-25 17:15:16 +08:00
// Start is called before the first frame update
void Start()
{
schoolChoiceLable.gameObject.SetActive(true);
eventChoiceLable.gameObject.SetActive(false);
InstantiateScenePrefab();
InstantiateSchoolPrefab();
InstantiateEventPrefab();
2024-11-29 14:44:18 +08:00
SetEventToggleOpenorClose(eventInfoList);
continueBtn.onClick.AddListener(OnClickContinueBtn);
2024-11-29 14:44:18 +08:00
SetFirstChoise(toggleList);
SetToggleOpenorClose(sceneItemList);//δ<><CEB4><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD>ѡ<EFBFBD><D1A1>
SetScloolToggleOpenorClose(schoolInfoList);
}
// Update is called once per frame
void Update()
{
IsClick();
}
//<2F><>̬<EFBFBD><CCAC><EFBFBD>س<EFBFBD><D8B3><EFBFBD>ѡ<EFBFBD><D1A1>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
public void InstantiateScenePrefab()
{
for (int i = 0; i < 6; i++)
{
GameObject slot = GameObject.Instantiate<GameObject>(scenePrefab, sceneList);
SceneItem item = slot.GetComponent<SceneItem>();
2024-11-29 14:44:18 +08:00
item.sceneName.text = "<22><><EFBFBD><EFBFBD>" + 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);
}
}
}
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>ѧУѡ<D0A3><D1A1>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
public void InstantiateSchoolPrefab()
{
for (int i = 0; i < 6; i++)
2024-11-25 17:15:16 +08:00
{
GameObject slot = GameObject.Instantiate<GameObject>(schoolPrefab, schoolList);
SchoolInfo item = slot.GetComponent<SchoolInfo>();
item.schoolName.text = "<22><>ɽ<EFBFBD><C9BD>ѧ";
item.schoolId = i;
2024-11-27 02:11:27 +08:00
Toggle toggle = slot.GetComponent<Toggle>();
if (toggle != null)
{
// <20><> Toggle <20><><EFBFBD>ӵ<EFBFBD> ToggleGroup <20><>
toggle.group = schoolGroup;
2024-11-27 02:11:27 +08:00
// <20><> Toggle <20><><EFBFBD>ӵ<EFBFBD> schooltoggleList <20><>
schooltoggleList[i] = toggle;
// <20><> SchoolInfo <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD> schoolInfos <20>б<EFBFBD><D0B1><EFBFBD>
schoolInfoList.Add(item);
2024-11-27 02:11:27 +08:00
}
2024-11-25 17:15:16 +08:00
}
}
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ѡ<EFBFBD><D1A1>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
public void InstantiateEventPrefab()
2024-11-25 17:15:16 +08:00
{
2024-11-30 23:32:17 +08:00
foreach(var eventData in jsonReader.eventDictionary)
{
2024-11-30 23:32:17 +08:00
int i=2;
GameObject slot = GameObject.Instantiate<GameObject>(eventPrefab, eventList);
EventInfo item = slot.GetComponent<EventInfo>();
2024-11-30 23:32:17 +08:00
item.eventName.text = eventData.Value.Note;
Toggle toggle = slot.GetComponent<Toggle>();
if (toggle != null)
{
// <20><> Toggle <20><><EFBFBD>ӵ<EFBFBD> ToggleGroup <20><>
toggle.group = schoolGroup;
toggle.isOn = false;
// <20><> Toggle <20><><EFBFBD>ӵ<EFBFBD> schooltoggleList <20><>
eventToggleList[i] = toggle;
2024-11-30 23:32:17 +08:00
i++;
// <20><> SchoolInfo <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD> schoolInfos <20>б<EFBFBD><D0B1><EFBFBD>
eventInfoList.Add(item);
}
}
2024-11-25 17:15:16 +08:00
}
//ѧУѡ<D0A3><D1A1>
2024-11-25 17:15:16 +08:00
public void SelectSchoolBtn()
{
SchoolInfo gameObject = GetComponentInChildren<SchoolInfo>();
foreach (SchoolInfo item in schoolInfoList)
2024-11-25 17:15:16 +08:00
{
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
2024-11-25 17:15:16 +08:00
{
this.schoolId = item.schoolId;
2024-11-30 23:32:17 +08:00
this.schoolName = item.schoolName.text;
}
}
Debug.Log("###############1:" + this.schoolId);
Debug.Log("###############2:" + this.schoolName);
}
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
public void SelectSceneBtn()
{
bool sceneSelected = false; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
foreach (SceneItem item in sceneItemList)
{
// <20><><EFBFBD>鵱ǰ<E9B5B1><C7B0> Toggle <20>Ƿ<EFBFBD><C7B7><EFBFBD>ѡ<EFBFBD><D1A1>
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
{
// <20><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this.sceneName = item.sceneName.text; // <20><>ȡ Text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
sceneSelected = true;
break; // <20>ҵ<EFBFBD>ѡ<EFBFBD>еij<D0B5><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>ѭ<EFBFBD><D1AD>
}
}
2024-11-30 16:19:19 +08:00
Debug.Log("###############3:" + this.schoolId);
//IsClick();
}
//<2F>¼<EFBFBD>ѡ<EFBFBD><D1A1>
public void SelectEvnentBtn()
{
bool eventSelected = false; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
foreach (EventInfo item in eventInfoList)
{
2024-11-30 23:32:17 +08:00
// <20><><EFBFBD>鵱ǰ<E9B5B1><C7B0> Toggle <20>Ƿ<EFBFBD><C7B7><EFBFBD>ѡ<EFBFBD><D1A1>
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
{
// <20><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
this.eventName = item.eventName.text; // <20><>ȡ Text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
2024-11-30 23:32:17 +08:00
Debug.Log(this.eventName);
eventSelected = true;
break; // <20>ҵ<EFBFBD>ѡ<EFBFBD>еij<D0B5><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>ѭ<EFBFBD><D1AD>
2024-11-25 17:15:16 +08:00
}
}
}
2024-11-25 17:15:16 +08:00
//<2F>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>Ѷ<EFBFBD>ѡ<EFBFBD><D1A1>
public void SelectEvent()
{
EventInfo eventInfo = GetComponentInChildren<EventInfo>();
foreach (EventInfo item in eventInfoList)
2024-11-25 17:15:16 +08:00
{
if (item.gameObject.transform.GetComponent<Toggle>().isOn)
{
this.eventId = item.eventId;
this.eventName = item.eventName.text;
2024-11-25 17:15:16 +08:00
}
}
2024-11-30 23:32:17 +08:00
Debug.Log("%%%%%%%%%%%%%1:"+ this.eventId);
Debug.Log("%%%%%%%%%%%%%2:" + this.eventName);
2024-11-25 17:15:16 +08:00
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
public void OnRandomEventClick()
{
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD>¼<EFBFBD>
if (eventInfoList.Count > 0)
{
int randomIndex = Random.Range(0, eventInfoList.Count);
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Toggle<6C><65>ѡ<EFBFBD><D1A1>״̬
foreach (Toggle toggle in eventToggleList)
{
// <20>ȼ<EFBFBD><C8BC><EFBFBD>toggle<6C>Ƿ<EFBFBD>Ϊnull
if (toggle != null)
{
toggle.isOn = false;
}
}
// ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
2024-11-29 14:44:18 +08:00
if (eventToggleList[randomIndex] != null&& eventToggleList[randomIndex].GetComponent<EventInfo>().isOpen!=false)
{
eventToggleList[randomIndex].isOn = true;
this.eventName = eventInfoList[randomIndex].eventName.text; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
Debug.Log("<22><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>: " + this.eventName);
}
else
{
Debug.LogWarning("<22><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD> Toggle Ϊ null<6C><6C>");
}
}
else
{
Debug.LogWarning("<22>¼<EFBFBD><C2BC>б<EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>");
}
}
2024-11-25 17:15:16 +08:00
//<2F><>Ϸ<EFBFBD>Ѷ<EFBFBD>ѡ<EFBFBD><D1A1>
public void SelsctDifficulty()
{
auth_createTemplate auth_CreateTemplate = new auth_createTemplate();
foreach (Toggle item in difficultyList)
2024-11-25 17:15:16 +08:00
{
if (item.isOn)
{
this.difficulty = item.transform.parent.GetComponentInChildren<Text>().text;
auth_CreateTemplate.mode = this.difficulty;//<2F><><EFBFBD><EFBFBD><EFBFBD>Ѷȡ<D1B6><C8A1><EFBFBD>ֵ
2024-11-25 17:15:16 +08:00
}
}
//Debug.Log("%%%%%%%%%%%%%3:" + this.difficulty);
2024-11-25 17:15:16 +08:00
}
2024-11-25 17:15:16 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>
2024-11-27 02:11:27 +08:00
public void OnClickContinueBtn()
2024-11-25 17:15:16 +08:00
{
//IsClick(); // <20><><EFBFBD><EFBFBD> IsClick <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ѡ<EFBFBD><D1A1>ѧУ<D1A7>ͳ<EFBFBD><CDB3><EFBFBD>
2024-11-25 17:15:16 +08:00
SelectSchoolBtn();
SelectSceneBtn();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧУû<D0A3><C3BB>ѡ<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
if (continueBtn.interactable)
{
schoolChoiceLable.gameObject.SetActive(false);
eventChoiceLable.gameObject.SetActive(true);
}
else
{
Debug.Log(<><C3BB>ѡ<EFBFBD>񳡾<EFBFBD><F1B3A1BE><EFBFBD>ѧУ<D1A7><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>");
}
}
2024-11-25 17:15:16 +08:00
//<2F><EFBFBD><E1BDBB>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݺ<EFBFBD><DDBA><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD>
public void SubmitBtn()
{
SelectEvent();
SelsctDifficulty();
SelectEvnentBtn();
2024-11-30 16:19:19 +08:00
SetDataPanelInfo();
2024-11-25 17:15:16 +08:00
this.gameObject.SetActive(false);
}
2024-11-30 16:19:19 +08:00
//<2F>رհ<D8B1>ť
public void OnClickCloseBtn()
{
transform.gameObject.SetActive(false);
}
2024-11-27 02:11:27 +08:00
//ͨ<><CDA8><EFBFBD>ж<EFBFBD>Toggle<6C><65>IsOn<4F>Ƿ񱻴<C7B7><F1B1BBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϼ<D0B6><CFBC><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD>Ƿ<EFBFBD><C7B7>û<EFBFBD>
public void IsClick()
{
bool anyToggleSelected = false;
// // <20><><EFBFBD><EFBFBD><E9B3A1>ѡ<EFBFBD><D1A1>
2024-11-27 02:11:27 +08:00
foreach (Toggle toggle in toggleList)
{
if (toggle.isOn)
{
anyToggleSelected = true;
break; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Toggle <20><>ѡ<EFBFBD>У<EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
2024-11-27 02:11:27 +08:00
}
}
// //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD> Toggle <20><>ѡ<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD> ContinueBtn <20>Ƿ<EFBFBD><C7B7>ɽ<EFBFBD><C9BD><EFBFBD>
2024-11-27 02:11:27 +08:00
if (continueBtn != null)
{
2024-11-29 14:44:18 +08:00
//Debug.Log(anyToggleSelected);
2024-11-27 02:11:27 +08:00
continueBtn.interactable = anyToggleSelected; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>е<EFBFBD> Toggle<6C><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򲻿ɽ<F2B2BBBF><C9BD><EFBFBD>
}
else
{
Debug.LogError("ContinueBtn <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>");
}
}
2024-11-29 14:44:18 +08:00
public void SetFirstChoise(Toggle[] toggles)//Ĭ<><C4AC>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Toggle
{
// <20><>ȡToggleGroup<75>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>Toggle
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Toggle<6C><65><EFBFBD><EFBFBD>ѡ<EFBFBD>е<EFBFBD>һ<EFBFBD><D2BB>
if (toggles.Length > 0)
{
toggles[0].isOn = true;
}
}
//<2F><><EFBFBD><EFBFBD>toggle
public void SetToggleOpenorClose(List<SceneItem> sceneItems)
{
foreach (SceneItem item in sceneItems)
{
if (item.IsOpen==false)
{
item.GetComponent<Toggle>().interactable = false;
if (item.GetComponent<Toggle>().isOn)
{
item.GetComponent<Toggle>().isOn = false;
}
}
else
{
item.GetComponent<Toggle>().interactable = true;
}
}
}
2024-11-30 16:19:19 +08:00
//ѧУToggle
2024-11-29 14:44:18 +08:00
public void SetScloolToggleOpenorClose(List<SchoolInfo> sceneItems)
{
foreach (SchoolInfo item in sceneItems)
{
if (item.isOpen == false)
{
item.GetComponent<Toggle>().interactable = false;
if (item.GetComponent<Toggle>().isOn)
{
item.GetComponent<Toggle>().isOn = false;
}
}
else
{
item.GetComponent<Toggle>().interactable = true;
}
}
}
2024-11-30 16:19:19 +08:00
//<2F>¼<EFBFBD>Toggle
2024-11-29 14:44:18 +08:00
public void SetEventToggleOpenorClose(List<EventInfo> sceneItems)
{
foreach (EventInfo item in sceneItems)
{
if (item.isOpen == false)
{
item.GetComponent<Toggle>().interactable = false;
if (item.GetComponent<Toggle>().isOn)
{
item.GetComponent<Toggle>().isOn = false;
}
}
else
{
item.GetComponent<Toggle>().interactable = true;
}
}
}
2024-11-30 16:19:19 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void SetDataPanelInfo()
{
datePanel.SchoolText.text = schoolName;
datePanel.PlaceText.text = eventName;
}
}