CamFiLiveViewManager.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using System.Net;
  6. using System.IO;
  7. using System.Net.Sockets;
  8. namespace MartellGroupPhoto
  9. {
  10. public class CamFiLiveViewManager : MonoBehaviour
  11. {
  12. public static CamFiLiveViewManager Instance;
  13. public Texture2D CameraTexture;
  14. // ==================================================
  15. private void Awake()
  16. {
  17. Instance = this;
  18. }
  19. private void Start()
  20. {
  21. Init();
  22. }
  23. private void Update()
  24. {
  25. if (tcpClient.Connected)
  26. {
  27. Debug.Log("TCP已连接");
  28. // tcpClient.
  29. // Stream serverstream = tcpClient.GetStream();
  30. // if (serverstream.CanRead)
  31. // {
  32. // Debug.Log($"串流可读,尺寸为:{tcpClient.ReceiveBufferSize}");
  33. // // using (MemoryStream writer = new MemoryStream())
  34. // // {
  35. // // byte[] readBuffer = new byte[tcpClient.ReceiveBufferSize];
  36. // // // while (serverstream)
  37. // // }
  38. // // using (FileStream fs = new FileStream())
  39. // byte[] readBuffer = new byte[tcpClient.ReceiveBufferSize];
  40. // CameraTexture.LoadImage(readBuffer);
  41. // }
  42. }
  43. if (Input.GetKeyDown(KeyCode.T))
  44. {
  45. }
  46. }
  47. // ==================================================
  48. public TcpClient tcpClient;
  49. private void Init()
  50. {
  51. tcpClient = new TcpClient();
  52. // tcpListener = new TcpListener(new IPEndPoint(IPAddress.Parse(CamFiStorage.CamFiIP), int.Parse(CamFiStorage.CamFiLiveViewPort)));
  53. CameraTexture = new Texture2D(2880, 1920);
  54. // socketManager = new SocketManager(new Uri( CamFiStorage.CamFiLiveViewAddress)); // DEBUG // https://(x) ws://(√)
  55. return;
  56. }
  57. public void StartLiveView()
  58. {
  59. Debug.Log("开始接收串流");
  60. Debug.Log(CamFiStorage.CamFiLiveViewAddress);
  61. tcpClient.Connect(new IPEndPoint(IPAddress.Parse(CamFiStorage.CamFiIP), int.Parse(CamFiStorage.CamFiLiveViewPort)));
  62. return;
  63. }
  64. }
  65. }