link downloader
This commit is contained in:
parent
a8d5ba8ba1
commit
449ee2f194
11 changed files with 146 additions and 0 deletions
41
LinkDownloader/Editor/LinkDownloaderPlugin.cs
Normal file
41
LinkDownloader/Editor/LinkDownloaderPlugin.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using gay.lilyy.LinkDownloader;
|
||||
using nadena.dev.ndmf;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[assembly: ExportsPlugin(typeof(LinkDownloaderPlugin))]
|
||||
|
||||
namespace gay.lilyy.LinkDownloader
|
||||
{
|
||||
public class LinkDownloaderPlugin : Plugin<LinkDownloaderPlugin>
|
||||
{
|
||||
public override string DisplayName => "LinkDownloader";
|
||||
public override string QualifiedName => "gay.lilyy.LinkDownloader";
|
||||
|
||||
protected override void Configure()
|
||||
{
|
||||
InPhase(BuildPhase.Transforming).Run("LinkDownloader", async ctx =>
|
||||
{
|
||||
var links = ctx.AvatarRootObject.GetComponentsInChildren<LinkDownloaderConfig>();
|
||||
if (links.Length == 0) return;
|
||||
using var http = new HttpClient();
|
||||
foreach (var link in links) {
|
||||
try
|
||||
{
|
||||
Debug.Log($"Downloading {link.link} to {link.path}");
|
||||
var data = await http.GetByteArrayAsync(link.link);
|
||||
File.WriteAllBytes(link.path, data);
|
||||
Debug.Log($"Link saved to: {link.path}");
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Debug.LogError($"Failed to download link: {ex.Message}");
|
||||
}
|
||||
}
|
||||
AssetDatabase.Refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue