using QFramework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Networking;
///
/// 下载Word脚本
///
public class WebGLDownLoadFile : MonoSingleton
{
[DllImport("__Internal")]
private static extern void WebGLDownloadWord(byte[] array, int size, string reportjson);
///
/// 下载Word 方法
///
public void Download(string json)
{
#region 初始化
//LabReprotData reprotData = new LabReprotData();
//// 转json
//string json = JsonUtility.ToJson(reprotData, true);
#endregion
// 调用携程下载数据
StartCoroutine(WebGLDownloadWord(json));
}
///
/// 下载Word
///
/// 实验报告json
///
IEnumerator WebGLDownloadWord(string json)
{
UnityWebRequest request = UnityWebRequest.Get(Global.reportDemoPath);
yield return request.SendWebRequest();
if (string.IsNullOrEmpty(request.error) == false)
{
Debug.Log("错误路径:" + request.error);
}
else
{
// 下载word
DownloadDocx(request.downloadHandler.data, json);
}
}
///
/// 调用下载Word
///
/// 支持多种文件格式下载(doc docx xml xlsx txt等)
/// json数据
public void DownloadDocx(byte[] bytes, string reportjson)
{
WebGLDownloadWord(bytes, bytes.Length, reportjson);
}
}