157 lines
4.2 KiB
C#
157 lines
4.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Linq;
|
|
using DataModel.Model;
|
|
using System;
|
|
using LitJson;
|
|
|
|
public class RoomListPanel : MonoBehaviour
|
|
{
|
|
public GridLayoutGroup connect;
|
|
[HideInInspector]
|
|
public GameObject itemPrefb;
|
|
public Button refreshBtn;
|
|
public Button createBtn;
|
|
public Canvas canvas;
|
|
public Text DateTimeText;
|
|
public Button SettingBtn;
|
|
public Button QuitBtn;
|
|
public Text UserNameText;
|
|
public SystrmSettingPanel systrmSettingPanel;
|
|
|
|
[HideInInspector]
|
|
public GameObject CreateRoomPrefb;
|
|
[HideInInspector]
|
|
public GameObject CheckPanelPrefb;
|
|
|
|
public static RoomListPanel instance;
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
if (itemPrefb==null)
|
|
{
|
|
itemPrefb = Resources.Load<GameObject>("UI/Item/roomItem");
|
|
}
|
|
|
|
if(CheckPanelPrefb==null)
|
|
{
|
|
CheckPanelPrefb = Resources.Load<GameObject>("UI/CheckPanel");
|
|
}
|
|
|
|
|
|
|
|
refreshBtn.onClick.AddListener(() =>
|
|
{
|
|
//刷新
|
|
Refresh();
|
|
});
|
|
|
|
createBtn.onClick.AddListener(() =>
|
|
{
|
|
//创建
|
|
if (CreateRoomPrefb == null)
|
|
{
|
|
CreateRoomPrefb = Resources.Load<GameObject>("UI/CreateRoomPanel");
|
|
}
|
|
|
|
GameObject obj = Instantiate<GameObject>(CreateRoomPrefb, canvas.transform);
|
|
});
|
|
|
|
QuitBtn.onClick.AddListener(() =>
|
|
{
|
|
LoadManage.Instance.me = null;
|
|
if (LoadManage.Instance.systemMode == SystemMode.PC)
|
|
{
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene("LoginSencePC");
|
|
}
|
|
else if(LoadManage.Instance.systemMode== SystemMode.MR)
|
|
{
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene("LoginSenceMR");
|
|
}
|
|
});
|
|
|
|
SettingBtn.onClick.AddListener(() =>
|
|
{
|
|
//显示配置界面
|
|
systrmSettingPanel.gameObject.SetActive(true);
|
|
});
|
|
|
|
systrmSettingPanel.Init();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (LoadManage.Instance != null)
|
|
{
|
|
UserNameText.text = LoadManage.Instance.me.user.nickName;
|
|
}
|
|
//刷新
|
|
Refresh();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
//刷新按钮旋转
|
|
if(refreshBtn.interactable==false)
|
|
{
|
|
refreshBtn.transform.Rotate(Vector3.forward, 5, Space.Self);
|
|
}
|
|
|
|
DateTimeText.text = DateTime.Now.ToLongDateString()+" "+ DateTime.Now.ToLongTimeString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新
|
|
/// </summary>
|
|
public void Refresh()
|
|
{
|
|
refreshBtn.interactable = false;
|
|
Invoke("ResetBtn", 3);
|
|
connect.transform.GetComponentsInChildren<RoomItem>(true).ToList().ForEach(a=>
|
|
{
|
|
DestroyImmediate(a.gameObject);
|
|
});
|
|
|
|
StartCoroutine(MyNetMQClient.CallGet("http://"+MyNetMQClient.CallIP+"/Handler/Practice.ashx?action=query&state=0,1", result=>
|
|
{
|
|
var json = JsonMapper.ToObject<CallResultList<practice>>(result);
|
|
var data=JsonMapper.ToObject(result)["data"];
|
|
if(data!=null)
|
|
{
|
|
data.ValueAsArray().ToList().ForEach(a =>
|
|
{
|
|
json.data.Find(b => b.Id == a["Id"].ToString()).CreateTime = DateTime.Parse(a["CreateTime"].ToString());
|
|
});
|
|
}
|
|
|
|
if (json.state)
|
|
{
|
|
var list = json.data.OrderByDescending(a=>a.CreateTime).ToList();
|
|
list.ToList().ForEach(a=>
|
|
{
|
|
//创建
|
|
GameObject item = Instantiate<GameObject>(itemPrefb,connect.transform);
|
|
item.GetComponent<RoomItem>().Init(a);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
string msg = json.message;
|
|
Debug.LogError(msg);
|
|
MessagePanel.ShowMessage(msg, canvas.transform);
|
|
}
|
|
}));
|
|
}
|
|
|
|
public void ResetBtn()
|
|
{
|
|
if (refreshBtn != null)
|
|
{
|
|
refreshBtn.interactable = true;
|
|
}
|
|
}
|
|
}
|