PDFPageTextureHolder.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. http://www.cgsoso.com/forum-211-1.html
  3. CG搜搜 Unity3d 每日Unity3d插件免费更新 更有VIP资源!
  4. CGSOSO 主打游戏开发,影视设计等CG资源素材。
  5. 插件如若商用,请务必官网购买!
  6. daily assets update for try.
  7. U should buy the asset from home store if u use it in your project!
  8. */
  9. using Paroxe.PdfRenderer.WebGL;
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. namespace Paroxe.PdfRenderer.Internal.Viewer
  13. {
  14. public class PDFPageTextureHolder
  15. {
  16. public AspectRatioFitter m_AspectRatioFitter;
  17. public int m_PageIndex;
  18. public GameObject m_Page;
  19. #if UNITY_WEBGL
  20. public bool m_RenderingStarted;
  21. public bool m_Visible;
  22. public IPDFJS_Promise m_RenderingPromise;
  23. #endif
  24. private Texture2D m_Texture;
  25. public PDFViewer m_PDFViewer;
  26. public void RefreshTexture()
  27. {
  28. Texture = m_Texture;
  29. }
  30. public Texture2D Texture
  31. {
  32. get
  33. {
  34. return m_Texture;
  35. }
  36. set
  37. {
  38. m_Texture = value;
  39. RawImage rawImage = m_Page.GetComponent<RawImage>();
  40. if (rawImage == null)
  41. rawImage = m_Page.gameObject.AddComponent<RawImage>();
  42. if (value != null)
  43. {
  44. rawImage.texture = value;
  45. rawImage.uvRect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
  46. rawImage.color = Color.white;
  47. }
  48. else
  49. {
  50. if (m_PDFViewer.PageTileTexture != null)
  51. {
  52. rawImage.texture = m_PDFViewer.PageTileTexture;
  53. RectTransform rt = rawImage.transform as RectTransform;
  54. rawImage.uvRect = new Rect(0.0f, 0.0f,
  55. rt.sizeDelta.x / rawImage.texture.width,
  56. rt.sizeDelta.y / rawImage.texture.height);
  57. }
  58. else
  59. {
  60. rawImage.texture = null;
  61. rawImage.color = m_PDFViewer.PageColor;
  62. }
  63. }
  64. if (m_AspectRatioFitter != null)
  65. m_AspectRatioFitter.aspectRatio = value.width / (float)value.height;
  66. }
  67. }
  68. }
  69. }