123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- 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<HomeMgr>
- {
- /// <summary>
- /// 场景中游戏对象界面集合(除房间显示界面以外)
- /// </summary>
- private List<GameObject> ViewList;
- public static int CREATESEARCHRROOMDLG = 0;
- public static int CREATROOMDLG = 1;
- public static int AboutMeDlg = 2;
- /// <summary>
- /// 场景中显示房间游戏对象
- /// </summary>
- public GameObject roomListDlg
- {
- get;
- set;
- }
- /// <summary>
- /// 房间游戏对象身上的 MenuListDlg 脚本
- /// </summary>
- public MenuListDlg _menuListDlg
- {
- get;
- set;
- }
- /// <summary>
- /// 自己创建的房间数据集合(作为数据备份)
- /// </summary>
- public List<RoomConfig> SelfRoomConfigList
- {
- get;
- set;
- }
- void Start()//初始化
- {
- ViewList = new List<GameObject>();
- SelfRoomConfigList = new List<RoomConfig>();
- roomListDlg = transform.GetChild(0).gameObject;
- _menuListDlg = roomListDlg.GetComponent<MenuListDlg>();
- Invoke("InitViewList", 1f);
- //请求数据以及处理数据
- WSHandler.User.OnGetSelfRoomList -= getRoomList;
- WSHandler.User.OnGetSelfRoomList += getRoomList;//(收到数据后)处理数据的方法
- WSHandler.User.GetSelfRoomList();//向服务器请求数据
- HomeProxy.Instance.GetSettingsAction += GetSettings;
- HomeProxy.Instance.RequestGetSettings();
- }
- /// <summary>
- /// 获取房间数据信息以及处理数据
- /// </summary>
- /// <param name="data"></param>
- 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;
- }
- /// <summary>
- /// 初始化房间游戏对象
- /// </summary>
- /// <returns></returns>
- 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();//显示房间游戏对象(动画)
- }
- /// <summary>
- /// 初始化场景中游戏对象界面集合(除房间显示界面以外)
- /// </summary>
- public void InitViewList()
- {
- for (int i = 0; i < transform.childCount; i++)
- {
- ViewList.Add(transform.GetChild(i).gameObject);
- }
- ViewList.RemoveAt(0);
- }
- /// <summary>
- /// 显示指定索引的界面
- /// </summary>
- /// <param name="index"></param>
- 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();
- }
- }
- }
|