Magicono just recently helped me set up a new mod, and I thought I would put the process here, as I couldn't find a complete tutorial anywhere.
First, let's give a quick overview of the process. The bulk of creating a mod is editing the game files in the Daggerfall Unity repository locally (as if you're making a new version of Daggerfall Unity) in the Unity editor. You can run and test your mod in this state as if it was its own Daggerfall Unity standalone. When you're ready to release a build, you tell the provided mod builder which files you added or edited for your mod. The mod builder then handles the building of your .dfmod file, and voila.
First, you're going to want to download the Daggerfall Unity repository here
https://github.com/Interkarma/daggerfall-unity. You're also going to want to download and install Unity 2019.4.28f1 (yes the version does matter), which you can find here
https://download.unity3d.com/download_u ... 4.28f1.exe for Windows or here
https://download.unity3d.com/download_u ... 4.28f1.dmg for Mac. Don't be daunted if you've never used Unity; Unity is laid out in a very intuitive manner, and modding Daggerfall Unity is a great way to learn how to use. Just stick with it and you'll get it in no time.
Open the Daggerfall Unity project (that you just downloaded from Github) in Unity. Behold; the whole of the Daggerfall Unity project is before you, in all its open-source glory. But before you jump in, let's set up your mod, using the standard conventions. In the project window, go to Assets>Game>Mods, and make a new folder here with the name of your mod. So the hierarchy should look like Assets>Game>Mods>[ModName]. Inside your new mod folder, make two new folders called "Prefabs" and "Scripts." Now, inside your "Scripts" folder, create a new script called "[ModName]Main". Inside "[ModName]Main", paste the following code:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Utility.ModSupport;
using DaggerfallWorkshop.Game.Utility;
using DaggerfallConnect;
namespace ModName
{
public class ModNameMain : MonoBehaviour
{
static ModNameMain instance;
public static ModNameMain Instance
{
get { return instance ?? (instance = FindObjectOfType<ModNameMain>()); }
}
static Mod mod;
[Invoke(StateManager.StateTypes.Start, 0)]
public static void Init(InitParams initParams)
{
mod = initParams.Mod;
instance = new GameObject("ModName").AddComponent<ModNameMain>(); // Add script to the scene.
mod.IsReady = true;
}
private void Start()
{
Debug.Log("Begin mod init: ModName");
// Initialize your mod here. Usually that means instantiating a GameObject
Debug.Log("Finished mod init: ModName");
}
}
}
Obviously, switch out "ModName" for the name of your mod whenever it occurs in this file. Once you save "[ModName]Main," add it as a component to the "DaggerfallUnity" prefab located at Assets>Prefabs.
"[ModName]Main" will be your mod's "entry" into the game. The "DaggerfallUnity" prefab is instantiated once the game starts, and anything you put in "[ModName]Main" will run right after.
Now you're ready to start modding. Edit and add any prefabs, GameObjects and scripts you desire. I recommend that you place any new prefabs or scripts you create into their respective folder in Assets>Game>Mods>[ModName]. Take note of which files you added or changed, as this will be important later.
To test your mod, open either "DaggerfallUnityGame" or "DaggerfallUnityStartup" in Assets>Scenes. You can simply run the game from either of these scenes, and your mod will be automatically loaded.
To release your mod, you will need to build a .dfmod file. Fortunately, the Daggerfall Tools will do this for you. Click on "Daggerfall Tools" on the Unity toolbar and click on "Mod Builder." Then, click the button "Create New Mod." You will be prompted to create a .dfmod.json file. Save this file as "[ModName].dfmod.json" in your Assets>Game>Mods>[ModName] folder. Then, use the button "Add Selected Asset(s)" to add the files your mod adds or changes. Finish filling out the rest of the relevant information, click "Save Mod Settings to File," and then click "Build Mod." There is no strict convention on where to build your mod files to.
Once your .dfmod file is built, you can drag it to your mods folder in your local Daggerfall Unity game files.
This should enough to get your started on building your own mod. If you think I should change or add anything, please let me know.