using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; using ZIM; public class InfraredLocateTest : MonoBehaviour { public ZIMWebCamera webCamera; public List crosshairInCamera; public List InfraredLocation { get; private set; } public Color[] pixels { get; private set; } InfraredLocate infraredLocate; // Update is called once per frame void Update() { //WebCamTexture texture = webCamera?.webCamTexture; //if (texture == null) return; //if (infraredLocate == null) // infraredLocate = new InfraredLocate(webCamera); //if (texture.didUpdateThisFrame) // 检查camera是否更新帧 //{ // pixels = texture.GetPixels(); // 从左往右、从下往上 // InfraredLocation = infraredLocate.Get(pixels); // foreach (var i in crosshairInCamera) // { // i.gameObject.SetActive(false); // } // for (int i = 0; i < InfraredLocation.Count; i++) // { // // 检测到光点 // var posInCanvas = InfraredLocation[i].pixelToLocalPosition_AnchorCenter(webCamera.Size, webCamera.rawImage.rectTransform.rect); // crosshairInCamera[i].gameObject.SetActive(true); // crosshairInCamera[i].rectTransform.anchoredPosition = posInCanvas; // //Debug.Log("location: " + posInCanvas); // } //if (InfraredLocation.Count == 0) //{ // // 没有检测到亮点 // crosshairInCamera.gameObject.SetActive(false); //} //else //{ // // 检测到光点 // var posInCanvas = ((Vector2)InfraredLocation).pixelToLocalPosition_AnchorCenter(webCamera.Size, webCamera.rawImage.rectTransform.rect); // crosshairInCamera.gameObject.SetActive(true); // crosshairInCamera.rectTransform.anchoredPosition = posInCanvas; // //Debug.Log("location: " + posInCanvas); //} //} } }