GQ_Communicate/GQ_URP/GQ/Assets/script/摄像头/ClickEventLens.cs

167 lines
4.7 KiB
C#

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ClickEventLens : MonoBehaviour
{
public Coroutine coroutine = null;
public BaseConf baseConf;
public List<ClickEventLens> clickEventLens = new List<ClickEventLens>();
public AutoScaleUI scaleUI;
public Transform lensUI_tranform;
public LensUI lensUI;
public static Transform Camera;
public Button button;
public TextMeshProUGUI text;
public Material material;
public MeshCollider mycollider;
/// <summary>
/// 该摄像头是否在播放视频
/// </summary>
public bool isplay = false;
private void Awake()
{
mycollider = gameObject.GetComponent<MeshCollider>();
clickEventLens = GameObject.FindObjectsOfType<ClickEventLens>().ToList();
lensUI_tranform = transform.GetChild(0);
lensUI = lensUI_tranform.GetComponent<LensUI>();
scaleUI = lensUI_tranform.GetComponent<AutoScaleUI>();
button = scaleUI.button;
text = scaleUI.text;
material = GetComponent<Renderer>().materials[0];
}
void Start()
{
Camera = UnityEngine.Camera.main.transform;
}
// Update is called once per frame
void Update()
{
if (mycollider)
{
if (Menu.M_全景监控_摄像头 == CabinetUIManager.Instance.current_menu)
mycollider.enabled = true;
else
mycollider.enabled = false;
}
lensUI_tranform.eulerAngles = Camera.eulerAngles;
}
private void OnMouseEnter()
{
lensUI_tranform.gameObject.SetActive(true);
lensUI.maodian.position = Input.mousePosition;
if (!isplay)
ChangeMaterialColor(gameObject, 1);
}
private void OnMouseExit()
{
lensUI_tranform.gameObject.SetActive(false);
if (!isplay)
ChangeMaterialColor(gameObject, 99);
}
private void OnMouseDown()
{
var t = text.text.Replace("摄像", "");
if (!baseConf.conf1.isPicture)
{
ChangeMaterialColor(gameObject, 4);
//WebInteraction.Inst.current_videoNumber = t;
WebInteraction.Inst.current_videoNumber = baseConf.conf1.LensID;
WebInteraction.Inst.isVideoPlay = true;
//WebInteraction.Inst.OpenVideo(t);
WebInteraction.Inst.OpenVideo(baseConf.conf1.LensID);
float x = Input.mousePosition.x;
float y = Screen.height - Input.mousePosition.y;
WebInteraction.Inst.SendVideoPosition(x, y);
}
else
{
WebInteraction.Inst.current_videoNumber = baseConf.conf1.LensID;
ChangeMaterialColor(gameObject, 4);
WebInteraction.Inst.OpenVideo(baseConf.conf1.base64.ToString(), "1");
}
}
public void ChangeMaterialColor(GameObject go, int index)
{
Material material = null;
switch (index)
{
case 1:
material = Resources.Load<Material>("Materials/1Tou");
break;
case 2:
material = Resources.Load<Material>("Materials/2Tou");
break;
case 3:
material = Resources.Load<Material>("Materials/3Tou");
break;
case 4:
material = Resources.Load<Material>("Materials/4Tou");
break;
case 5:
material = Resources.Load<Material>("Materials/5Hui");
break;
default:
material = this.material;
break;
}
go.GetComponent<Renderer>().material = material;
}
/// <summary>
/// 闪烁
/// </summary>
/// <param name="looptime"></param>
/// <returns></returns>
public IEnumerator TwinkleLens(float looptime)
{
for (int i = 0; i < 3; i++)
{
ChangeMaterialColor(gameObject, 1);
yield return new WaitForSeconds(looptime);
ChangeMaterialColor(gameObject, 99);
yield return new WaitForSeconds(looptime);
}
}
/// <summary>
/// 本地视频告警闪烁
/// </summary>
/// <param name="looptime"></param>
/// <returns></returns>
public IEnumerator AlwaysFlashing(float looptime)
{
while (true)
{
//for (int i = 0; i < 3; i++)
//{
ChangeMaterialColor(gameObject, 1);
yield return new WaitForSeconds(looptime);
ChangeMaterialColor(gameObject, 99);
yield return new WaitForSeconds(looptime);
//}
}
//yield return null;
}
}