link downloader

This commit is contained in:
Lillith Rose 2025-10-05 21:17:34 -04:00
parent a8d5ba8ba1
commit 449ee2f194
11 changed files with 146 additions and 0 deletions

View file

@ -0,0 +1,19 @@
{
"name": "LinkDownloaderEditor",
"rootNamespace": "",
"references": [
"GUID:f7a3c1e913875bf4896e48f991fdd5a6",
"GUID:62ced99b048af7f4d8dfe4bed8373d76"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7eb3c7b8f35f15040802ea8b346b1691
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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();
});
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e589545f2ee61974e9d5ee2ac410072a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: