Async load mod, Assassin_WoundDeterioration(unfinished)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Continentis.MainGame;
|
||||
using Continentis.MainGame.Card;
|
||||
using Continentis.MainGame.Character;
|
||||
@@ -10,12 +11,19 @@ using I2.Loc;
|
||||
using SLSFramework.General;
|
||||
using UMod;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace SLSFramework.UModAssistance
|
||||
{
|
||||
public partial class ModBrowser : MonoBehaviour
|
||||
{
|
||||
#region Inspector
|
||||
public UnityEvent OnModLoadBegin;
|
||||
public UnityEvent OnModLoadEnd;
|
||||
#endregion
|
||||
|
||||
|
||||
// Public
|
||||
public bool persistent = true;
|
||||
public Button loadButton;
|
||||
@@ -23,7 +31,7 @@ namespace SLSFramework.UModAssistance
|
||||
public GameObject modLoadTabPrefab;
|
||||
public List<ModLoadTab> modTabs = new List<ModLoadTab>();
|
||||
public List<IModInfo> selectedMods = new List<IModInfo>();
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
@@ -34,25 +42,26 @@ namespace SLSFramework.UModAssistance
|
||||
loadButton.onClick.AddListener(OnLoadClicked);
|
||||
GenerateUIList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class ModBrowser
|
||||
{
|
||||
private void OnLoadClicked()
|
||||
private async void OnLoadClicked()
|
||||
{
|
||||
OnModLoadBegin?.Invoke();
|
||||
GetAllSelectedMods();
|
||||
|
||||
foreach (IModInfo mod in selectedMods)
|
||||
{
|
||||
ModHost host = ModManager.LoadMod(mod);
|
||||
ModHost host = await ModManager.LoadAsync(mod);
|
||||
ModManager.RegisterTypesFromMod(host, typeof(RulesCollectionBase));
|
||||
ModManager.RegisterTypesFromMod(host, typeof(CharacterBase));
|
||||
ModManager.RegisterTypesFromMod(host, typeof(CardLogicBase));
|
||||
ModManager.RegisterTypesFromMod(host, typeof(EquipmentBase));
|
||||
ModManager.RegisterTypesFromMod(host,typeof(CardCombatBuffBase));
|
||||
ModManager.RegisterTypesFromMod(host,typeof(CharacterCombatBuffBase));
|
||||
|
||||
|
||||
ModManager.RegisterTypesFromMod(host, typeof(CardCombatBuffBase));
|
||||
ModManager.RegisterTypesFromMod(host, typeof(CharacterCombatBuffBase));
|
||||
|
||||
|
||||
string manifestName = host.CurrentMod.NameInfo.ModName + "_Manifest";
|
||||
ModManifest manifest = host.Assets.Load<ModManifest>(manifestName);
|
||||
manifest.SaveToDatabase(host);
|
||||
@@ -65,10 +74,11 @@ namespace SLSFramework.UModAssistance
|
||||
LocalizationManager.AddSource(sourceData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LocalizationManager.LocalizeAll();
|
||||
OnModLoadEnd?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
private void GenerateUIList()
|
||||
{
|
||||
// Destroy all cells
|
||||
@@ -80,14 +90,14 @@ namespace SLSFramework.UModAssistance
|
||||
CreateUICell(info, modButtonContainer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void CreateUICell(IModInfo mod, RectTransform container)
|
||||
{
|
||||
ModLoadTab modTab = Instantiate(modLoadTabPrefab, container).GetComponent<ModLoadTab>();
|
||||
modTab.Initialize(mod);
|
||||
modTabs.Add(modTab);
|
||||
}
|
||||
|
||||
|
||||
private void GetAllSelectedMods()
|
||||
{
|
||||
selectedMods = modTabs.FindAll(t => t.isSelected).ConvertAll(t => t.modInfo);
|
||||
|
||||
@@ -3,10 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using SLSFramework.General;
|
||||
using UMod;
|
||||
using UMod.Scripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.ResourceManagement.Exceptions;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace SLSFramework.UModAssistance
|
||||
@@ -21,6 +23,23 @@ namespace SLSFramework.UModAssistance
|
||||
Debug.Log($"Mod '{modName}' loaded successfully.");
|
||||
return host;
|
||||
}
|
||||
|
||||
public static async Task<ModHost> LoadAsync(IModInfo modInfo)
|
||||
{
|
||||
string modName = modInfo.NameInfo.ModName;
|
||||
var host = Mod.LoadAsync(Mod.DefaultDirectory.GetModPath(modName));
|
||||
while (!host.IsDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
if (!host.IsSuccessful)
|
||||
{
|
||||
throw new OperationException($"Failed to load mod '{modName}'");
|
||||
}
|
||||
LoadedMods.Add(modName, host.Result);
|
||||
Debug.Log($"Mod '{modName}' async loaded successfully.");
|
||||
return host.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class ModManager
|
||||
|
||||
Reference in New Issue
Block a user