SafetyGreyCameraUI.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class SafetyGreyCameraUI : MonoBehaviour
  6. {
  7. public Material greyCameraMaterial;
  8. public Transform planeTransform;
  9. //public RawImage rawImage;
  10. int imageWidth;
  11. int imageHeight;
  12. bool outBUdate = true;
  13. uint outCurrFrameIndex = 0;
  14. ulong outFrameExposureNano = 0;
  15. byte[] outLeftFrameData;
  16. byte[] outRightFrameData;
  17. float[] trArray;
  18. TextureFormat textureFormat = TextureFormat.Alpha8;
  19. Texture2D textureTemp;
  20. public void Start()
  21. {
  22. Init();
  23. }
  24. public void Init()
  25. {
  26. imageWidth = (int)API_Module_Device.Current.FishEyeResolution.x;
  27. imageHeight = (int)API_Module_Device.Current.FishEyeResolution.y;
  28. outBUdate = true;
  29. outCurrFrameIndex = 0;
  30. outFrameExposureNano = 0;
  31. outLeftFrameData = new byte[imageWidth * imageHeight];
  32. outRightFrameData = new byte[imageWidth * imageHeight];
  33. trArray = new float[7];
  34. textureFormat = TextureFormat.Alpha8;
  35. }
  36. // Update is called once per frame
  37. private void LateUpdate()
  38. {
  39. //if (!GSXRManager.Instance.Initialized)
  40. //{
  41. // return;
  42. //}
  43. this.transform.position = Camera.main.transform.position + Camera.main.transform.forward.normalized * 0.4f;
  44. this.transform.rotation = Camera.main.transform.transform.rotation;
  45. planeTransform.gameObject.transform.localScale = new Vector3(imageWidth / 8f, 1f, imageHeight / 8f);
  46. if (Application.platform == RuntimePlatform.Android)
  47. {
  48. API_GSXR_Slam.GSXR_Get_LatestFishEyeBinocularData(ref outBUdate, ref outCurrFrameIndex, ref outFrameExposureNano, outLeftFrameData, outRightFrameData);
  49. //GSXRPluginAndroid.GSXRGetLatestCameraFrameData(ref outBUdate, ref outCurrFrameIndex, ref outFrameExposureNano, outLeftFrameData, trArray);
  50. if (outBUdate)
  51. {
  52. Debug.Log("outBUdate == true");
  53. GetTexture(outLeftFrameData);
  54. greyCameraMaterial.mainTexture = textureTemp;
  55. //rawImage.texture = textureTemp;
  56. }
  57. else
  58. {
  59. Debug.Log("Error: Please Check Slamconfig prop: gUseXXXCamera = true");
  60. }
  61. }
  62. }
  63. public Texture2D GetTexture(byte[] outFrameData)
  64. {
  65. if (textureTemp == null)
  66. {
  67. textureTemp = new Texture2D(imageWidth, imageHeight, textureFormat, false);
  68. }
  69. textureTemp.LoadRawTextureData(outFrameData);
  70. textureTemp.Apply();
  71. return textureTemp;
  72. }
  73. }