70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
![]() |
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;
|
||
|
}
|
||
|
}
|
||
|
}
|