| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using InfraredManager;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using ZIM;
- using ZIM.Unity;
- //处理光源检测部分
- public class InfraredLightGuider2 : MonoBehaviour
- {
- [SerializeField]
- RawImage rawImage;
- //相机感光部分
- [SerializeField]
- Slider slider;
- [SerializeField] List<RectTransform> _crosshairsInCamera;
- // Start is called before the first frame update
- void Start()
- {
- if (InfraredDemo._ins)
- {
- slider.onValueChanged.AddListener((value) =>
- {
- InfraredDemo._ins.onSliderEvent(value);
- });
- InfraredDemo._ins.onSetSliderValue(slider);
- SetLocatePointsToCameraRender(ScreenLocate.quadUnityVectorList,1,1);
- }
- }
- void Update()
- {
- if (InfraredDemo.running)
- {
- //渲染相机画面
- //渲染相机画面
- Texture texture = InfraredDemo.infraredCameraHelper.GetCameraTexture();
- if (rawImage.texture == null || texture.GetNativeTexturePtr() != rawImage.texture.GetNativeTexturePtr())
- rawImage.texture = texture;
- //rawImage.material = InfraredDemo.infraredCameraHelper.GetCameraMaterial();
- //在相机画面显示准心
- if (ScreenLocate.Main)
- {
- var _sl = ScreenLocate.Main;
- var buffer = _sl.infraredSpotBuffer;
- if (buffer != null)
- {
- for (int i = 0; i < buffer.Length; i++)
- {
- if (buffer[i].CameraLocation != null)
- {
- //添加一个偏移量,使得最后输出的准心是指向正中心
- Vector2 newPoint2 = _sl.GetOffsetCameraLocation(buffer[i].CameraLocation.Value);
- // 检测到光点
- var pos = newPoint2.pixelToLocalPosition_AnchorCenter(_sl.mUVCCameraInfo.Size, rawImage.rectTransform.rect);
- _crosshairsInCamera[i].gameObject.SetActive(true);
- _crosshairsInCamera[i].anchoredPosition = pos;
- }
- else
- _crosshairsInCamera[i].gameObject.SetActive(false);
- }
- }
- }
- }
- }
- public void SetLocatePointsToCameraRender(List<Vector2> points, float w, float h)
- {
- Transform pointsTF2 = rawImage.transform.Find("Points");
- if (pointsTF2.childCount == points.Count)
- {
- Vector2 texSize = new Vector2(w, h);
- for (int i = 0; i < pointsTF2.childCount; i++)
- {
- Transform pointTF = pointsTF2.GetChild(i);
- Vector2 pos = points[i];
- pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(texSize, rawImage.rectTransform.rect);
- pointTF.gameObject.SetActive(true);
- }
- }
- }
- public void Close() {
- Destroy(gameObject);
- }
- }
|