using System; using System.Collections; using System.Collections.Generic; using LitJson; using SC.XR.Unity.Module_InputSystem; using ShadowStudio.Model; using ShadowStudio.UI; using Studio.Scripts; using Studio.WebSocket.Message; using UnityEngine; using UnityEngine.SceneManagement; using XRTool.Util; namespace ShadowStudio.Mgr { public class HomeMgr : UnitySingleton { /// /// 场景中游戏对象界面集合(除房间显示界面以外) /// private List ViewList; public static int CREATESEARCHRROOMDLG = 0; public static int CREATROOMDLG = 1; public static int AboutMeDlg = 2; /// /// 场景中显示房间游戏对象 /// public GameObject roomListDlg { get; set; } /// /// 房间游戏对象身上的 MenuListDlg 脚本 /// public MenuListDlg _menuListDlg { get; set; } /// /// 自己创建的房间数据集合(作为数据备份) /// public List SelfRoomConfigList { get; set; } void Start()//初始化 { ViewList = new List(); SelfRoomConfigList = new List(); roomListDlg = transform.GetChild(0).gameObject; _menuListDlg = roomListDlg.GetComponent(); Invoke("InitViewList", 1f); //请求数据以及处理数据 WSHandler.User.OnGetSelfRoomList -= getRoomList; WSHandler.User.OnGetSelfRoomList += getRoomList;//(收到数据后)处理数据的方法 WSHandler.User.GetSelfRoomList();//向服务器请求数据 HomeProxy.Instance.GetSettingsAction += GetSettings; HomeProxy.Instance.RequestGetSettings(); } /// /// 获取房间数据信息以及处理数据 /// /// private void getRoomList(SelfRoomListResponseMessage roomListData) { for (int i = 0,roomCount = roomListData.data.Count; i < roomCount; i++) { RoomNetData roomNetData = roomListData.data[i]; RoomConfig itemConfig = new RoomConfig(roomNetData, "1"); ConfigModel.Instance.InitElement(itemConfig); SelfRoomConfigList.Add(itemConfig); } while (ConfigModel.Instance.Count < 5)//如果数据不够五个,则补齐为五个数据(造假空数据) { RoomConfig itemConfig = new RoomConfig("", "1", "教育", "", "", "", "", "", "", ""); ConfigModel.Instance.InitElement(itemConfig); SelfRoomConfigList.Add(itemConfig); } StartCoroutine(InitRoomList()); } private void GetSettings(MySetting mySetting) { CommonMethod.mySetting = mySetting; } /// /// 初始化房间游戏对象 /// /// IEnumerator InitRoomList() { /* * 由于WorldDlg在start函数里进行了0.02秒的缩放延迟:(由(0,0,0)放大为正常尺寸) 所以这里为了避免初始化冲突,则也同样进行0.02秒的延迟处理来保证代码的流程 */ yield return new WaitForSeconds(0.02f); _menuListDlg._menuUI.Init();//初始化游戏对象 MenuListDlg.Instance.UpdateData();//刷新数据显示 _menuListDlg.Show();//显示房间游戏对象(动画) } /// /// 初始化场景中游戏对象界面集合(除房间显示界面以外) /// public void InitViewList() { for (int i = 0; i < transform.childCount; i++) { ViewList.Add(transform.GetChild(i).gameObject); } ViewList.RemoveAt(0); } /// /// 显示指定索引的界面 /// /// public void ShowView(int index) { for (int i = 0; i < ViewList.Count; i++) { if (index == i) { ViewList[i].SetActive(true); } else { ViewList[i].SetActive(false); } } } public void LoadSence() { CommonMethod.ShowLoading(); Invoke("LoadShowSence", 0.1f); CommonMethod.LoadSence("Show"); this.gameObject.SetActive(false); } public void LoadShowSence() { CommonMethod.HideLoading(); CommonMethod.AllowLoadSence(); } protected override void OnDestroy() { base.OnDestroy(); WSHandler.User.OnGetSelfRoomList -= getRoomList; if (HomeProxy.Instance) { HomeProxy.Instance.GetSettingsAction -= GetSettings; } } public void LoadLoginSence() { CommonMethod.ShowLoading(); Invoke("AllowLoadSence", 0.1f); CommonMethod.LoadSence("Login"); this.gameObject.SetActive(false); } public void AllowLoadSence() { CommonMethod.HideLoading(); CommonMethod.AllowLoadSence(); } } }