Unity3D iOS plugin using ObjectiveC sources to instantiate classes - ios

I would like to know if it is possible to have a Unity iOS plugin made from the sources (.h .m) that allows the instantation of classes and not only calling static methods; and guidance about how to proceed.
I have a java library that has been converted to C# and ObjectiveC with the idea of producing Android, Windows and iOS plugins for unity to later make a transparent layer that will be used in my scene scripts.

Calling Unity C# from native code:
UnitySendMessage("UnityFactory", "CreateObject", "Message");
The "UnityFactory" could be implemented as factory to create new object. The "Message" could be the payload for the new object in json format.
Calling native (.mm not .m because .mm is c/c++ compatible) from Unity:
You have to use a static method but only one.
extern "C" {
void NativeSendMessage("NativeFactory", "CreateObject", "Message");
}
Does the same as the UnitySendMessage...
If you need more flexibility then add more functions to the Factory. In my sample there is only a "CreateObject" but if you don't want to create an object you could add a RouteToObject function ( but of course you need a registry mechanism and the object id in the "Massage" json ).
iOS GUI overlay
I'am not sure if this is relevant to you too but you can overlay the unity-view with UIView's. You have to look for "unity application controller subclassing"

Related

ios swift wrapper in unity related difficulties

i am new to unity.
my aim is to write native wrapper for existing ios sdk.
for a start, i have written sample ios sdk, with just few test methods.
code is written in swift:
https://pastebin.com/auqNutu7
and another file which expose swift functions so that they can matchup with something which unity understands.
https://pastebin.com/rvrSs2aY
and on unity side:
https://pastebin.com/zezmCmKb
i have few queries, which i am not able to figure out.
is this correct way to write:
private static extern void AwesomeSDK_initializeSDK(string name, string apiKey, Action completionHandler);
if you see swift side of code.
i have completion handler/closure in swift method
(https://pastebin.com/auqNutu7)
, how can i relate it to exposed function
(https://pastebin.com/rvrSs2aY)
in swift framework, and also how can i write in unity side
(https://pastebin.com/zezmCmKb).

How to control embedded Unity app from native iOS app

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
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

How to wrap existing iOS code in a new Appcelerator module?

This seems like a basic request, but I can't find the answer to it anywhere. I want to wrap some existing iOS code that I wrote, in a Appcelerator module. That's it. Important points:
I am NOT wrapping a pre-existing 3rd party iOS SDK.
I wrote the iOS code being wrapped.
Code is verified as working within xcode.
There are no .a files. There are 2x .h files and 2x .m files though.
There are no UI elements in the iOS code as it is only designed to connect the native bluetooth hardware to the app.
I have created a generic appcelerator iOS module project, built it, and successfully called the generic ID function within my app.
I cannot figure out how to successfully edit the generic module so that it utilizes my code. Every attempt results in it refusing to compile, and it's maddening.
I do not have access to Hyperloop.
Once I can successfully build the wrapped module, I would call an initialization function which triggers a native bluetooth hardware search. Once connected, there are functions within the module to send commands to the hardware and receive data back. This is the official documentation I've followed so far:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Quick_Start
That helped me build the blank module, include it in the app, and ensure that it worked by calling the built in test property. From there it stops short of actually telling me what I need to know. These are the closest things I've found so far, while still not being what I need:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project-section-43288810_iOSModuleProject-AddaThird-PartyFramework
appcelerator module for existing ios project sdk
Heck, I still don't even know if I can do this within studio or if I have to edit the generic module in Xcode. Help! :) Many thanks in advance.
so first of all, this is not best practice and will cause possible problems in the future when the SDK changes and your module still relies on outdated core API's.
Regarding your question, you could either create a new component that subclasses the existing class, e.g.
class TiMyModuleListViewProxy : TiUiListViewProxy {
}
and call it with
var myList = MyModule.createListView();
or you write a category to extend the existing API with your own logic, e.g.
#interface TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value;
#end
#implementation TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value
{
// Set the value of "somethingElse" now
}
#end
I would prefer the second option since it matches a better Objective-C code-style, but please still be aware of the possible core-changes that might effect your implementation in the feature. Thanks!

libgdx: Parse.com iOS SDK and RoboVM

I have a app project using libgdx 1.2. I want to add Parse.com push notifications to its iOS and Android builds. No problems with the usual java interface that enables the core app to call into the native platform methods, but I have quite a few problems in understanding how to call Parse.com SDK methods from Java RoboVM code, e.g., assuming NativeMethods were my interface for native methods access, and IOSNatives my iOS RoboVM implementation:
public class IOSNatives implements NativeMethods
{
public void pushNotifications()
{
// how do I write the java code equivalent to this example?
// step 5 here: https://parse.com/tutorials/ios-push-notifications
}
}
I mean, step 5 here: and then I need some hints about steps 1-4 too...
I've already searched SO for similar questions, but the only one I could find is
Is there a way for push notifications in libGDX (Android and iOS projects)?
which doesn't really tell what I need.
In order to work with IOS sdk's written on Objective C, you must use bindings. Binding is wrapper which allows you to call objective C code from java. Fortunately you don't need to write your own binding fot parse, because here is existing one: RoboVM parse binding.
You can look at Sample.java for example of implementation.
You can get more info about bindings and how to add them to your project here

using c++ files in objective c sample tutorial

Where can I get sample tutorial where I can get how to use visual C++ files in XCODE using objective c? I am working on app which is having multiple visual C++ files. Basically this is an gaming application which is developed for windows. And now want to develop it on iPad. So can I reuse those files?
Thank you in Advance.
You can just add the c++ files directly to Xcode and it will compile them (assuming you have all the proper headers etc). You can create 'bridges' to that code by using ObjectiveC++ - meaning you can set the suffix of an ObjectiveC file to '.mm' and the methods in the file will be visible to any other ObjectiveC object, but you can instantiate C++ objects too. In fact if you have C++ ivars (object variables), they get the proper destruct messages when the ObjectiveC class is released. Google 'ObjectiveC++' for more info.

Resources