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
2
Question by user-2241 (yahoo) · Sep 10, 2010 at 02:41 AM · iphonexcodeapidevelopment

API integration for Unity

I have been doing a lot of research into iPhone development and have seen the light of APIs. I would like to use Xcode for the APIs but I want to use Unity for the engine. Is there a way I can integrate the APIs (like CoreMotion) into Unity so it compiles altogether so I don't have to worry about everything working together? Or are there unity APIs that do the same thing?

I am a beginning developer and need help. Links are great but explanations on how to integrate are better.

Thank you 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
4
Best Answer

Answer by jashan · Sep 10, 2010 at 04:51 AM

Sure, Unity iPhone Advanced 1.7 supports "plugins" and Unity iPhone 3.0 will also support plugins (in other words, starting with 3.0 you will no longer need Unity iPhone Advanced in order to be able to use that feature).

There's a related question and answer: Specific steps to set up a plugin for iphone in XCode

There's also a couple of vendors that sell Plugins that make it very easy to access many of the iOS features that are not directly supported by Unity. One example would be: Unity 3 iPhone Plugins - Native Made Easy. As these come with full source code, they might also be a good starting point to learn the trade ;-)

EDIT: How to connect Unity scripts with plugins ... it's in the documentation but I only have a local link which wouldn't work for you, so I'm duplicating some of the information here (EDIT2: That documentation is now available online: Unity Manual > Advanced > Plugins - Pro/Mobile-Only Feature, thanks to ForceMagic for the note):

Define your extern method like:

[DllImport ("__Internal")] private static extern float FooPluginFunction();

  • Hit build in Unity iPhone

  • Add your native implementation to the generated XCode project's "Classes" folder (this folder is not overwritten when project is updated, but don't forget to backup your native code).
  • If you are using C++ (.cpp) or Objective-C (.mm) to implement the plugin you have to make sure the functions are declared with C linkage to avoid name mangling issues.

    extern "C" {
      float FooPluginFunction();
    } 
    

    Using your plugin from C#

    iPhone native plugins can be called only when deployed on the actual device, so it is recommended to wrap all native code methods with an additional C# code layer. This code could check Application.platform and call native methods only when running on the actual device and return mockup values when running in the Editor. Check the Bonjour browser sample application.

    Calling C# / JavaScript back from native code Unity iPhone supports limited native->managed callback functionality via UnitySendMessage:

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

    This function has three parameters : game object name, game object script method to call, message to pass to the called method. Limitations to know:

    only script methods that correspond to the following signature can be called from native code :

    function MethodName(message:string)
    

    calls to UnitySendMessage are asynchronous and have a one frame delay.

    Comment
    Add comment · Show 6 · 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 user-2241 (yahoo) · Sep 10, 2010 at 04:07 PM 0
    Share

    Thanks Jashan! Those are very helpful links. The next thing that is holding me back is this. I can put these plugins into unity but how do I connect them to the object on the screen? Like for instance I add in accelerometer support but how do I connect it to lets say hit a drum?

    avatar image jashan · Sep 11, 2010 at 12:43 PM 0
    Share

    Well, with accelerometer support it might be a little tricky because for "hitting a drum", you may want to do some fancy calculations from the data you get from the accelerometer to figure out the user shook the device so that the drum should be hit. That's not trivial. But connecting the two technically is not that hard; I'll add something about this to my original answer ...

    avatar image user-2241 (yahoo) · Sep 15, 2010 at 07:21 PM 0
    Share

    I'm going to experiment with this for a while. Hopefully it works. But I'll try to get back to you with results!

    avatar image ForceMagic_Legacy · Nov 22, 2010 at 07:09 PM 0
    Share

    Well, no offense but linking the original page would have been faster. There is no new content on that awnser anyway, except for the related question and awnser.

    http://unity3d.com/support/documentation/$$anonymous$$anual/Plugins.html

    avatar image jashan · Nov 29, 2010 at 10:06 AM 0
    Share

    At the time when I posted the answer, that part of the documentation wasn't in the public documentation, yet - that's why I copied the contents here. See also my remark in the beginning of the quote: "it's in the documentation but I only have a local link which wouldn't work for you, so I'm duplicating some of the information here". Had it been available in the public documentation back then, I would have posted just the link, of course (that was during the Unity 3 beta, with the NDA lifted ;-) ). But thanks for the heads up - I've added the link now that it is available.

    Show more comments

    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

    1 Person is following this question.

    avatar image

    Related Questions

    iOS Title Rejected due to Apple Music API Inclusion 1 Answer

    Xcode error dyld: symbol not found: _glbeginquery 0 Answers

    unable to download & load particular scene in iPhone Project 2 Answers

    iPhone StoreKit implementation problem 2 Answers

    I need the pro version to call my own objective C libraries from Unity ? 2 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