Reputation: 14380
I want to create an iOS app that contains Unity3D elements. I also want to control these elements, to change colors and set specific properties on them.
I want to do this controlling from UIKit
elements, so that I can create my interface easily (using native elements such as UINavigationController
).
Is there a way to integrate a Unity3D view as a subview in a native (or Xamarin) app?
I have found a way to take the exported build code from Unity and put it inside another project so that I can instantiate that UIWindow
and display it when I need it, but I have not found a way to interact with it or use it as a subview in my view hierarchy.
Does anyone have some experience with this? Or a way to do this?
Edit: I have a structure in my mind: create a unity app, take the main window (or even the view that is contained inside it, if that does not mess with the contents), and then use the view in the view hierarchy as I like. I think I might be able to use the Native Plugin Interface to talk to my Unity view then.
Edit2: I found a video explaining the entire process I had in mind: https://vimeo.com/145572230
Upvotes: 2
Views: 969
Reputation: 1792
This interaction will require iOS plugin to be written for Unity. A bit tough job but definitely possible. Have a look here should answer your questions.
https://docs.unity3d.com/Manual/PluginsForIOS.html
Define your extern method in the C# file as follows:
[DllImport ("__Internal")]
private static extern float FooPluginFunction();
Set the editor to the iOS build target Add your native code source files to the generated Xcode project’s “Classes” folder (this folder is not overwritten when the 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 must ensure the functions are declared with C linkage to avoid name mangling issues.
extern "C" {
float FooPluginFunction();
}
to call Unity from native code
UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");
Hope that helps
Upvotes: 2