PDFPageTextureHolder.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Paroxe.PdfRenderer.WebGL;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace Paroxe.PdfRenderer.Internal.Viewer
  5. {
  6. public class PDFPageTextureHolder
  7. {
  8. public AspectRatioFitter m_AspectRatioFitter;
  9. public int m_PageIndex;
  10. public GameObject m_Page;
  11. #if UNITY_WEBGL
  12. public bool m_RenderingStarted;
  13. public bool m_Visible;
  14. public IPDFJS_Promise m_RenderingPromise;
  15. #endif
  16. private Texture2D m_Texture;
  17. public PDFViewer m_PDFViewer;
  18. public void RefreshTexture()
  19. {
  20. Texture = m_Texture;
  21. }
  22. public Texture2D Texture
  23. {
  24. get
  25. {
  26. return m_Texture;
  27. }
  28. set
  29. {
  30. m_Texture = value;
  31. RawImage rawImage = m_Page.GetComponent<RawImage>();
  32. if (rawImage == null)
  33. rawImage = m_Page.gameObject.AddComponent<RawImage>();
  34. if (value != null)
  35. {
  36. rawImage.texture = value;
  37. rawImage.uvRect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
  38. rawImage.color = Color.white;
  39. }
  40. else
  41. {
  42. if (m_PDFViewer.PageTileTexture != null)
  43. {
  44. rawImage.texture = m_PDFViewer.PageTileTexture;
  45. RectTransform rt = rawImage.transform as RectTransform;
  46. rawImage.uvRect = new Rect(0.0f, 0.0f,
  47. rt.sizeDelta.x / rawImage.texture.width,
  48. rt.sizeDelta.y / rawImage.texture.height);
  49. }
  50. else
  51. {
  52. rawImage.texture = null;
  53. }
  54. rawImage.color = m_PDFViewer.PageColor;
  55. }
  56. if (m_AspectRatioFitter != null)
  57. m_AspectRatioFitter.aspectRatio = value.width / (float)value.height;
  58. }
  59. }
  60. }
  61. }