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 Daiyunchao · Dec 21, 2012 at 09:46 PM · macforbundle

unity plugins for mac,the bundle file how to callback the c#?

i build a plugins bundle for mac ,but i don't know how to callback c#? anyone know? thank you

Comment
Add comment · Show 5
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 Graham-Dunnett ♦♦ · Dec 23, 2012 at 10:07 PM 0
Share

c# calls into your bundle, not the other way round.

avatar image Daiyunchao · Dec 24, 2012 at 01:08 AM 0
Share

yes i know,like this:

[DllImport ("PluginName")]

private static extern float FooPluginFunction ();

c# calls into your bundle,it can work,but i want the code in the bundle can callback my c# code. how it do?

avatar image Graham-Dunnett ♦♦ · Dec 24, 2012 at 05:31 PM 0
Share

It can't. Communication goes the other way.

avatar image $$anonymous$$ · Dec 25, 2012 at 04:26 PM 0
Share

@Graham Dunnett: This is false, Unity does have official callback functionality.

avatar image Hola Soy Edu Feliz Navidad · Sep 13, 2014 at 09:18 AM 0
Share

The answer you shown is only for $$anonymous$$obile, desktop plugins doesn´t have this functionality. The only way on desktop you can do is creating a pool on the navitive code and call it frequently.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by $$anonymous$$ · Dec 25, 2012 at 04:24 PM

I've been working with building plugins to Unity using Objective-C (To access parts of the Cocoa Touch framework which Unity does not have any prebuild solution to, such as the StoreKit framework for in app purchases).

If I understand your problem correctly, you wish to make some sort of call from Objective-C code (or C or C++) back into Unity? Preferably to some script attached to an object in the game, which is in most cases the only possible way.

If you have a look at the official Unity documentation for building plugins: Building plugins for iOS

You will see that they mention one official way of calling back to a script in Unity from native code, which is this function:

 UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");

This is, as far as I've ever found, the only official native-to-managed callback functionality which Unity supports. But from my experiences it is all you will ever need. It is also very easy to use.

This is the function you will call from your native code such as Objective-C, C, or C++, etc. The first parameter specifies the game object which contains a method you want to call from one of its attached scripts. The second parameter specifies the name of the method, and the last one is the parameter you want to give to the method.

This also means that any method in your Unity C# scripts you want to use as callback methods need a signature which is:

 void (string)

That is, they must not return anything and they only have one parameter, namely of the type string.

But the documentation from the provided link covers all of this :)

Hope this helps!

Comment
Add comment · 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

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity fails to include .bundle for native code plugin when building Intel Mac player. 0 Answers

Does Unity 5 support OSX i386 plugins (without x86_64)? 0 Answers

Why doesn't my bundle build for Mac OS X using Xcode 4.5? 1 Answer

What to choose to make .bundle plugin in XCode? 1 Answer

In-app purchase "Invalid product" on Mac Store build 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