Unity3D 與 objective-c 之間資料互動。iOS SDK介面封裝Unity3D介面 .-- 轉載

來源:互聯網
上載者:User

標籤:message   成功   unity3   init   oid   img   result   ini   created   

Unity 3D 簡單工程的建立。與Xcode 匯出到iOS 平台請看這 

Unity3D 學習 建立簡單的按鈕、相應事件

Unity C# 代碼

 

using UnityEngine;using System.Collections;using System.Runtime.InteropServices;public class testFeil : MonoBehaviour {        [DllImport("__Internal")]    private static extern void c_ctest();        // Use this for initialization    void Start () {        }        // Update is called once per frame    void Update () {        }        void OnGUI()      {          //開始按鈕  建立了一個按鈕。          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);    }        //這個是C#裡的一個回調。用來接收資料是否傳送成功。----這裡的作用就是OC裡的回調。    void testBtnResult (string msg)    {        Debug.Log ("btnPressSuccessssssssssss:"+msg);    }}

 

 

.mm 檔案裡的OC  與 C 介面

////  MeiyuPushSdkC.m//  MeiYuPushDemo////  Created by qingyun on 3/31/14.//  Copyright (c) 2014 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", "成功啦.哇哈哈哈");}@endMeiyuPushSdkC *m_pushSdk = NULL;#if defined (__cplusplus)extern "C"{#endif        void c_ctest()    {        if(m_pushSdk == 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$_^_$介面調用失敗");    }    #if defined (__cplusplus)}#endif

 

 這樣就把Unity3d 與OC 連到了一起。

 

具體可參考 unityFile.zip

 

Unity3D 與 objective-c 之間資料互動。iOS SDK介面封裝Unity3D介面 .-- 轉載

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.