228 lines
6.7 KiB
C#
228 lines
6.7 KiB
C#
using AdamThinkDevicesData;
|
|
using PData;
|
|
using RDate;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.PostProcessing;
|
|
using UnityEngine.SceneManagement;
|
|
using static InterfaceManager;
|
|
|
|
public class UIBootstrap : MonoSingleton<UIBootstrap>
|
|
{
|
|
//private string url = Url_GetAllThinkData;
|
|
private string sceneInfoUrl;
|
|
public Editinformation editinformation = new Editinformation();
|
|
public SceneRoot currentSceneInfo = new SceneRoot();
|
|
public List<SceneRoot> sceneRoots = new List<SceneRoot>();
|
|
public List<RSData.SubjectDataItem> subjectInfo = new List<RSData.SubjectDataItem>();
|
|
public List<Traininginformation> traininginformations = new List<Traininginformation>();
|
|
public AdamThinkDevicesData.DeviceData thinkDevicesData = new AdamThinkDevicesData.DeviceData();
|
|
public RoomData roomdata = new RoomData();
|
|
public GameObject loadingPanel;
|
|
public GameObject go;
|
|
public GameObject loadTem;
|
|
//public RSData.RoomSubjectData currentRoomData = new RSData.RoomSubjectData();
|
|
|
|
// Start is called before the first frame update
|
|
private async void Start()
|
|
{
|
|
|
|
sceneInfoUrl = Url_GetSceneInfo;
|
|
//Debug.LogError(Url_GetAllThinkData);
|
|
editinformation = await AsyncWebReq.Post<Editinformation>(Url_GetAllThinkData, null);
|
|
|
|
for (int i = 0; i < editinformation.data.Count; i++)
|
|
{
|
|
Traininginformation t = new Traininginformation();
|
|
t = Jsonanalyze.FromJson<Traininginformation>(editinformation.data[i].VirtualPath);
|
|
traininginformations.Add(t);
|
|
}
|
|
AdamSync.SyncCreateRoom.leaveRoomRequset += OnLeaveRoomInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async void GetSceneData(string roomId)
|
|
{
|
|
string _url = sceneInfoUrl + roomId;
|
|
//Debug.LogError(_url);
|
|
currentSceneInfo = await AsyncWebReq.Get<SceneRoot>(_url);
|
|
GlobalFlag.field_Char1 = currentSceneInfo.data.Field_Char1;
|
|
|
|
}
|
|
|
|
public void GetSubjectInfo(List<RSData.SubjectDataItem> sdi)
|
|
{
|
|
subjectInfo = sdi;
|
|
}
|
|
|
|
public async void GetAllDeviceData()
|
|
{
|
|
thinkDevicesData = await AsyncWebReq.Post<AdamThinkDevicesData.DeviceData>(Url_GetAllPracticeThinkDevice + GlobalFlag.currentThinkId, null);
|
|
}
|
|
public AdamThinkDevicesData.DataItem GetDeviceByName(string deviceName)
|
|
{
|
|
AdamThinkDevicesData.DataItem detaIteml = null;
|
|
for (int i = 0; i < thinkDevicesData.data.Count; i++)
|
|
{
|
|
if (thinkDevicesData.data[i].device_name == deviceName)
|
|
return thinkDevicesData.data[i];
|
|
}
|
|
return detaIteml;
|
|
}
|
|
|
|
public void SetRoomdata(RoomData _roomdata)
|
|
{
|
|
roomdata = _roomdata;
|
|
}
|
|
|
|
public int GetRoomStateById(string Id)
|
|
{
|
|
for (int i = 0; i < roomdata.data.Count; i++)
|
|
{
|
|
if (roomdata.data[i].Id == Id)
|
|
{
|
|
return roomdata.data[i].State;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
public async void GetAllSceneRoots(RoomData roomId)
|
|
{
|
|
for (int i = 0; i < roomId.data.Count; i++)
|
|
{
|
|
SceneRoot s = new SceneRoot();
|
|
string _url = sceneInfoUrl + roomId.data[i].Id;
|
|
s = await AsyncWebReq.Get<SceneRoot>(_url);
|
|
if (!sceneRoots.Contains(s))
|
|
sceneRoots.Add(s);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 通过 房间 ID 获取 该房间的想定信息,然后解析出所属地形
|
|
/// </summary>
|
|
public string GetRoomModelByThinkingDataAndRoomID(string roomID)
|
|
{
|
|
for (int i = 0; i < sceneRoots.Count; i++)
|
|
{
|
|
if (sceneRoots[i].data.Id == roomID)
|
|
{
|
|
return sceneRoots[i].data.Field_Char1;
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public List<List_paraItem> GetListParaItemById(string deviceId)
|
|
{
|
|
for (int i = 0; i < thinkDevicesData.data.Count; i++)
|
|
{
|
|
if (thinkDevicesData.data[i].id == deviceId)
|
|
return thinkDevicesData.data[i].list_para;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public string GetRoleByIDPracticeId(string practiceID)
|
|
{
|
|
for (int i = 0; i < subjectInfo.Count; i++)
|
|
{
|
|
int index = i;
|
|
if (subjectInfo[index].Id == practiceID && subjectInfo[index].UserName == GlobalFlag.currentUser.real_name)
|
|
{
|
|
return subjectInfo[index].Role;
|
|
}
|
|
}
|
|
return "-1";
|
|
}
|
|
/// <summary>
|
|
/// 是否分配角色
|
|
/// </summary>
|
|
public bool IsAllocate()
|
|
{
|
|
for (int i = 0; i < subjectInfo.Count; i++)
|
|
{
|
|
if (subjectInfo[i].UserAccount == GlobalFlag.currentUser.login_name)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
public void OnLeaveRoomInfo(string msg)
|
|
{
|
|
_ = AdamSync.SyncCreateRoom.SendMessageAsync($"send2world {GlobalFlag.currentUser.user_id}");
|
|
SceneLoad.Instance.SceneChange("SampleScene");
|
|
//SceneManager.LoadScene("SampleScene");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 控制load界面显示隐藏
|
|
/// </summary>
|
|
public void CheckShowLoad(UnityAction callback = null)
|
|
{
|
|
if (go == null)
|
|
go = GameObject.Find("UIRoot");
|
|
if (loadTem == null)
|
|
loadTem = Instantiate(loadingPanel, go.transform);
|
|
StopCoroutine(ShowLoad(callback));
|
|
StartCoroutine(ShowLoad(callback));
|
|
}
|
|
|
|
private IEnumerator ShowLoad(UnityAction callback = null)
|
|
{
|
|
loadTem.SetActive(true);
|
|
yield return new WaitForSeconds(1f);
|
|
loadTem.SetActive(false);
|
|
callback?.Invoke();
|
|
}
|
|
|
|
|
|
private void OnDisable()
|
|
{
|
|
Debug.Log("OnDisable UIBootstrap");
|
|
AdamSync.SyncCreateRoom.leaveRoomRequset -= OnLeaveRoomInfo;
|
|
string _msg = "leaveroom ";
|
|
_ = AdamSync.SyncCreateRoom.SendMessageAsync(_msg);
|
|
}
|
|
private void OnDestory()
|
|
{
|
|
Debug.Log("OnDestory");
|
|
AdamSync.SyncCreateRoom.leaveRoomRequset -= OnLeaveRoomInfo;
|
|
}
|
|
|
|
|
|
public void WaitForT(UnityAction callback)
|
|
{
|
|
StopCoroutine(WaitExecution(callback));
|
|
StartCoroutine(WaitExecution(callback));
|
|
}
|
|
|
|
private IEnumerator WaitExecution(UnityAction callback)
|
|
{
|
|
yield return new WaitForSeconds(0.1f);
|
|
callback?.Invoke();
|
|
}
|
|
|
|
public void OnLogout()
|
|
{
|
|
Dictionary<string, string> replaceInfoDic = new Dictionary<string, string>();
|
|
replaceInfoDic.Add("login_name", GlobalFlag.currentUser.login_name);
|
|
StartCoroutine(AsyncWebReq.PostData2(Url_LoginCheck, replaceInfoDic));
|
|
Debug.Log("OnLogout");
|
|
}
|
|
|
|
private void OnApplicationQuit()
|
|
{
|
|
OnLogout();
|
|
}
|
|
}
|