326 lines
9.7 KiB
C#
326 lines
9.7 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
using SimpleJSON;
|
|
using static GameManager;
|
|
using Newtonsoft.Json;
|
|
|
|
public class WebInteraction : MonoBehaviour
|
|
{
|
|
public static WebInteraction Inst;
|
|
|
|
public string current_videoNumber = null;
|
|
|
|
/// <summary>
|
|
/// 视频监控是否为打开状态
|
|
/// </summary>
|
|
public bool isVideoPlay = false;
|
|
|
|
/// <summary>
|
|
/// 工作票是否为打开状态
|
|
/// </summary>
|
|
public bool isWorkPlay = false;
|
|
|
|
public GameManager gameManager;
|
|
|
|
private void Awake()
|
|
{
|
|
Inst = this;
|
|
//StartCoroutine(QiangZhi());
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
bt.onClick.AddListener(() =>
|
|
{
|
|
//gameManager.token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTI2NDMyODksInVzZXJuYW1lIjoiMTgzMTIzNDU2NzgifQ.uMoC7I4SytLEgYTKHxyvOv7Lygeb9zDCmhLDYv1cJrA";
|
|
//gameManager.enabled = true;
|
|
});
|
|
}
|
|
|
|
//前端调用Unity 方法逻辑
|
|
//参数1 脚本所挂载的物体名 GameManager
|
|
//参数2 脚本内方法名 unity_token_value
|
|
//参数3 传递的参数 token值
|
|
|
|
/// <summary>
|
|
/// 前端调用此方法传递Token
|
|
/// </summary>
|
|
/// <param name="token"></param>
|
|
public IEnumerator unity_token_value(string jsonData)
|
|
{
|
|
try
|
|
{
|
|
JSONNode dataNode = JSON.Parse(jsonData);
|
|
gameManager.arguments.token = dataNode["data"]["token"].Value;
|
|
gameManager.arguments.heatThresholdValueMax = dataNode["data"]["heatThresholdValueMax"].Value;
|
|
gameManager.arguments.heatThresholdValueMin = dataNode["data"]["heatThresholdValueMin"].Value;
|
|
gameManager.arguments.humidityThresholdValueMax = dataNode["data"]["humidityThresholdValueMax"].Value;
|
|
gameManager.arguments.humidityThresholdValueMin = dataNode["data"]["humidityThresholdValueMin"].Value;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Debug.Log("解析Token错误");
|
|
}
|
|
|
|
|
|
yield return (StartCoroutine(GameManager.Inst.LoadAddress((ct) =>
|
|
{
|
|
if (ct != null)
|
|
{
|
|
GameManager.Inst.Jk_URL = new webURL(ct);
|
|
StartCoroutine(GameManager.Inst.Initialize((x)=>
|
|
{
|
|
if (!string.IsNullOrEmpty(x))
|
|
{
|
|
#region 循环读取信息
|
|
if (!gameManager.isgonging)
|
|
{
|
|
StartCoroutine(
|
|
CombineJSON.GetJson_POST(GameManager.Inst.Jk_URL.gj_cx, GameManager.Inst.arguments.token, 1800, (jsonResult3) =>
|
|
{
|
|
if (!string.IsNullOrEmpty(jsonResult3))
|
|
{
|
|
try
|
|
{
|
|
gameManager.root_AllAlarm = JsonConvert.DeserializeObject<TmsAlarmQuery.Root>(jsonResult3);
|
|
|
|
Array.ForEach(GameObject.FindObjectsOfType<TmsAlarmQuery>(), itme =>
|
|
{
|
|
itme.tmsAlarmLists.Clear();
|
|
});
|
|
|
|
gameManager.tmsAlarms.Clear();
|
|
|
|
gameManager.Load_TmsAlarm();
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log("序列化-循环告警查询错误:" + e.Message);
|
|
}
|
|
}
|
|
}));
|
|
|
|
StartCoroutine(
|
|
CombineJSON.GetJson_POST(GameManager.Inst.Jk_URL.hj_cx, GameManager.Inst.arguments.token, 1800, (jsonResult2) =>
|
|
{
|
|
if (!string.IsNullOrEmpty(jsonResult2))
|
|
{
|
|
try
|
|
{
|
|
gameManager.root_AllENV = JsonConvert.DeserializeObject<ENVQuery.Root>(jsonResult2);
|
|
|
|
gameManager.ENVs.Clear();
|
|
|
|
gameManager.Load_ENV();
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log("序列化-循环环境查询错误:" + e.Message);
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
#endregion
|
|
|
|
gameManager.isgonging = true;
|
|
}
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("获取穿透错误!");
|
|
}
|
|
})));
|
|
|
|
}
|
|
|
|
public Button bt;
|
|
|
|
public IEnumerator QiangZhi()
|
|
{
|
|
string filePath = Application.streamingAssetsPath + "/tk.txt";
|
|
|
|
UnityWebRequest www = UnityWebRequest.Get(filePath);
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.result == UnityWebRequest.Result.Success)
|
|
{
|
|
string fileContent = www.downloadHandler.text;
|
|
|
|
if (string.IsNullOrEmpty(fileContent)) yield break;
|
|
gameManager.arguments.token = fileContent;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 发送视频监控坐标的函数
|
|
/// </summary>
|
|
/// <param name="x"></param>
|
|
/// <param name="y"></param>
|
|
public void SendVideoPosition(float x, float y)
|
|
{
|
|
// 在此处将视频监控坐标发送给前端
|
|
Debug.Log("Sending video position: (" + x + ", " + y + ")");
|
|
Application.ExternalCall("web_video_position", x + "," + y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭视频监控的函数
|
|
/// </summary>
|
|
/// <param name="videoNumber"></param>
|
|
public void CloseVideo(string videoNumber)
|
|
{
|
|
// 在此处处理关闭视频监控的逻辑
|
|
Debug.Log("Closing video number: " + videoNumber);
|
|
isVideoPlay = false;
|
|
Application.ExternalCall("web_video_close", videoNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打开视频监控的函数
|
|
/// </summary>
|
|
/// <param name="videoNumber"></param>
|
|
public void OpenVideo(string videoNumber)
|
|
{
|
|
// 在此处处理打开视频监控的逻辑
|
|
Debug.Log("Opening video number: " + videoNumber);
|
|
Application.ExternalCall("web_video_open", videoNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打开现场作业的函数
|
|
/// </summary>
|
|
public void OpenTicket()
|
|
{
|
|
// 在此处处理打开现场作业的逻辑
|
|
Debug.Log("Opening ticket");
|
|
Application.ExternalCall("web_ticket_open", "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭现场作业的函数
|
|
/// </summary>
|
|
public void CloseTicket()
|
|
{
|
|
// 在此处处理关闭现场作业的逻辑
|
|
Debug.Log("Closing ticket");
|
|
Application.ExternalCall("web_ticket_close", "");
|
|
|
|
//foreach (var item in GameManager.Inst.Cabinets_go)
|
|
//{
|
|
// item.transform.Find("高亮").gameObject.SetActive(false);
|
|
//}
|
|
for (int i = 0; i < CabinetUIManager.Instance.cabine_hights.Count; i++)
|
|
{
|
|
CabinetUIManager.Instance.cabine_hights[i].SetActive(false);
|
|
}
|
|
}
|
|
|
|
[ContextMenu("工作票设备关联的函数")]
|
|
/// <summary>
|
|
/// 工作票设备关联机柜变色
|
|
/// </summary>
|
|
/// <param name="deviceNumbers"></param>
|
|
public void unity_ticket_cabinet(string deviceNumbers)
|
|
{
|
|
|
|
var devices = deviceNumbers.Split(',');
|
|
List<GameObject> ls = new List<GameObject>();
|
|
ls.AddRange(GameManager.Inst.Cabinets_go);
|
|
ls.AddRange(GameManager.Inst.Racks_go);
|
|
|
|
for (int i = 0; i < ls.Count; i++)
|
|
{
|
|
for (int j = 0; j < devices.Length; j++)
|
|
{
|
|
if (devices[j] == ls[i].GetComponent<DeviceQuery>().deviceList.id)
|
|
{
|
|
var Cabinet = gameManager.FindParent(ls[i].gameObject, gameManager.IsDesiredParent);
|
|
if (Cabinet)
|
|
{
|
|
var hight = Cabinet.transform.Find("高亮").gameObject;
|
|
|
|
changC(hight, "1");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工作票设备关联机柜镜头聚焦
|
|
/// </summary>
|
|
/// <param name="deviceNumbers"></param>
|
|
public void unity_ticket_locate_cabinet(string deviceNumbers)
|
|
{
|
|
List<GameObject> ls = new List<GameObject>();
|
|
ls.AddRange(GameManager.Inst.Cabinets_go);
|
|
for (int i = 0; i < ls.Count; i++)
|
|
{
|
|
if (ls[i].GetComponent<DeviceQuery>().deviceList.id == deviceNumbers)
|
|
{
|
|
ls[i].GetComponent<ClickEvent>().Change_hide(ls[i], true, true);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void changC(GameObject hight, string index)
|
|
{
|
|
hight.SetActive(true);
|
|
|
|
Renderer renderer = hight.GetComponent<Renderer>();
|
|
|
|
|
|
Material[] sharedMaterials = renderer.sharedMaterials;
|
|
|
|
//for (int i = 0; i < sharedMaterials.Length; i++)
|
|
//{
|
|
// sharedMaterials[i] = newMaterial;
|
|
//}
|
|
|
|
sharedMaterials[0] = Resources.Load<Material>("Materials/" + index + "Tou");
|
|
|
|
renderer.sharedMaterials = sharedMaterials;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static class BoolMonitor
|
|
{
|
|
private static bool _value = false;
|
|
/// <summary>
|
|
/// 镜头是否为不动状态
|
|
/// </summary>
|
|
public static bool Value
|
|
{
|
|
get { return _value; }
|
|
set
|
|
{
|
|
if (_value != value)
|
|
{
|
|
_value = value;
|
|
OnValueChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static event EventHandler ValueChanged;
|
|
|
|
static void OnValueChanged()
|
|
{
|
|
ValueChanged?.Invoke(null, EventArgs.Empty);
|
|
}
|
|
}
|
|
|