Plugin reference to Unity

Hello all,

I have managed to create a simple plugin for Unity (a C# DLL that I can call from within Unity). Calling this DLL from Unity is no problem, but I also want to call methods from within this plugin to my created code in Unity.

The code that is communicating with the plugin is just a regular class (no MonoBehaviour or other Unity Component) and I really want to give a pointer of that class via an update method to the plugin.

public class ExternalControlModule
{
  public void Init()
  {
    // Start up the DLL
    ExternalControlTest.Test.Start(this);
  }
}

The plugin has the following method:

namespace ExternalControlTest
{
    public class Test
    {
        public static void Start(ExternalControlModule module)
        {
            // TODO: subscribe to events etc.
            module.Subscribe( <info here> );
        }
    }
}

The plugin cannot compile because it doesn't have a reference to the ExternalControlModule.

My question: Is it possible for me to create this external reference one way or the other, so that I have access to the code that I've created in my Unity scripts and classes? If not, what is the best way to get my message across from the plugin to my own Unity scripts or classes?

Thanks in advance!

No, you can't do it the way you're trying

This is however a nice place to use interfaces

In your plugin, add this:

public interface IControlModule
{
    void Subscribe(Whatever stuff);
}

then in your unity code:

public class ExternalControlModule : IControlModule
{
    //other code

    public void Subscribe(Whatever stuff)
    {
        //implementation
    }
}

What you can now do is:

public static void Start(IControlModule module)
{
    module.Subscribe(stuff);
}

Alternatively what you could do is add in a callback, using a delegate of some kind, but I'll spare you the details - plenty of tutorials on using delegates about. In this case, I think the interface is nicer (as it's then standard across all modules)