Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Martijn Hendriks · Feb 15, 2011 at 01:08 PM · pluginreferencecall

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mike 3 · Feb 15, 2011 at 01:38 PM

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)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Martijn Hendriks · Feb 21, 2011 at 11:45 AM 0
Share

Haven't thought of that smart solution. Thank you very much!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to call a function from another script without referencing it? 1 Answer

A node in a childnode? 1 Answer

Android GCM 1 Answer

Does Unity support Playstation Move? 2 Answers

Will Unity 4 Pro student edition allow me to develop applications with 3rd party plugins, specifically the Metaio SDK? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges