InfraredLightGuider2.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using AdaptUI;
  2. using InfraredManager;
  3. using o0InfraredLocate.ZIM;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using ZIM;
  9. using ZIM.Unity;
  10. //处理光源检测部分
  11. public class InfraredLightGuider2 : MonoBehaviour
  12. {
  13. [SerializeField]
  14. RawImage rawImage;
  15. //相机感光部分
  16. [SerializeField]
  17. Slider slider;
  18. //亮度
  19. [SerializeField]
  20. Slider sliderBrightness;
  21. [SerializeField] List<RectTransform> _crosshairsInCamera;
  22. // Start is called before the first frame update
  23. private bool bIpad = false;
  24. void Start()
  25. {
  26. DeviceTypeHelper.DeviceType detectedType = DeviceTypeHelper.DetectDeviceType();
  27. //根据设备类型显示不同的登录界面
  28. if (detectedType == DeviceTypeHelper.DeviceType.iPad)
  29. {
  30. bIpad = true;
  31. }
  32. if (InfraredDemo._ins)
  33. {
  34. //对比度
  35. slider.onValueChanged.AddListener((value) =>
  36. {
  37. InfraredDemo._ins.onSliderCustomEvent(value,-20.0f,20.0f);
  38. });
  39. InfraredDemo._ins.onSetSliderCustomValue(slider,-20.0f, 20.0f);
  40. //亮度
  41. sliderBrightness.onValueChanged.AddListener((value) =>
  42. {
  43. //if (bIpad) {
  44. // value -= 15;
  45. //}
  46. InfraredDemo._ins.onSliderCustomBrightnessEvent(value, -20.0f, 20.0f);
  47. });
  48. InfraredDemo._ins.onSetSliderCustomBrightnessValue(sliderBrightness, -20.0f, 20.0f);
  49. SetLocatePointsToCameraRender(ScreenLocate.quadUnityVectorList,1,1);
  50. }
  51. Color currentColor = rawImage.color;
  52. currentColor.a = Mathf.Clamp01(1); // Clamp the alpha between 0 and 1
  53. rawImage.color = currentColor;
  54. }
  55. void Update()
  56. {
  57. if (InfraredDemo.running)
  58. {
  59. //渲染相机画面
  60. //渲染相机画面
  61. Texture texture = InfraredDemo.infraredCameraHelper.GetCameraTexture();
  62. if (rawImage.texture == null || texture.GetNativeTexturePtr() != rawImage.texture.GetNativeTexturePtr())
  63. rawImage.texture = texture;
  64. //rawImage.material = InfraredDemo.infraredCameraHelper.GetCameraMaterial();
  65. //在相机画面显示准心
  66. if (ScreenLocate.Main)
  67. {
  68. var _sl = ScreenLocate.Main;
  69. var buffer = _sl.infraredSpotBuffer;
  70. if (buffer != null)
  71. {
  72. for (int i = 0; i < buffer.Length; i++)
  73. {
  74. if (buffer[i].CameraLocation != null)
  75. {
  76. //添加一个偏移量,使得最后输出的准心是指向正中心
  77. Vector2 newPoint2 = _sl.GetOffsetCameraLocation(buffer[i].CameraLocation.Value);
  78. // 检测到光点
  79. var pos = newPoint2.pixelToLocalPosition_AnchorCenter(_sl.mUVCCameraInfo.Size, rawImage.rectTransform.rect);
  80. _crosshairsInCamera[i].gameObject.SetActive(true);
  81. _crosshairsInCamera[i].anchoredPosition = pos;
  82. }
  83. else
  84. _crosshairsInCamera[i].gameObject.SetActive(false);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. public void SetLocatePointsToCameraRender(List<Vector2> points, float w, float h)
  91. {
  92. Transform pointsTF2 = rawImage.transform.Find("Points");
  93. if (pointsTF2.childCount == points.Count)
  94. {
  95. Vector2 texSize = new Vector2(w, h);
  96. for (int i = 0; i < pointsTF2.childCount; i++)
  97. {
  98. Transform pointTF = pointsTF2.GetChild(i);
  99. Vector2 pos = points[i];
  100. pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(texSize, rawImage.rectTransform.rect);
  101. pointTF.gameObject.SetActive(true);
  102. }
  103. }
  104. }
  105. public void Close() {
  106. Destroy(gameObject);
  107. }
  108. }