1
This commit is contained in:
70
Unity/Scripts/Tests/WebDavTester.cs
Normal file
70
Unity/Scripts/Tests/WebDavTester.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using WebDav;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
using BITKit.IO;
|
||||
using BITKit.Web;
|
||||
using System;
|
||||
using System.IO;
|
||||
namespace BITKit
|
||||
{
|
||||
public class WebDavTester : MonoBehaviour
|
||||
{
|
||||
public string baseUrl;
|
||||
public string filePath;
|
||||
public async void GetFile()
|
||||
{
|
||||
WebDavStorageProvider provider = new();
|
||||
provider.requestUrl = baseUrl;
|
||||
var file = await provider.GetFile(filePath);
|
||||
Debug.Log(await file.GetTextAsync());
|
||||
}
|
||||
public async void DownloadFile()
|
||||
{
|
||||
WebDavStorageProvider provider = new();
|
||||
provider.requestUrl = baseUrl;
|
||||
Debug.Log("正在连接");
|
||||
var file = await provider.GetFile(filePath);
|
||||
using (var fs = File.Create(PathHelper.GetTempFilePath()))
|
||||
{
|
||||
Debug.Log("正在创建ReaderStream");
|
||||
var stream = await file.OpenReadAsync();
|
||||
Debug.Log("已创建ReaderStream");
|
||||
await stream.CopyToAsync(fs);
|
||||
Debug.Log("已写入FileStream");
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
[CustomEditor(typeof(WebDavTester))]
|
||||
public class WebDavTesterInspector : Editor
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
VisualElement root = new();
|
||||
WebDavTester tester = serializedObject.targetObject as WebDavTester;
|
||||
|
||||
Button button = new();
|
||||
Button downloadButton = new();
|
||||
PropertyField baseUrl =
|
||||
new(serializedObject.FindProperty(nameof(WebDavTester.baseUrl)));
|
||||
PropertyField filePath =
|
||||
new(serializedObject.FindProperty(nameof(WebDavTester.filePath)));
|
||||
|
||||
button.clicked += tester.GetFile;
|
||||
button.text = nameof(WebDavTester.GetFile);
|
||||
|
||||
downloadButton.clicked += tester.DownloadFile;
|
||||
downloadButton.text = nameof(WebDavTester.DownloadFile);
|
||||
|
||||
root.Add(baseUrl);
|
||||
root.Add(filePath);
|
||||
root.Add(button);
|
||||
root.Add(downloadButton);
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user