148 lines
4.5 KiB
C#
148 lines
4.5 KiB
C#
using AdamThinkDevicesData;
|
|
using PData;
|
|
using RDate;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
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<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 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;
|
|
AdamSync.SyncCreateRoom.send2worldRequset += OnGetWorldInfo;
|
|
}
|
|
|
|
|
|
|
|
public async void GetSceneData(string roomId)
|
|
{
|
|
string _url = sceneInfoUrl + roomId;
|
|
//Debug.LogError(_url);
|
|
currentSceneInfo = await AsyncWebReq.Get<SceneRoot>(_url);
|
|
|
|
}
|
|
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 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 OnGetWorldInfo(string msg)
|
|
{
|
|
Debug.Log("OnGetWorldInfo====" + msg);
|
|
GameManager.Instance.RemovePlayer(ulong.Parse(msg));
|
|
}
|
|
|
|
public void OnLeaveRoomInfo(string msg)
|
|
{
|
|
_ = AdamSync.SyncCreateRoom.SendMessageAsync($"send2world {GlobalFlag.currentUser.user_id}");
|
|
SceneManager.LoadScene("SampleScene");
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
}
|