Unity interacts with iOS, Android

Source: Internet
Author: User

1. Unity Tuning iOS method

In the homepage of the Viewcontroller inside the implementation method

void _pressbutton3 (const char *args)

{

Unityappcontroller *unityapp = (Unityappcontroller *) [uiapplication sharedapplication].delegate;

[Unityapp Showwindowssubview];

}

Call _pressbutton3 (content) directly inside unity;

2, iOS and Unity interaction, value

Unitysendmessage ("Scripts", [@ "Function" utf8string], [@ "Parameters" utf8string]);

3. Unity tune Android Inside the method

Add a method to the activity of initializing Unityplayer as follows:

/**
* Test Unity to call Android method
*/
public void TestMethod (String param) {
SYSTEM.OUT.PRINTLN ("parameter:" +param);
}

For the provided method, the UI operation is not possible because Unity3d for Android's UI thread, which is just a child thread, and you can use handler to send a message if you want to do a UI operation.


In Unity Engineering, use C # files to write the code that Unity calls:

public static void Activateshareimage (string content)
{
if (Application.platform = = Runtimeplatform.iphoneplayer)
{
_pressbutton3 (content);
}
else if (Application.platform = = runtimeplatform.android)
{
Uisystem.console ("Test method!");

Androidjavaclass JC = new Androidjavaclass ("Com.unity3d.player.UnityPlayer");
Androidjavaobject Jo = JC. Getstatic<androidjavaobject> ("currentactivity");
Jo. Call ("TestMethod", "unity");
}
Else
{

}
}

4. Android interacts with Unity

Unityplayer. Unitysendmessage ("Scripts", "Function", "Parameters");

Unity interacts with iOS, Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.