PopWindowManager.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Paroxe.PdfRenderer;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class PopWindowManager : MonoBehaviour
  8. {
  9. public PDFViewer pDFViewer;
  10. public static Texture texture;
  11. public RawImage image;
  12. public static string info;
  13. public static string pdfpath;
  14. public Text fivetext;
  15. public static PopWindowManager Instance;
  16. void Awake()
  17. {
  18. Instance=this;
  19. }
  20. public List<GameObject> golist;
  21. public static int indexwd;
  22. public Action<int> callback;
  23. public void OnEnable()
  24. {
  25. image.texture = texture;
  26. if(pdfpath!=""&&pdfpath!=null)
  27. {
  28. pDFViewer.FilePath=pdfpath;
  29. }
  30. fivetext.text = info;
  31. for (int i=0;i<golist.Count;i++)
  32. {
  33. golist[i].SetActive(false);
  34. }
  35. golist[indexwd].SetActive(true);
  36. StartCoroutine(readpdf());
  37. SetImageFullScreen();
  38. }
  39. IEnumerator readpdf()
  40. {
  41. yield return new WaitForSeconds(1f);
  42. Debug.Log("pdfpath===>"+pdfpath);
  43. if(pdfpath!=""&&pdfpath!=null)
  44. {
  45. Screen.autorotateToLandscapeLeft = true;
  46. Screen.autorotateToLandscapeRight = true;
  47. Screen.autorotateToPortrait = true;
  48. Screen.autorotateToPortraitUpsideDown = true;
  49. pDFViewer.LoadDocumentFromFile(pdfpath);
  50. pdfpath="";
  51. }
  52. }
  53. void SetImageFullScreen()
  54. {
  55. if(image.texture==null)
  56. {
  57. return;
  58. }
  59. // 获取屏幕和图片的宽高比
  60. float screenAspect = (float)Screen.width / Screen.height;
  61. float imageAspect = (float)image.texture.width / image.texture.height;
  62. // 根据宽高比调整图片大小
  63. if (screenAspect > imageAspect)
  64. {
  65. // 屏幕更宽,以高度为基准
  66. image.rectTransform.sizeDelta = new Vector2(
  67. Screen.height * imageAspect,
  68. Screen.height
  69. );
  70. }
  71. else
  72. {
  73. // 屏幕更高,以宽度为基准
  74. image.rectTransform.sizeDelta = new Vector2(
  75. Screen.width,
  76. Screen.width / imageAspect
  77. );
  78. }
  79. // 居中显示
  80. image.rectTransform.anchoredPosition = Vector2.zero;
  81. }
  82. }