ModelSwapLib
A modding library intending to make asset swap mod development slightly easier.
模組介紹 作者原文
Model Swap Lib
Model Swap Lib is an abstraction originally based on this Asset Swap Template for the game Jump Space.
This library is intended for use by mod developers and will have no effect if installed alone.
Usage Steps:
- Add ModelSwapLib.dll as a project reference
- Include [assembly: MelonAdditionalDependencies("ModelSwapLib")] in your core file
- Instantiate a swapper using one of the options below
- Register your swapper with ObjectActionManager.GetInstance().RegisterSwapper(swapper); - This will return a populated Guid if this succeeded, or a Guid.Empty if ModelSwapLib was unable to validate the Swapper structure
There are 2 ways to create a swapper:
Option 1 - Builder Pattern:
Swapper swapper = new SwapperBuilder("Optional ModName").SetModName("YourModName").SetSwapperName("Any Name You Want").SetBundleName("YourBundle.bundle").AddObjectName("ObjectName").AddAssetModule(new MeshModule("Path/To/Your/Model.fbx")).AddAssetModule(new Texture2DModule("Path/To/Your/Texture.png")).AddTransformModule(new MoveMeshModule(0f, 0f, 0f)).AddTransformModule(new RotateMeshModule(0f, 0f, 0f)).AddTransformModule(new ScaleMeshModule(0f, 0f, 0f)).AddDeactivation("ObjectYouWantDeactivated").Build();
new Swapper() - The string parameter for ModName is optional here but is required at some point
SetModName(string) - ModName is a required parameter for a Swapper
SetSwapperName(string) - SwapperName is not required and will default to "Unnamed Swapper", this is mainly for logging
SetBundleName(string) - BundleName is only required if you use an IAssetModule
AddObjectName(string) - Swapper must contain at least 1 object name, otherwise it will not apply to anything and will be rejected
AddAssetModule(IAssetModule) - List of modules that use an asset from a provided AssetBundle
AddTransformModule(ITransformModule) - List of modules that manipulate the transform of a mesh
AddDeactivation(string) - List of object names to be deactivated
Additional methods include:
- AddObjectNames(List<string>)
- AddAssetModules(List<IAssetModule>)
- AddTransformModules(List<ITransformModule>)
- AddDeactivations(List<string>)
Build() - Returns the swapper object, or null if the configuration is not valid
Option 2 - Manual creation:
Swapper swapper = new Swapper
{
ModName = "YourModName",
SwapperName = "Any Name You Want",
ObjectNames = new List([
"ObjectName1",
"ObjectName2"
]),
BundleName = "YourBundle.bundle",
AssetModules = new List
{
new MeshModule("Path/To/Your/Model.fbx"),
new Texture2DModule("Path/To/Your/Texture.png")
},
TransformModules = new List
{
new MoveMeshModule(0f, 0f, 0f),
new RotateMeshModule(0f, 0f, 0f),
new ScaleMeshModule(0f, 0f, 0f)
},
Deactivations = new List
{
"ObjectYouWantDeactivated"
}
};
Full Implementation Template
[assembly: MelonAdditionalDependencies("ModelSwapLib")]
namespace YourMod
{
public class Core: MelonMod
{
public override void OnInitializeMelon()
{
Swapper swapper = new SwapperBuilder().SetModName("YourModName").SetSwapperName("Any Name You Want").AddObjectNames(["ObjectName1", "ObjectName2"]).SetBundleName("YourBundle.bundle").AddAssetModule(new MeshModule("Path/To/Your/Model.fbx")).AddAssetModule(new Texture2DModule("Path/To/Your/Texture.png")).AddTransformModule(new MoveMeshModule(0f, 0f, 0f)).AddTransformModule(new RotateMeshModule(0f, 0f, 0f)).AddTransformModule(new ScaleMeshModule(0f, 0f, 0f)).AddDeactivation("ObjectYouWantDeactivated").Build();
if(swapper == null)
{
Melon.Logger.Warning($"Invalid swapper");
}else{
Guid guid = ObjectActionManager.GetInstance().RegisterSwapper(swapper);
if(guid == Guid.Empty) // If you receive a Guid.Empty then the Swapper.Validate() failed
{
Melon.Logger.Warning($"Failed to register swapper: {swapper.SwapperName}");
} else
{
Melon.Logger.Msg($"Successfully registered swapper: {swapper.SwapperName} with guid: {swapper.SwapperGuid}");
}
}
Melon.Logg
安裝與使用 安裝:按包內說明操作
- 解壓本站下載的壓縮包,先讀包內的 readme / 說明檔案。
- 多數模組依賴遊戲的模組載入器:常見做法是用社群模組管理器(如 r2modman)選中本遊戲安裝,由管理器自動處理載入器與依賴。
- 手動安裝時,把模組檔案放進遊戲目錄下對應的 Mod / plugins 資料夾。
- 啟動遊戲確認載入成功;帶「前置依賴」的模組需要把依賴一併安裝。
不同模組的安裝位置差異較大,包內說明是最可靠的依據。
下面這些內容需要先安裝,否則該模組不會生效: