using InfraredManager; using o0InfraredLocate.ZIM; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using ZIM; using ZIM.Unity; //处理光源检测部分 public class InfraredLightGuider : MonoBehaviour { [SerializeField] RawImage rawImage; //相机感光部分 [SerializeField] Slider slider; [SerializeField] List _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); } //这里为了修改背景摄像机显示 Color currentColor = rawImage.color; currentColor.a = Mathf.Clamp01(1); // Clamp the alpha between 0 and 1 rawImage.color = currentColor; } 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 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); } }