优化:解决切换pdf操作多崩溃问题:
在 rawImage.GetComponent<RawImage>().texture赋值前先删除之前的texture
if ( rawImage.GetComponent<RawImage>().texture != null)
{
GameObject.Destroy( rawImage.GetComponent<RawImage>().texture);
}
正文:
先导入插件 PDFRenderer
链接: https://pan.baidu.com/s/1Un-FoINPmK8iVBRLS0jkTw 提取码: z78q
然后使用以下代码就可以
using Paroxe.PdfRenderer;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class PlayPDF : MonoBehaviour
{
public RawImage rawImage; //显示PDF的UI
PDFDocument pdfDocument; //PDF文件
PDFRenderer pdfRenderer; //PDF渲染
int curPDFPage; //当前显示的PDF页数
int countOfPDFAllPage; //PDF文件总页数
//PDF网络路径 (这里填入自己的网络PDF路径)
string url= "https:// xx.xxxx.xxxx.pdf";
// Start is called before the first frame update
void Start()
{
StartCoroutine(DownLoadFile(url));
}
/// <summary>
/// 加载本地PDF文件
/// </summary>
/// <param name="url"></param>
void LoadLocalPDF(string url)
{
pdfDocument = new PD