MiracastUI.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading;
  6. #if ARMiracast
  7. using Unity.RenderStreaming;
  8. using Unity.RenderStreaming.Signaling;
  9. #endif
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. namespace EZXR.Glass.MiraCast
  13. {
  14. public class MiracastUI : MonoBehaviour
  15. {
  16. #if ARMiracast
  17. InputField inputField;
  18. Text buttonText;
  19. string path;
  20. // Start is called before the first frame update
  21. void Start()
  22. {
  23. inputField = transform.Find("InputField").GetComponent<InputField>();
  24. buttonText = transform.Find("Button/Text").GetComponent<Text>();
  25. path = Path.Combine(Application.persistentDataPath, "miracast.cfg");
  26. if (File.Exists(path))
  27. {
  28. inputField.text = File.ReadAllText(path);
  29. OnButtonClicked();
  30. }
  31. }
  32. // Update is called once per frame
  33. void Update()
  34. {
  35. }
  36. public void OnButtonClicked()
  37. {
  38. if (buttonText.text == "Connect")
  39. {
  40. Run();
  41. buttonText.text = "DisConnect";
  42. File.WriteAllText(path, inputField.text);
  43. }
  44. else if (buttonText.text == "DisConnect")
  45. {
  46. Stop();
  47. buttonText.text = "Connect";
  48. }
  49. }
  50. void Run()
  51. {
  52. MiracastManager.Instance.Run(inputField.text);
  53. }
  54. void Stop()
  55. {
  56. MiracastManager.Instance.Stop();
  57. }
  58. #endif
  59. }
  60. }