AR初版demo

This commit is contained in:
lishuo committed 2022-03-04 16:12:15 +08:00
1 parent c1c93c2a60
commit e85d5f8613
82 files changed
+4010 -62

No files matched your search

+47
View File
@@ -13,6 +13,7 @@ using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.Video;
namespace Assets.Scripts
{
@@ -461,6 +462,52 @@ namespace Assets.Scripts
}
}
}
//下载video
public static IEnumerator DownloadVideo(string fileName,string url, UnityAction<float, UnityWebRequest> onProcessing = null, UnityAction<string> onCompleted = null)
{
string local = "";
var path = PFConstants.VideoFolder;
//根据id读取本地文件
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var filepath= path+$"/{fileName}.mp4";
if (File.Exists(filepath))
{
local = filepath;
}
//本地文件读取不到读取网络文件
else
{
UnityWebRequest request = UnityWebRequest.Get(url);
request.SendWebRequest();
while (!request.isDone)
{
if (onProcessing != null)
{
onProcessing.Invoke(request.downloadProgress, request);
}
yield return new WaitForSeconds(1);
}
if (request.isNetworkError || request.isHttpError)
{
Debug.Log(request.error);
}
else
{
var fs = File.Create(filepath);
fs.Write(request.downloadHandler.data, 0, request.downloadHandler.data.Length);
fs.Close();
local = filepath;
}
}
if (onCompleted != null)
{
onCompleted.Invoke(local);
}
}
static IEnumerator DownloadImage(MaskableGraphic img,string MediaUrl, Action<Texture> action = null,UnityAction<byte[]> callback = null)
{
UnityWebRequest request = UnityWebRequest.Get(MediaUrl);