Making a moddingAPI for my Unity game and call functions without direct references

Viewed 117

I'm trying to make a moddingAPI for my Unity game, and I stumbled upon a question I can't really find an answer to. Let me explain: I have a specific function in my Unity project, let's name it exampleFunction()

using moddingAPI;
  public class exampleClass : MonoBehaviour
  {
    public static void exampleFunction()
    {
      //stuff
    }
  }

How can I call this function with my moddingAPI, if modders want to call it?

I know that the modder would have to write something like:

using moddingAPI;
  public void callModdingAPI()
  {
    moddingAPI.moddingClass.callExampleFunction();
  }

And the moddingAPI class library would include this:

using ???????;
public class moddingClass : MonoBehaviour
{
  public static void callExampleFunction()
  {
//how do I get the reference to "exampleClass"?
    exampleClass.exampleFunction();
  }
}

⬆ And this part is where my question is. I'm currently creating the moddingAPI with a brand new class library with nothing imported (.NET Framework if it is important). I don't have a direct reference to the exampleClass that is in my Unity game, so this code wouldn't work, and I don't know how to get this reference. Do I have to import something? Do I have to build something? What do I have to do? Thanks in advance.

1 Answers

What you'd need to do is build-release this library as a .DLL file.

Let's assume you released this as 'ModdingApiLib.dll'.

In your unity code, you will have to import this .DLL, and then reference it in your code as:

 public static void main()
  {
    new ModdingApiLib.ExampleFunction();
  }
Related