一路整合走来。前后花了4天时间。其中百度,搜狗,Google。不知道多少次。谁知程序员心中泪。。。
话不多说。我只说我遇到的坑。然后怎么集成,网上还是很多例子。
谢谢这遍文章:http://www.jianshu.com/p/a3df2922d98d
Unity3D :2017.1.0f3
Xcode : 8.1(8B62)
Swift:3.1
cocoapods
1.兼容 CocoaPods :要在Unity.xcconfig 文件最后加入: xxx是你的项目名字
#include"Pods/Target Support Files/Pods-xxx/Pods-xxx.debug.xcconfig"
#include"Pods/Target Support Files/Pods-xxx/Pods-xxx.release.xcconfig"
2.Classes里面的main.mm文件没有作用,因为我们新建了main.swift文件。这个文件里面有UIApplicationMain这个函数。这个函数是程序启动的意思。一个程序只能有一个main文件。有些攻略写要改。是因为他是通过这个启动的。所以大家看吧。只能留一个。
3. 多处引用。RegisterMonoModules()。这个意思就是多个注册模型。所以注释Libraries目录下的RegisterMonoModules.cpp文件的除最后一行代码。理论都注释都行,我也没看到最后一行代码干啥子。
/*#if !INIT_SCRIPTING_BACKEND
extern void RegisterAllClassesGranular();
void RegisterAllClasses()
{
// Register classes for unit tests
RegisterAllClassesGranular();
}
void RegisterAllStrippedInternalCalls() {}
void InvokeRegisterStaticallyLinkedModuleClasses() {}
void RegisterStaticallyLinkedModulesGranular() {}
#endif // INIT_SCRIPTING_BACKEND
*/
voidRegisterMonoModules() {}
4.出现 xxx compiled with optimization - stepping may behave oddly; variables may not be available.
这个很多也有。我是没有启动main文件的代码所导致。所以大家出现这个,看网上的什么改debug。optimization level 都没什么用。是要启动main文件啊。这个耽误我很多时间,很烦。
5.出现 player data archive not found at data.unity3d using local filesystem 这个是最后的错误。看了很多帖子,还看到Linux系统下去了。还看到Stream帖子去了。都是泪。
其实是unity3D里面的有些代码用的方法是iOS8的。我的编译系统是iOS9的。
更改 :文件在Classes/UI/OrientationSupport.mm文件里面。
return ConvertToUnityScreenOrientation(controller.interfaceOrientation);return ConvertToUnityScreenOrientation(controller.preferredInterfaceOrientationForPresentation);
6.启动还会错,我在我的appdelegate文件里面加了判断。先不执行unity3d的方法。就是Appdelegate.swift 文件的unityAppController的方法。
classAppDelegate:UIResponder,UIApplicationDelegate,JPUSHRegisterDelegate,BHAlertViewDelegate
{
varwindow:UIWindow?
varunityWindow :UIWindow?
varstartNavigationController=UIViewController()
varcurrentUnityController =UnityAppController()
varisNeedShowUnit3D =false
letnav1 =UINavigationController()
lethelper =AppDelegateHelper.share
funcshowUnityWindow() {
unityWindow?.makeKeyAndVisible()
}
funchideUnityWindow() {
window?.makeKeyAndVisible()
}
funcapplication(_application:UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey:Any]?) ->Bool{
currentUnityController.application(application, didFinishLaunchingWithOptions: launchOptions)
}