Unity 打开PDF显示在UI或者物体上面
1.里面有用到PDF插件,如果你没有插件可以去下面链接下载:
有积分了可以直接下,没有的可以评论联系我,给你发
2. 这是设置对象
下面上脚本
using Paroxe.PdfRenderer; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UI; public class DocumentGroup : MonoBehaviour { public float m_Page = 0; string downloadFileName; //pdf 地址 public GameObject link; //plane 也可以 public RawImage rawImage; //UI 也可以 private void Update() { m_Page += Time.deltaTime; PrintLocalPDF(); } public void PrintLocalPDF() { #if UNITY_EDITOR downloadFileName = Application.dataPath + "/wcl.pdf"; print(downloadFileName); #elif UNITY_ANDROID downloadFileName = Application.persistentDataPath+"/wcl.pdf"; #endif PDFDocument pdfDocument = new PDFDocument(downloadFileName); if (pdfDocument.IsValid) { int pageCount = pdfDocument.GetPageCount(); PDFRenderer renderer = new PDFRenderer(); Texture2D tex = renderer.RenderPageToTexture(pdfDocument.GetPage((int)m_Page % pageCount), 1024, 1024); tex.filterMode = FilterMode.Bilinear; tex.anisoLevel = 8; // link.GetComponent<MeshRenderer>().material.mainTexture = tex; rawImage.texture = tex; } } }
运行就能播放了,具体扩展看自己需求