1
This commit is contained in:
@@ -11,6 +11,7 @@ using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BITKit.IO;
|
||||
using BITKit.UX;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Microsoft.CSharp;
|
||||
using Newtonsoft.Json;
|
||||
@@ -129,6 +130,10 @@ namespace BITKit.Mod
|
||||
{
|
||||
public static async UniTask<ModPackage[]> SearchPackages()
|
||||
{
|
||||
DI.TryGet<IUXWaiting>(out var waiting);
|
||||
var handle = waiting?.Get();
|
||||
handle?.SetMessage("正在搜索Mod包");
|
||||
|
||||
var list=new List<ModPackage>();
|
||||
var path = Path.Combine(Environment.CurrentDirectory, "Mods");
|
||||
var dir = new DirectoryInfo(path);
|
||||
@@ -142,10 +147,13 @@ namespace BITKit.Mod
|
||||
package.WorkDirectory = x.FullName;
|
||||
list.Add(package);
|
||||
}
|
||||
|
||||
waiting?.Release(handle);
|
||||
return list.ToArray();
|
||||
}
|
||||
public static async UniTask Reload()
|
||||
{
|
||||
OnReload?.Invoke();
|
||||
var mods = Mods;
|
||||
foreach (var x in Mods)
|
||||
{
|
||||
@@ -170,6 +178,7 @@ namespace BITKit.Mod
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
}
|
||||
OnReloaded?.Invoke();
|
||||
}
|
||||
|
||||
public static IMod[] Mods { get; private set; }=Array.Empty<IMod>();
|
||||
@@ -194,6 +203,9 @@ namespace BITKit.Mod
|
||||
public static event Action<IMod> OnModUnLoaded;
|
||||
public static event Action<IMod> OnModInstalled;
|
||||
public static event Action<IMod> OnModUnInstalled;
|
||||
|
||||
public static event Action OnReload;
|
||||
public static event Action OnReloaded;
|
||||
|
||||
public static event Action<bool> OnLocked;
|
||||
|
||||
@@ -266,37 +278,20 @@ namespace BITKit.Mod
|
||||
|
||||
while (_IsRunning)
|
||||
{
|
||||
DI.TryGet<IUXWaiting>(out var waiting);
|
||||
|
||||
_CacheMods.Clear();
|
||||
while (_RegisterQueue.TryDequeue(out var mod))
|
||||
{
|
||||
_CacheMods.Add(mod);
|
||||
mod.OnInitialize();
|
||||
OnModLoad?.Invoke(mod);
|
||||
BIT4Log.Log<ModService>($"加载Mod:{mod.GetType().FullName}");
|
||||
}
|
||||
|
||||
foreach (var mod in _CacheMods)
|
||||
{
|
||||
await mod.OnInitializedAsync(_CancellationTokenSource.Token);
|
||||
foreach (var x in OnModLoadAsync.CastAsFunc())
|
||||
{
|
||||
await x.Invoke(mod);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var mod in _CacheMods)
|
||||
{
|
||||
mod.OnInitialized();
|
||||
OnModLoaded?.Invoke(mod);
|
||||
}
|
||||
|
||||
_CacheMods.Clear();
|
||||
|
||||
|
||||
while (_UnRegisterQueue.TryDequeue(out var mod))
|
||||
{
|
||||
var handle = waiting?.Get();
|
||||
handle?.SetMessage($":正在卸载{mod.PackageName}");
|
||||
|
||||
mod.OnDispose();
|
||||
_CacheMods.Add(mod);
|
||||
OnModUnLoad?.Invoke(mod);
|
||||
|
||||
waiting?.Release(handle);
|
||||
}
|
||||
|
||||
foreach (var mod in _CacheMods)
|
||||
@@ -314,6 +309,51 @@ namespace BITKit.Mod
|
||||
OnModUnLoaded?.Invoke(mod);
|
||||
BIT4Log.Log<ModService>($"卸载Mod:{mod.GetType().FullName}");
|
||||
}
|
||||
|
||||
_CacheMods.Clear();
|
||||
|
||||
while (_RegisterQueue.TryDequeue(out var mod))
|
||||
{
|
||||
var handle = waiting?.Get();
|
||||
|
||||
handle?.SetMessage($"正在加载:{mod.PackageName}");
|
||||
|
||||
_CacheMods.Add(mod);
|
||||
mod.OnInitialize();
|
||||
OnModLoad?.Invoke(mod);
|
||||
BIT4Log.Log<ModService>($"加载Mod:{mod.GetType().FullName}");
|
||||
|
||||
waiting?.Release(handle);
|
||||
}
|
||||
|
||||
foreach (var mod in _CacheMods)
|
||||
{
|
||||
var handle = waiting?.Get();
|
||||
handle?.SetMessage($"正在初始化:{mod.PackageName}");
|
||||
|
||||
await mod.OnInitializedAsync(_CancellationTokenSource.Token);
|
||||
foreach (var x in OnModLoadAsync.CastAsFunc())
|
||||
{
|
||||
await x.Invoke(mod);
|
||||
}
|
||||
|
||||
waiting?.Release(handle);
|
||||
}
|
||||
|
||||
foreach (var mod in _CacheMods)
|
||||
{
|
||||
var handle = waiting?.Get();
|
||||
handle?.SetMessage($":正在完成初始化中{mod.PackageName}");
|
||||
|
||||
mod.OnInitialized();
|
||||
OnModLoaded?.Invoke(mod);
|
||||
|
||||
waiting?.Release(handle);
|
||||
}
|
||||
|
||||
_CacheMods.Clear();
|
||||
|
||||
|
||||
//Thread.Sleep(1000);
|
||||
#if UNITY_64
|
||||
await UniTask.Delay(1000);
|
||||
|
Reference in New Issue
Block a user