using DG.Tweening;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using UnityEngine;
public class WebInteraction : MonoBehaviour
{
public static WebInteraction Inst;
public string current_videoNumber = null;
///
/// 视频监控是否为打开状态
///
public bool isVideoPlay = false;
///
/// 工作票是否为打开状态
///
public bool isWorkPlay = false;
public GameManager gameManager;
private void Awake()
{
Inst = this;
}
private void Start()
{
Application.ExternalCall("OnSceneLoaded");
//三维场景加载时显示地图
}
//前端调用Unity 方法逻辑
//参数1 脚本所挂载的物体名 GameManager
//参数2 脚本内方法名 unity_token_value
//参数3 传递的参数 token值
///
/// 前端调用此方法传递Token
///
///
public void unity_token_value(string token)
{
gameManager.token = token;
gameManager.enabled = true;
}
///
/// 发送视频监控坐标的函数
///
///
///
public void SendVideoPosition(float x, float y)
{
// 在此处将视频监控坐标发送给前端
Debug.Log("Sending video position: (" + x + ", " + y + ")");
Application.ExternalCall("web_video_position", x + "," + y);
}
///
/// 关闭视频监控的函数
///
///
public void CloseVideo(string videoNumber)
{
// 在此处处理关闭视频监控的逻辑
Debug.Log("Closing video number: " + videoNumber);
isVideoPlay= false;
Application.ExternalCall("web_video_close", videoNumber);
}
///
/// 打开视频监控的函数
///
///
public void OpenVideo(string videoNumber)
{
// 在此处处理打开视频监控的逻辑
Debug.Log("Opening video number: " + videoNumber);
Application.ExternalCall("web_video_open", videoNumber);
}
///
/// 打开现场作业的函数
///
public void OpenTicket()
{
// 在此处处理打开现场作业的逻辑
Debug.Log("Opening ticket");
Application.ExternalCall("web_ticket_open", "");
}
///
/// 关闭现场作业的函数
///
public void CloseTicket()
{
// 在此处处理关闭现场作业的逻辑
Debug.Log("Closing ticket");
Application.ExternalCall("web_ticket_close", "");
}
///
/// 工作票设备关联的函数
///
///
public void unity_ticket_cabinet(string deviceNumbers)
{
//,
Array.ForEach(deviceNumbers.Split(','), (device) =>
{
GameObject go = null;
List ls = new List();
ls.AddRange(GameManager.Inst.Cabinets_go);
ls.AddRange(GameManager.Inst.Racks_go);
ls.AddRange(GameManager.Inst.MachineSlots_go);
ls.AddRange(GameManager.Inst.TmsCards_go);
go = Array.Find(ls.ToArray(), item =>
{
return (item.GetComponent().deviceList.id == device);
});
if (go != null)
{
try
{
var c = go.GetComponent().materials[0].color;
GameManager.Inst.ChangeMaterialColor(go, 0, new Color(1, 109f / 255, 0, 1));
DOVirtual.Float(0, 10, 1f, null).OnComplete(() => GameManager.Inst.ChangeMaterialColor(go, 0, c));
}
catch (Exception e)
{
Debug.Log(e.Message);
}
}
});
}
public static class BoolMonitor
{
private static bool _value = false;
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);
}
}
}