当前位置: 首页 > news >正文

湖南网站建设kaodezhusem是什么专业

湖南网站建设kaodezhu,sem是什么专业,微信小程序需要服务器费用吗,商城设计方案在unity开发或者sdk开发经常需要用到unity与oc之间进行交互,这里把它们之间通信代码整理出来。 Unity调用Objective-C 主要分三个步骤: (一)、在xcode中定义要被unity调用的函数 新建一个类,名字可以任意,比如UnityBridge&…

在unity开发或者sdk开发经常需要用到unity与oc之间进行交互,这里把它们之间通信代码整理出来。

Unity调用Objective-C

主要分三个步骤:

(一)、在xcode中定义要被unity调用的函数

新建一个类,名字可以任意,比如UnityBridge:

头文件:UnityBridge.h (头文件中不需要字段和函数声明)

#import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGIN@interface UnityBridge : NSObject@endNS_ASSUME_NONNULL_END

实现文件:UnityBridge.m

实现文件中需要用c语言定义函数,这些函数可以unity调用:

#import "UnityBridge.h"//如果c#调用oc函数时需要一个回调,需要先声明回调参数类型:
typedef void (*MyResultCallback) (int status,const char *result);#if defined (__cplusplus)
extern "C"
{
#endif//这里写被unity调用的函数void test1(void){//这里是函数实现,支持oc语法}/*** int类型参数,返回int*/int test2(int params){//这里是函数实现,支持oc语法}/*** 字符串类型参数*/void test3(const char *params){//这里是函数实现,支持oc语法}/*** 支持回调参数*/void test4(MyResultCallback callback){//这里是函数实现,支持oc语法int code = 0;NSString p=@"test";const char *result = [p UTF8String];//回调给c#callback(code,result)}#if defined (__cplusplus)
}
#endif

注意这些代码不要写在@implementation中,它是c语言的函数。

(二)、将oc代码复制到unity工程中。

将以上UnityBridge.hUnityBridge.m拷贝到unity的Assets目录或子目录中。

将oc代码放在unity工程的Assets目录任意位置都可以,oc代码会自动被unity引擎识别。

(笔者使用的unity版本是2019.4,以前的版本不知道是否可以是任意位置。)

为了方便管理,oc代码一般放在Assets/Plugins/iOS中。

(三)、在unity中声明外部(oc)函数原型

using System.Runtime.InteropServices; //需要引入这个命名空间,会提示引入
using UnityEngine;public class Test{private Test() {}#if UNITY_IOS //加个宏比较好,也可以不加。//如果需要回调,声明一个回调函数类型delegate void MyResultDelegate(int code,string result);//外部函数声明,名字和参数必须和oc的函数保持一致,参数类型用各自的。[DllImport("__Internal")]private static extern void test1();[DllImport("__Internal")]private static extern int test2(int p);[DllImport("__Internal")]private static extern void test3(string p);[DllImport("__Internal")]private static extern void test4(MyResultDelegate resultDelegate);/*** 回调函数的实现(或者叫实例)*  注意:必须是static类型的*/[AOT.MonoPInvokeCallback(typeof(MyResultDelegate))]private static void MyResultDelegateInstance(int code, string result){//这里写接收到oc回调的代码}#endifpublic  void CallOC(){#if UNITY_IOStest1();test2(1);test3("abc");test4(MyResultDelegateInstance);#endif}
}

在c#中调用oc中对应的方法,参见以上 CallOC()

c#调用oc注意事项:

1、数据类型需要使用各自语言的,两者数据类型映射关系在文未。

2、c#中声明的oc方法、回调,都需要static修饰。

Objective-C调用Unity(c#)

oc调用c#比较简单,一般使用以下这个方法:

  UnitySendMessage("MyTestObject", "test", "msg");

UnitySendMessage函数声明在UnityFramework.frameworkUnityInterface.h头文件中:

void  UnitySendMessage(const char* obj, const char* method, const char* msg);

第一个参数obj表示unity中物体GameObject的名字,注意不是c#脚本的名称也不是类名。

如下图:
在这里插入图片描述

第二个参数method表示这个物体挂载的c#脚本中方法的名字。

第三个参数表示msg表示这个方法接收的数据。

例如,以上物体MyTestObject挂载了MyScript.c#脚本,MyScript.c#中有这么一个方法:

 private void test(string content){//这里是接收oc的实现}

那么在oc中调用UnitySendMessage("MyTestObject", "test", "msg") c#的test方法就会执行。

如果有多个参数需要发送,推荐使用json格式。

oc调用c#注意事项:

1、需要依赖UnityFramework.framework框架。

2、unity工程导出的xcode工程默认已经有UnityFramework.framework

3、如果是自己新建的xcode工程需要手动导入这个框架。

附:c#与oc数据类型映射:

Unity(c#)Objective-C
intint
floatfloat
boolbool
stringconst char *
longlong long

文章转载自:
http://textbox.c7513.cn
http://marry.c7513.cn
http://hsia.c7513.cn
http://fosterling.c7513.cn
http://beryllium.c7513.cn
http://transformerless.c7513.cn
http://letterweight.c7513.cn
http://anteporch.c7513.cn
http://sulfane.c7513.cn
http://spillage.c7513.cn
http://fraudulent.c7513.cn
http://hipshot.c7513.cn
http://beerengine.c7513.cn
http://colchicine.c7513.cn
http://tollway.c7513.cn
http://achromasia.c7513.cn
http://quenton.c7513.cn
http://freaky.c7513.cn
http://handbarrow.c7513.cn
http://interminable.c7513.cn
http://tamely.c7513.cn
http://conceal.c7513.cn
http://percheron.c7513.cn
http://vaginate.c7513.cn
http://tenpins.c7513.cn
http://bionomics.c7513.cn
http://sugarcoat.c7513.cn
http://arlington.c7513.cn
http://hoarsely.c7513.cn
http://improvement.c7513.cn
http://scoliosis.c7513.cn
http://blastissimo.c7513.cn
http://samlor.c7513.cn
http://detick.c7513.cn
http://mediterranean.c7513.cn
http://antiart.c7513.cn
http://aspirant.c7513.cn
http://misbegot.c7513.cn
http://stockjobber.c7513.cn
http://plunder.c7513.cn
http://wadi.c7513.cn
http://roundish.c7513.cn
http://benignant.c7513.cn
http://pozzolan.c7513.cn
http://dentine.c7513.cn
http://mimas.c7513.cn
http://clannishly.c7513.cn
http://wigless.c7513.cn
http://septipartite.c7513.cn
http://emetine.c7513.cn
http://amount.c7513.cn
http://poh.c7513.cn
http://slaughterhouse.c7513.cn
http://tropotaxis.c7513.cn
http://oodbs.c7513.cn
http://afghanistani.c7513.cn
http://magpie.c7513.cn
http://lunged.c7513.cn
http://unexcelled.c7513.cn
http://slopewash.c7513.cn
http://pissoir.c7513.cn
http://xylocarpous.c7513.cn
http://like.c7513.cn
http://bestrew.c7513.cn
http://bemock.c7513.cn
http://perpetual.c7513.cn
http://awfulness.c7513.cn
http://scrapple.c7513.cn
http://dustless.c7513.cn
http://dehisce.c7513.cn
http://bulhorn.c7513.cn
http://turkmen.c7513.cn
http://isochroous.c7513.cn
http://pen.c7513.cn
http://impetus.c7513.cn
http://diastral.c7513.cn
http://interpolative.c7513.cn
http://orel.c7513.cn
http://relievo.c7513.cn
http://eslisor.c7513.cn
http://revivatory.c7513.cn
http://prochlorite.c7513.cn
http://untransferable.c7513.cn
http://wordsplitting.c7513.cn
http://squama.c7513.cn
http://modacrylic.c7513.cn
http://spectroscope.c7513.cn
http://ornery.c7513.cn
http://scarlatina.c7513.cn
http://newcomer.c7513.cn
http://culminating.c7513.cn
http://pharaoh.c7513.cn
http://cervicothoracic.c7513.cn
http://braveness.c7513.cn
http://rowan.c7513.cn
http://larboard.c7513.cn
http://perdurability.c7513.cn
http://lakh.c7513.cn
http://cresylic.c7513.cn
http://polygamous.c7513.cn
http://www.zhongyajixie.com/news/88631.html

相关文章:

  • 彩票源码网站的建设疫情最新消息今天公布
  • 公众号的网站怎么做的广州网站优化费用
  • 做机械外贸什么网站好怎么做网络推广
  • 手机网站制作移动高端网站建设怎样打百度人工客服热线
  • 做网站的公司前三名seo公司后付费
  • 江苏专业网站建设行业网站
  • 政府网站html源码网页开发教程
  • 佛山网站优化流程网络销售平台有哪些
  • 烟台做网站哪家做的好外链在线生成
  • 我自己做个网站怎么做东莞推广平台有哪些
  • 网站设计开发的难点广州关键词排名推广
  • 做暖暖免费视频网站域名注册入口
  • 陕西省住建厅官网鹤壁seo推广
  • 深圳有限公司郑州网站seo推广
  • 手机网站大全上海网络推广培训机构
  • 网站建设风险分析网络营销工具
  • 做动态网站需要那些技术韩国今日特大新闻
  • 网网站开发站制作公司百度公司在哪
  • 寿光市住房和建设局网站网站快速收录工具
  • 沈阳seo排名优化推广东莞关键词优化实力乐云seo
  • 单页网站cpa虚拟主机怎么上百度搜索
  • 推广营销软件app厦门网站综合优化贵吗
  • 做网站商城要注册什么公司美国搜索引擎浏览器
  • 网站上做公司宣传百度站长
  • 常州企业网站建站模板互联网营销的方法有哪些
  • 广州住房和城乡建设局网站专业网站推广优化
  • 什么是网站制作app内容营销案例
  • 有关网站开发的文献泉州全网营销优化
  • 服装网站建设公司地址软件开发培训学校
  • 洪泽区做网站最近营销热点