This commit is contained in:
CortexCore
2024-06-14 14:11:28 +08:00
parent 4a2ab82e20
commit 349877fe7a
10 changed files with 28 additions and 12 deletions

View File

@@ -8,7 +8,7 @@ using UnityEngine.UIElements;
namespace BITKit.UX
{
#if !UNITY_WEBGL
#if UNITY_64
public class UXApplicationFile : MonoBehaviour
{
[SerializeReference, SubclassSelector] private IApplicationFile applicationFile;

View File

@@ -5,7 +5,9 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
#if UNITY_64
using AnotherFileBrowser.Windows;
#endif
using BITKit.Mod;
using Cysharp.Threading.Tasks;
using UnityEngine;
@@ -141,12 +143,16 @@ namespace BITKit.UX
return;
void OpenModInternal()
{
#if UNITY_64
BIT4Log.Log<UXModService>("已进入文件对话框线程");
new FileBrowser().OpenFileBrowser(new BrowserProperties()
{
//filterIndex = 0,
//filter = "C Sharp files (*.cs)|*.cs |Dll files (*.dll)|*.dll",
}, Filepath);
#else
throw new NotSupportedException($"{Application.platform} 不支持打开文件对话框");
#endif
return;
async void Filepath(string path)
{
@@ -159,9 +165,13 @@ namespace BITKit.UX
switch (file.Extension)
{
case ".cs":
#if UNITY_64
var code = await File.ReadAllTextAsync(path);
var assembly = BITSharp.Compile(code);
await ModService.Load(assembly,Path.GetDirectoryName(path));
#else
throw new NotSupportedException($"{Application.platform} 不支持编译C#代码");
#endif
break;
case ".dll":
var bytes = await File.ReadAllBytesAsync(path);