Unity Asset Ios Native V7.1
Category List
Threads | Latest Post | |
Expand for more options. Xamarin.FormsDiscussions about building iOS and Android apps from one shared codebase using Xamarin.Forms. | 169.7K | |
Expand for more options. Xamarin.iOSDiscussions about building iOS, tvOS, and watchOS apps with Xamarin.iOS | 53.7K | |
Expand for more options. Xamarin.AndroidDiscussions about building Android apps with Xamarin.Android | 67.7K | |
Expand for more options. Xamarin.MacDiscussions about specifically building macOS apps with Xamarin.Mac | 359 | |
Expand for more options. Cross Platform with XamarinDiscussions that apply to the development of multiple platforms with Xamarin. | 15K | |
Expand for more options. Xamarin University For the Xamarin University community, students and professors alike. | 1.5K | |
Expand for more options. Xamarin Test Cloud (Read Only)Discussions about Xamarin Test Cloud, Calabash, and Xamarin.UITest | 3.3K | Xamarin Test Cloud Forum is now read-only GlennWester.4818•in Xamarin Test Cloud (Read Only) |
The new Ultimate Mobile Pro, is a bundle of Stan's Assets best mobile native pro-line plugins wrapped with powerful unified API. Plugin provides simplified cross-platform API for most popular native services. The goal for this product is to be the best native cross-platform solution available for Unity. I have a very tiny Objective-C library built for iOS and I want to export it to Unity. I understand the basic process of writing a csharp wrapper that marshals all the invocations to native library, but I completely have no idea where to start. Getting started with iOS development. Unity allows you to call custom native functions written in C, C++ or Objective-C directly from C# scripts A piece of code that allows you to create your own Components. Tutorials Community Answers Knowledge Base Forums Asset Store.
I have a very tiny Objective-C library built for iOS and I want to export it to Unity. I understand the basic process of writing a csharp wrapper that marshals all the invocations to native library, but I completely have no idea where to start. Could anyone please explain step-by-step how to create a unity package with my library so I could also distribute it to other developers.
Unity3d documentation is pretty brief and does not explain anything.
Thanks.
2 Answers
Okay, after playing few days with Unity3d on Mac I finally figured it out. All the code in this guide is dummy. I have written this stuff in 15 minutes or so, so don't be bothered by mistakes and typos.
1) Open Unity, create new project (File -> New Project) and save it somewhere
2) When the project is generated it has the following structure:
ProjectName/Assets
(That's what you need)ProjectName/Library
(Nevermind what's there)ProjectName/ProjectSettings
(You don't care about it)ProjectName/ProjectName.sln
(MonoDevelop project)
3) Go to ProjectName/Assets
and create the following folders: Plugins/iOS
, so in the end you'll have a folder structure like this: ProjectName/Assets/Plugins/iOS
4) Put your compiled library (.a) file and necessary headers inside of ProjectName/Assets/Plugins/iOS
or copy the source code of your library there (.mm, .h, .m, etc.). Remember, normally you can only access C-functions from C#, so you'll have to wrap your Objective-C stuff in C-code somehow, in my case all Objective-C objects were implemented in a form of Singleton so it wasn't hard to make a C-style wrapper around, for instance:
CWrapper.h:
CWrapper.mm
Test Drive Unlimited 2 transforms the driving genre, adding the persistency, progression and customization of the latest multiplayer games to the auto racing experience. Test Drive Unlimited 2 blends single player and multiplayer experiences seamlessly, creating a dynamic world of evolving content and challenges.Players define their online persona through unparalleled customization of their avatars and vehicles, and the acquisition of property, clothing and other accoutrements of a luxurious international lifestyle. MINIMUM REQUİREMENTS: OS: Windows XP SP2, Vista SP2, Windows 7 Processor:Intel Core 2 Duo 2.2GHz or AMD Athlon X2 4400+ Memory: 2GB Graphics: Nvidia GeForce 8800 / ATI Radeon HD 3870 or faster* DirectX®: DirectX 9.0c Hard Drive: 14 GB Sound: DirectX 9.0c-compatible Peripherals: Keyboard, Mouse or 10-button controller such as Xbox 360 or Logitech Dual-Action Other Requirements: Internet Broadband Connection, Microsoft.NET 3.5 required Note:* Integrated video cards, such as the ATI Radeon HD 3200 or Intel HD Graphics, are not supported.
5) Then go to ProjectName/Assets
and create a folder for CSharp wrapper class(es), call it whatever you want, for example: ProjectName/Assets/MySDK
6) Inside of MySDK folder create MySDK.cs file, the dummy example of C# wrapper would look like this:
7) Create a shell script to pack this stuff into .unitypackage
and put it next to your project folder (not inside). Adjust EXPORT_PATH
and PROJECT_PATH
variables in the script for your needs.
8) Run the created bash script to get your package build. All stuff from Assets will be included in XCode project for your Unity Project when you generate it via File -> Build Settings in Unity Editor. You can use generated package to distribute your code to other developers so they can simply include your library to their Unity projects by double clicking on the package file.
Don't forget to shutdown Unity Editor when you run this script, otherwise it may fail to build a package.
If you have some issues and package does not show up, this script always prints log to export.log
Next steps make sense only if you want to make a Demo unity project for your library (good for testing at least)
9) You can put created Unity project (ProjectName.unity) to Assets/MySDKDemo
so you have a demo inside of your package.
10) Create a simple script for your Demo Unity3d scene at Assets/MySDKDemo/MySDKDemo.cs
, for example:
11) Go to Unity Editor. Find the 'Main Camera' in left sidebar in Unity Editor, select it and in the bottom of Inspector panel (right sidebar) click on AddComponent, select Scripts -> MySDKDemo script
12) Build the XCode project and run on device.
Few notes
1) Plugins don't work in Unity Editor, simply because they're not compiled in the real-time, well, not sure but probably until you use C# in your plugins, probably C# stuff gets linked immidiately and works in Editor environment.
2) This post does not cover marshaling, or data/memory management between native <-> managed code, as it is very well documented.
Ios Native Spinner White
3) Callbacks from C# to C can be passed using C# delegates, on C-side you use standard functions declarations, on C# side you declare delegates with the same signature. It seems that booleans, integers and strings (C: char*) are marshalled flawlessly (I don't talk about memory management policy and who's responsible to release memory or return value policies).
However it will not work on iOS builds out-of-box due to platform limitations, but C#-to-C callbacks still can be implemented using MonoPInvokeCallbackAttribute, useful links on this topic:
Actually in Unity 4 there's AOT.MonoPInvokeCallbackAttribute
already implemented, it's limited to static delegates that can be passed to unmanaged code, but still better than nothing.
Ios Native Player
4) There's a way to get Unity RootViewController using UnityGetGLViewController
function. Just declare this function in your implementation file, i.e.:
And use UnityGetGLViewController()
whenever you need to get an access to RootViewController.
5) There's much more magic and ugly stuff in details, keep your C interfaces as simple as possible otherwise marshalling can become your nightmare and also keep in mind that managed-to-unmanaged is generally expensive.
6) You definitely use some frameworks in your native code and you don't want linker problems. For example, if you use Keychain in your library then you need to include Security.framework into Xcode project.
I suggest to give a try to XUPorter, it helps Unity to integrate any additional dependencies into Xcode project.
Good luck!
highmaintenancehighmaintenanceI have written a post on how to create iOS plugin for unity. You can check it here. Hope it helps.Thanks.
Ashwani KAshwani K