using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; using UnityEngine.UI; public class ClickEventLens : MonoBehaviour { public List clickEventLens = new List(); public AutoScaleUI scaleUI; public Transform lensUI; public static Transform Camera; public Button button; public TextMeshProUGUI text; public Material material; public MeshCollider mycollider; //该摄像头是否在播放视频 public bool isplay = false; private void Awake() { mycollider = gameObject.GetComponent(); clickEventLens = GameObject.FindObjectsOfType().ToList(); lensUI = transform.GetChild(0); scaleUI = lensUI.GetComponent(); button = scaleUI.button; text = scaleUI.text; material = GetComponent().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.eulerAngles = Camera.eulerAngles; } private void OnMouseEnter() { lensUI.gameObject.SetActive(true); if (!isplay) ChangeMaterialColor(gameObject, 1); } private void OnMouseExit() { lensUI.gameObject.SetActive(false); if (!isplay) ChangeMaterialColor(gameObject, 99); } private void OnMouseDown() { var t = text.text.Replace("摄像", ""); //if (BoolMonitor.Value) { ChangeMaterialColor(gameObject, 4); WebInteraction.Inst.current_videoNumber = t; WebInteraction.Inst.isVideoPlay = true; WebInteraction.Inst.OpenVideo(t); float x = Input.mousePosition.x; float y = Screen.height - Input.mousePosition.y; WebInteraction.Inst.SendVideoPosition(x, y); } } public void ChangeMaterialColor(GameObject go, int index) { Material material = null; switch (index) { case 1: material = Resources.Load("Materials/1Tou"); break; case 2: material = Resources.Load("Materials/2Tou"); break; case 3: material = Resources.Load("Materials/3Tou"); break; case 4: material = Resources.Load("Materials/4Tou"); break; default: material = this.material; break; } go.GetComponent().material = material; } // 闪烁 public IEnumerator TwinkleLens(float looptime) { for (int i = 0; i < 4; i++) { ChangeMaterialColor(gameObject, 1); yield return new WaitForSeconds(looptime); ChangeMaterialColor(gameObject, 99); yield return new WaitForSeconds(looptime); } } }