162 lines
6.5 KiB
C#
162 lines
6.5 KiB
C#
using Newtonsoft.Json;
|
|
using NPOI.HPSF;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 重连
|
|
/// </summary>
|
|
public class Reconnection : MonoBehaviour
|
|
{
|
|
public DisconnectedData DisconnectedData;
|
|
string fileName;
|
|
public Transform Player;
|
|
public Vector3 PlayerPos;
|
|
public Vector3 PlayerRot;
|
|
[SerializeField] List<GameObject> tempGame;
|
|
char[] TempChar = new char[7] { '(', 'C', 'l', 'o', 'n', 'e', ')' };
|
|
public bool ison = false;
|
|
DuanDian isonDian;
|
|
[SerializeField] GameObject im;
|
|
public GameObject HandGameObject;
|
|
public bool isDuanDianok = false;
|
|
public Text te;
|
|
// Start is called before the first frame update
|
|
void Awake()
|
|
{
|
|
try
|
|
{
|
|
//Player = GameManager.Instance.Player.transform;
|
|
//DisconnectedData = new DisconnectedData();
|
|
//DisconnectedData.PlayerPosition = new pos();
|
|
//DisconnectedData.PlayerRotions = new pos();
|
|
//DisconnectedData.toolsName = new List<string>();
|
|
//DateTime currentTime = DateTime.Now;
|
|
//Debug.Log("当前系统时间:" + currentTime);
|
|
////fileName = Application.streamingAssetsPath + "/" + currentTime.Year.ToString() + currentTime.Month.ToString() + currentTime.Day.ToString() + ".json";
|
|
//fileName = Application.streamingAssetsPath + "/" +"2023922" + ".json";
|
|
//Debug.Log(fileName);
|
|
//StartCoroutine(LoadJSON(fileName));
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.LogError(ex.Message);
|
|
throw;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 读取是否有数据
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GetSceneLoad(string name, string id)
|
|
{
|
|
ExaminationLoad examinationLoad = new ExaminationLoad();
|
|
isonDian = await examinationLoad.GetLoad(name, id);
|
|
return isonDian.state;
|
|
}
|
|
async Task load1234(string name, string tips, string obj)
|
|
{
|
|
ExaminationLoad examinationLoad = new ExaminationLoad();
|
|
|
|
StartCoroutine(examinationLoad.LoadAsyncPost(name, tips, obj));
|
|
//await examinationLoad.LoadAsyncPost(name,tips,obj);
|
|
//Debug.Log(tempbool.data);
|
|
}
|
|
public void init(string data)
|
|
{
|
|
//ExaminationLoad examinationLoad = new ExaminationLoad();
|
|
//await examinationLoad.GetLoad(UIManager.Instance.loginController.userName, UIManager.Instance.loginController.PassWord);
|
|
LoadJSON(data);
|
|
string name = "";
|
|
|
|
PlayerPos = new Vector3(DisconnectedData.PlayerPosition.x, DisconnectedData.PlayerPosition.y, DisconnectedData.PlayerPosition.z);
|
|
PlayerRot = new Vector3(DisconnectedData.PlayerRotions.x, DisconnectedData.PlayerRotions.y, DisconnectedData.PlayerRotions.z);
|
|
//DisconnectedData.userBianHao =
|
|
if (!string.IsNullOrEmpty(DisconnectedData.HandGameObject))
|
|
{
|
|
name = Filter(DisconnectedData.HandGameObject, TempChar);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(DisconnectedData.HandGameObject))
|
|
{
|
|
for (int i = 0; i < tempGame.Count; i++)
|
|
{
|
|
if (tempGame[i].name.Equals(name))
|
|
{
|
|
HandGameObject = tempGame[i];
|
|
//GameManager.Instance.ToolsShow(tempGame[i]);
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < DisconnectedData.toolsName.Count; i++)
|
|
{
|
|
for (int j = 0; j < tempGame.Count; j++)
|
|
{
|
|
if (DisconnectedData.toolsName[i].Equals(tempGame[j].name))
|
|
{
|
|
Vector3 temppos = new Vector3(DisconnectedData.toolsPos[i].x, DisconnectedData.toolsPos[i].y, DisconnectedData.toolsPos[i].z);
|
|
Vector3 temprot = new Vector3(DisconnectedData.toolsRot[i].x, DisconnectedData.toolsRot[i].y, DisconnectedData.toolsRot[i].z);
|
|
ToolsItemManager.Instance.CreatToolItem(tempGame[j], temppos, temprot);
|
|
//Debug.Log(tempGame[j].name + " ======");
|
|
}
|
|
}
|
|
}
|
|
//SceneLoad.Instance.SceneChange(DisconnectedData.SceneName);
|
|
UIManager.Instance.bottomCotroller.buttomPanel.SetActive(true);
|
|
UIManager.Instance.time.countTime = DisconnectedData.Timer;
|
|
UIManager.Instance.loginController.gameObject.SetActive(false);
|
|
UIManager.Instance.jobCardController.show(DisconnectedData.timuAnd);
|
|
im.gameObject.SetActive(false);
|
|
UIManager.Instance.goToScene.OnGo(DisconnectedData.userBianHao);
|
|
UIManager.Instance.goToScene.userID.text = DisconnectedData.userBianHao;
|
|
UIManager.Instance.exitBtn.gameObject.SetActive(true);
|
|
te.text = "考生姓名:"+DisconnectedData.UserName;
|
|
//isDuanDianok = true;
|
|
}
|
|
void LoadJSON(string json)
|
|
{
|
|
//yield return new WaitForSeconds(1f);
|
|
//string sPath = fileName;
|
|
//using (UnityWebRequest oReq = UnityWebRequest.Get(sPath))
|
|
//{
|
|
// yield return oReq.SendWebRequest();
|
|
// if (!string.IsNullOrEmpty(oReq.error))
|
|
// {
|
|
// Debug.Log("获取配置信息失败!");
|
|
// yield break;
|
|
// }
|
|
// string json = oReq.downloadHandler.text;
|
|
DisconnectedData = new DisconnectedData();
|
|
DisconnectedData.PlayerPosition = new pos();
|
|
DisconnectedData.PlayerRotions = new pos();
|
|
DisconnectedData.toolsName = new List<string>();
|
|
DisconnectedData.keyValuePairs = new Dictionary<string, bool>();
|
|
DisconnectedData.timuAnd = new timuAndOptoin();
|
|
DisconnectedData.timuAnd.userID = new List<string>();
|
|
DisconnectedData.timuAnd.userName = new List<string>();
|
|
DisconnectedData.timuAnd.workSpace = new List<string>();
|
|
DisconnectedData.timuAnd.aqcss = new List<string>();
|
|
DisconnectedData.timuAnd.fxdfx = new List<string>();
|
|
DisconnectedData.timuAnd.bools = new List<bool>();
|
|
DisconnectedData.toolsPos = new List<pos>();
|
|
DisconnectedData.toolsRot = new List<pos>();
|
|
DisconnectedData = JsonConvert.DeserializeObject<DisconnectedData>(json);
|
|
//load1234("12345", "12345", json);
|
|
//}
|
|
//init();
|
|
}
|
|
public string Filter(string str, char[] charsToRemove)
|
|
{
|
|
return String.Concat(str.Split(charsToRemove.ToArray()));
|
|
}
|
|
}
|