breakpoint

before update unity version
This commit is contained in:
CortexCore
2024-03-04 18:45:21 +08:00
parent e2fbb14dd5
commit 9ad58a2ff4
5423 changed files with 14757 additions and 653 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using AnotherFileBrowser.Windows;
using BITKit.Mod;
@@ -27,6 +28,8 @@ namespace BITKit.UX
private Label _modNameLabel;
[UXBindPath("mod-description-label")]
private Label _modDescriptionLabel;
[UXBindPath("reload-mod-button",true)]
private Button reloadModButton;
private readonly ConcurrentDictionary<string,UXContainer> _modContainers=new();
@@ -50,6 +53,7 @@ namespace BITKit.UX
{
document.rootVisualElement.SetEnabled(!obj);
}
private void Start()
{
UXUtils.Inject(this);
@@ -57,15 +61,30 @@ namespace BITKit.UX
{
_openModButton.clicked += OpenMod;
}
if (_returnButton is not null)
{
_returnButton.clicked += UXService.Return;
}
_modsContainer.Clear();
foreach (var x in ModService.Mods)
{
OnModInstalled(x);
}
if (reloadModButton is not null)
reloadModButton.clicked += async () =>
{
reloadModButton.SetEnabled(false);
await ModService.Reload();
if (destroyCancellationToken.IsCancellationRequested)
return;
await UniTask.SwitchToMainThread();
if (destroyCancellationToken.IsCancellationRequested)
return;
reloadModButton.SetEnabled(true);
};
}
private async void OnModUnInstalled(IMod obj)
@@ -73,7 +92,7 @@ namespace BITKit.UX
await UniTask.SwitchToMainThread();
if (destroyCancellationToken.IsCancellationRequested) return;
_modContainers.TryRemove(obj.Name, out var container);
container.visualElement.SetEnabled(false);
container.visualElement.RemoveFromHierarchy();
}
private async void OnModInstalled(IMod obj)
@@ -101,26 +120,62 @@ namespace BITKit.UX
private static void OpenMod()
{
BIT4Log.Log("正在打开选择文件对话框");
#if UNITY_EDITOR
new Thread(OpenModInternal).Start();
#else
OpenModInternal();
#endif
return;
void OpenModInternal()
{
BIT4Log.Log<UXModService>("已进入文件对话框线程");
new FileBrowser().OpenFileBrowser(new BrowserProperties()
{
filter = "C Sharp files (*.cs)|*.cs",
//filterIndex = 0,
//filter = "C Sharp files (*.cs)|*.cs |Dll files (*.dll)|*.dll",
}, Filepath);
return;
async void Filepath(string path)
{
BIT4Log.Log<UXModService>("已选择文件:"+path);
await BITApp.SwitchToMainThread();
var file = new FileInfo(path);
switch (file.Extension)
try
{
case ".cs":
var code = await File.ReadAllTextAsync(path);
var assembly = BITSharp.Compile(code);
await ModService.Load(assembly,Path.GetDirectoryName(path));
break;
var file = new FileInfo(path);
switch (file.Extension)
{
case ".cs":
var code = await File.ReadAllTextAsync(path);
var assembly = BITSharp.Compile(code);
await ModService.Load(assembly,Path.GetDirectoryName(path));
break;
case ".dll":
var bytes = await File.ReadAllBytesAsync(path);
await ModService.Load(Assembly.Load(bytes),Path.GetDirectoryName(path));
break;
case ".json" when file.Name is ModPackage.DefaultFileName:
await ModService.LoadFromPackage(path);
break;
default:
Alert.Print(new AlertMessage()
{
title = "加载失败",
message = "不支持的文件类型"
});
break;
}
}
catch (Exception e)
{
Alert.Print(new AlertMessage()
{
title = "加载失败",
message = e.Message
});
BIT4Log.LogException(e);
}
}
}