118 lines
3.5 KiB
C#
118 lines
3.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class LocalVideoAlarmUI : MonoBehaviour, IPointerClickHandler
|
|
{
|
|
public TextMeshProUGUI textMeshPro;
|
|
public LocalVideoAlarm localVideoAlarm;
|
|
public Image expand_image;
|
|
public Button close_bt;
|
|
public GameObject preform;
|
|
public RectTransform Content;
|
|
public Canvas canvas;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
if (Menu.M_全景监控_摄像头 != CabinetUIManager.Instance.current_menu)
|
|
return;
|
|
GameObject go;
|
|
if (canvas.transform.childCount != 0)
|
|
{
|
|
DestroyImmediate(canvas.transform.GetChild(0).gameObject);
|
|
}
|
|
|
|
go = Instantiate(expand_image.gameObject);
|
|
go.transform.SetParent(canvas.transform);
|
|
go.transform.rotation = Quaternion.identity;
|
|
close_bt = canvas.transform.GetChild(0).Find("关闭").GetComponent<Button>();
|
|
close_bt.onClick.RemoveAllListeners();
|
|
close_bt.onClick.AddListener(() =>
|
|
{
|
|
canvas.transform.GetChild(0).gameObject.SetActive(false);
|
|
});
|
|
|
|
// 动态配置要显示的图片
|
|
var localVideoAlarmItems = Content.GetComponentsInChildren<LocalVideoAlarmItem>().ToList();
|
|
for (int i = 0; i < localVideoAlarmItems.Count; i++)
|
|
{
|
|
Carousel.inst.SetImages(localVideoAlarmItems[i].sprites);
|
|
}
|
|
|
|
var worldPosition = expand_image.transform.position;
|
|
|
|
var list = localVideoAlarm.transform.root.GetComponent<CabinetUIManager>().cabinet_ui_base_list;
|
|
var v = Array.FindAll(list.ToArray(), (itme) =>
|
|
{
|
|
return (itme.name == "本地报警");
|
|
});
|
|
for (int i = 0; i < v.Length; i++)
|
|
{
|
|
v[i].gameObject.GetComponent<LocalVideoAlarm>().localVideoAlarmUI.canvas.gameObject.SetActive(false);
|
|
}
|
|
canvas.gameObject.SetActive(true);
|
|
|
|
|
|
RectTransform canvasRectTransform = canvas.GetComponent<RectTransform>();
|
|
|
|
|
|
Vector3 screenPos = Camera.main.WorldToScreenPoint(worldPosition);
|
|
|
|
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, screenPos, canvas.worldCamera, out Vector2 overlayPos);
|
|
|
|
|
|
//go.GetComponent<RectTransform>().position = new Vector3(overlayPos.x, overlayPos.y, 0);
|
|
go.GetComponent<RectTransform>().localPosition = new Vector3(overlayPos.x, overlayPos.y, 0);
|
|
|
|
go.GetComponent<RectTransform>().localScale = Vector3.one;
|
|
go.transform.rotation = Quaternion.identity;
|
|
go.SetActive(true);
|
|
|
|
for (int i = 0; i < go.transform.Find("Scroll View/Viewport/Content").childCount; i++)
|
|
{
|
|
var R = go.transform.Find("Scroll View/Viewport/Content").GetChild(i).GetComponent<RectTransform>();
|
|
R.position = Vector3.zero;
|
|
R.rotation = Quaternion.Euler(Vector3.zero);
|
|
R.localScale = Vector3.one;
|
|
}
|
|
|
|
LocalVideo.Inst.current_UI = this;
|
|
}
|
|
|
|
|
|
public void LoadShowInfo(int num)
|
|
{
|
|
try
|
|
{
|
|
|
|
|
|
Content.sizeDelta = new Vector2(0, Content.GetComponent<GridLayoutGroup>().cellSize.y * int.Parse(textMeshPro.text));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log(e.StackTrace + "\n" + e.Message);
|
|
}
|
|
}
|
|
|
|
|
|
}
|