Skip to content

服务器托管,北京服务器托管,服务器租用-价格及机房咨询

Menu
  • 首页
  • 关于我们
  • 新闻资讯
  • 数据中心
  • 服务器托管
  • 服务器租用
  • 机房租用
  • 支持中心
  • 解决方案
  • 联系我们
Menu

Unity跟IOS原生开发项目融合

Posted on 2023年5月6日 by hackdl

更多精品文章

Aladdin的博客

需求:


做一款社交类的APP,主体工程是原生开发,也就是是IOS的Xcode工程,产品经理为了丰富应用的玩法,就想往里面加上现在比较流行的AR功能,组成一款AR社交APP,我们之前见识多的都是工程是主体,然后IOS原生功能或者代码作为插件添加进Unity的Plugin里面,这样的方式参见文章(举例):Unity和Android交互让手机动起来,相关IOS方面的文章也可以参见Mono的文章。但是作为AR社交我们肯定是以IOS的Xcode功能为主体,Unity的AR功能为宿主,因为毕竟还是属于社交APP。下面就进入正题,如何将Unity的功能模块添加整合进Xcode工程里面,直接上步骤。

介绍:Unity导出一个空的IOS项目,命名为UnityProject,原生应用命名为Native。

步骤:


一、拷贝文件

将UnityProject项目下 Classes Data Libraries MapFileParser MapFileParser.sh 等文件拷贝到Native主项根目录下


二、添加Framework


###三、添加配置

1.添加runscript

2.添加Search Paths

Header Search Paths 添加
“$(SRCROOT)/Classes”
“$(SRCROOT)”
$(SRCROOT)/Classes/Native
$(SRCROOT)/Libraries/bdwgc/include
$(SRCROOT)/Libraries/libil2cpp/include
 
Library Search Paths 添加
$(inherited)
“$(SRCROOT)”
“$(SRCROOT)/Libraries”

####3.添加预处理文件

Classes/Prefix.pch

####4.添加 -DINIT_SCRIPTING_BACKEND=1


###四、修改main.m

复制Classes/main.mm内容到main.m 修改main.m的扩展名为.mm删除Unity生成main.mm return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

###五、修改 unityAppController

inline UnityAppController* GetAppController()
{
return (UnityAppController*)[[UIApplication sharedApplication] valueForKeyPath:@"delegate.unityAppController"];
}

###六、修改 appdelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    BOOL returnBool;
    if (_unityAppController == nil) {
         
        _unityAppController = [[UnityAppController alloc] init];
    }
    returnBool = [_unityAppController application:application didFinishLaunchingWithOptions:launchOptions];
//    self.window = _unityAppController.window;
     
    HelloViewController *vc = [[HelloViewController alloc] init];
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
     
    return YES;
     
}
 
- (void)applicationWillResignActive:(UIApplication *)application {
    [_unityAppController applicationWillResignActive:application];
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
 
- (void)applicationDidEnterBackground:(UIApplication *)application {
    [_unityAppController applicationDidEnterBackground:application];
 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
 
- (void)applicationWillEnterForeground:(UIApplication *)application {
    [_unityAppController applicationWillEnterForeground:application];
 
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
 
- (void)applicationDidBecomeActive:(UIApplication *)application {
    [_unityAppController applicationDidBecomeActive:application];
 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
 
- (void)applicationWillTerminate:(UIApplication *)application {
    [_unityAppController applicationWillTerminate:application];
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

###七、Error

####1、Expected identifier or ‘(‘

修改UnityViewControllerBaseiOS.h

#ifdef __cplusplus
extern "C" {
#endif
    void AddViewControllerRotationHandling(Class class_, IMP willRotateToInterfaceOrientation, IMP didRotateFromInterfaceOrientation, IMP viewWillTransitionToSize);
#ifdef __cplusplus
}
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
    void AddViewControllerDefaultRotationHandling(Class class_);
#ifdef __cplusplus
}
#endif

####2、如果存在多个pch配置文件,需要整合为一个
####3、Unity和Xcode版本会存在兼容问题,最好都升级到最新,否则会碰到莫名其妙的报错

###八、关于EasyAR的提示

如果使用EasyAR的话,会出现融合后黑屏的问题,解决如下


欢迎关注我的围脖

====================== 相互学习,共同进步 ===================

服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net

Related posts:

  1. 昌平数据中心服务器托管服务:保障稳定性和可靠性
  2. 服务器托管是否存在违法风险?
  3. 山西idc机房租用
  4. 高效稳定的服务器托管CDN服务
  5. 自贡云服务器托管服务介绍

服务器托管,北京服务器托管,服务器租用,机房机柜带宽租用

服务器托管

咨询:董先生

电话13051898268 QQ/微信93663045!

上一篇: [Unity XLua]热更新XLua入门(一)-基础篇
下一篇: Unity Profiler使用说明

最新更新

  • 五月学习之keepalived 软件简介
  • Cibersort免疫浸润的在线分析及R语言代码实现
  • 阿里云的认证最有几个等级?考试费用是多少?
  • 京东APP百亿级商品与车关系数据检索实践 | 京东云技术团队
  • 【Hello Network】TCP协议 TCP协议 确认应答机制 (ACK) 超时重传机制 连接管理机制 流量控制 滑动窗口 拥塞控制 延时应答 捎带应答 面向字节流 粘包问题 TCP的异常情况 TCP小结 基于TCP的应用层协议

随机推荐

  • 上海移动机房服务器托管
  • 服务器托管注意事项与建议
  • 丽江服务器租赁托管厂家价格批发
  • 经济实惠的云服务器与托管服务
  • 北京idc数据中心哪家好

客服咨询

  • 董先生
  • 微信/QQ:93663045
  • 电话:13051898268
  • 邮箱:dongli@hhisp.com
  • 地址:北京市石景山区重聚园甲18号2层

友情链接

  • 服务器托管
  • 服务器租用
  • 机房租用托管
  • 服务器租用托管
©2023 服务器托管,北京服务器托管,服务器租用-价格及机房咨询 京ICP备13047091号-8