Data interaction between Unity3d and Objective-c. IOS SDK interface encapsulates the Unity3d interface.--Reprint

Source: Internet
Author: User

Creation of the Unity 3D simple project. Export to iOS platform with Xcode see this

Unity3d Learn to create simple buttons, corresponding events

Unity C # code

Using unityengine;using system.collections;using System.runtime.interopservices;public class Testfeil:monobehaviour {        [DllImport ("__internal")]    private static extern void C_ctest ();        Use the for initialization    void Start () {        }        //update is called once per frame    void update () {        }        void Ongui ()          the {//Start button  creates a button.          if (GUI. button (new Rect (20,100,200,50), "Qingyun"))          {              //system.console.writeline ("Hello World");             Print ("Hello Qingyun!");             C_ctest ();               Debug.Log ("Up.up");        }                }         void TestResult (String msg)    {        Debug.Log ("TestResult:" +msg);        This is a callback in C #. Used to receive data whether the transmission was successful. ----The function here is the callback in OC.    void Testbtnresult (String msg)    {        Debug.Log ("btnpresssuccessssssssssss:" +msg);    }}

OC and C interfaces in. mm files

meiyupushsdkc.m//meiyupushdemo////Created by Qingyun on 3/31/14.//Copyright (c) Qingyun. All rights reserved.//#import "MeiyuPushSdkC.h" #import "MeiyuPushSdk.h" @interface meiyupushsdkc:nsobject<        Meiyupushsdkdelegate> @end @implementation meiyupushsdkc-(ID) init{id object = [super init];    [[Meiyupushsdk my_initpush]setdelegate:self];    Sdk.delegate = self;    NSLog (@ "INITMEIYUPUSHSDKC"); return object;} -(void) ctestresult{unitysendmessage ("Main Camera", "Testbtnresult", "success. Wow hahaha");} @endMeiyuPushSdkC *m_pushsdk = NULL, #if defined (__cplusplus) extern "C" {#endif void C_ctest () {if (M_push        SDK = = NULL) {m_pushsdk = [[Meiyupushsdkc alloc]init];                } meiyupushsdk *m = [Meiyupushsdk My_initpush];        Objc_msgsend (obj, @selector (setName:), @ "Balabala");        [M ctest];        NSLog (@ "testsuccess---------");    Unitysendmessage ("Main Camera", "TestResult", " -10862904$_^_$ Interface call failed"); } #iF defined (__cplusplus)} #endif 

This connects Unity3d with OC.

Specifically, refer to Unityfile.zip

Data interaction between Unity3d and Objective-c. IOS SDK interface encapsulates the Unity3d interface.--Reprint

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.