Support for virtual mods
See original GitHub issueSome time ago @Nystul-the-Magician raised the need to simplify mod testing and use debuggers during mod development and came up with this solution:
/*
* used for debugging
* howto debug:
* -) add a dummy GameObject to DaggerfallUnityGame scene
* -) attach this script (_startupMod) as component
* -) deactivate mod in mod list (since dummy gameobject will start up mod)
* -) attach debugger and set breakpoint to one of the mod's cs files and debug
*/
void Awake()
{
initMod();
}
The issue is that mod functionalities like settings, loading resources or localization are not functional during debug. So i decided to further develop the idea with a concept of “virtual mod”, which relies on a folder inside Assets/Game/Mods
instead of an assetbundle when running inside the Editor. This is a pratical example:
public class Test : MonoBehaviour
{
static Mod mod;
[Invoke(StateManager.StateTypes.Start)]
private void Init(InitParams initParams)
{
mod = initParams.Mod;
var go = new GameObject(mod.Title);
go.AddComponent<Test>();
}
private void Awake()
{
#if UNITY_EDITOR
if (mod == null)
mod = new Mod("Test/Test.dfmod.json");
#endif
mod.IsReady = true;
}
private void Start()
{
var settings = mod.GetSettings();
int number = settings.GetValue<int>("Configuration", "Number");
var texture = mod.GetAsset<Texture2D>("Example_Tex");
var shader = mod.GetAsset<Shader>("NewUnlitShader");
var material = mod.GetAsset<Material>("Example_Material");
}
}
All the code is shared for both testing and releases because the Mod class instance handles loading assets from assetbundle, if running from a released mod, or Assets/Game/Mods/Test/Resources/
if running from a virtual debug mod environment. Ideally, this means you can write and test a mod with the same comfort of writing core code, and only build an assetbundle for release.
I published this to a separate branch for testing and get some opinions 😃
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
will have to test this out the next time I touch my mods 😉
hi all, I finally got around to testing how this works, and can confirm that I have it working now. It is quite slick, just drop the mod builder dfmod.json file into assets\game\mods and the mod shows up in mods. Nicely Done!! I can now debug my mod scripts!
thanks again for the very fast responses. A