【问题标题】:Customize Unity3D Xcode project with storyboards使用故事板自定义 Unity3D Xcode 项目
【发布时间】:2015-08-05 20:21:23
【问题描述】:

我是 Unity3D 的新手。我的要求是在 iOS 原生应用程序之间拥有游戏屏幕(由 Unity3D 构建)。 我已经编写了 .mm 以继承 UnityAppController.mm 的子类

#import <UIKit/UIKit.h>
#import "UnityAppController.h"

@interface TNAppController : UnityAppController

- (void)createViewHierarchyImpl;

@end

@implementation TNAppController

- (void)createViewHierarchyImpl {

    UIStoryboard *storyBoard    = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    UIViewController *mainVC    = [storyBoard instantiateInitialViewController];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = mainVC;
    _rootController             = [self.window rootViewController];
    _rootView                   = _rootController.view;
}

@end

IMPL_APP_CONTROLLER_SUBCLASS(TNAppController)

但是当我尝试分配 _rootView 时出现以下错误。

2015-01-29 18:21:53.298 ProductName[548:60b] -> 注册单声道 模块 0x136b0c0 -> applicationDidFinishLaunching() 单声道路径[0] = '/var/mobile/Applications/A7836E0B-2F4B-4704-B359-63A7C860CB07/ProductName.app/Data/Managed' 单声道配置路径 = '/var/mobile/Applications/A7836E0B-2F4B-4704-B359-63A7C860CB07/ProductName.app/Data/Managed' -> applicationDidBecomeActive() 请求分辨率:640x1136 渲染器:PowerVR SGX 543 供应商:Imagination Technologies 版本: OpenGL ES 2.0 IMGSGX543-97 GL_OES_depth_texture GL_OES_depth24 GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_vertex_array_object GL_EXT_blend_minmax GL_EXT_color_buffer_half_float GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_draw_instanced GL_EXT_instanced_arrays GL_EXT_map_buffer_range GL_EXT_occlusion_query_boolean GL_EXT_pvrtc_sRGB GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_shadow_samplers GL_EXT_sRGB GL_EXT_texture_filter_anisotropic GL_EXT_texture_rg GL_EXT_texture_storage GL_APPLE_copy_texture_levels GL_APPLE_framebuffer_multisample GL_APPLE_rgb_422 GL_APPLE_sync GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_IMG_read_format GL_IMG_texture_compression_pvrtc 创建 OpenGLES2.0图形设备初始化引擎版本:4.6.1f1 (d1db7a1b5196) 开始 MonoManager ReloadAssembly - 在 0.072 秒内完成重新加载

按照http://www.the-nerd.be/2014/08/06/add-unity3d-in-a-native-ios-application/中的教程进行操作

注意到在 UnityAppController.mm 中的 transitionToViewController 方法中 _rootViewController 被垃圾收集,这会引发错误访问。

有这方面的经验吗?

非常感谢!

【问题讨论】:

  • 您可能希望从您拥有的错误消息中删除(这是无害的)消息,因为现在是这样。我什至在大量文本中找不到错误消息
  • 抱歉!希望现在能有所帮助..
  • 请将错误发布为文本,您可以分别复制和粘贴调用堆栈和代码片段。图像变得难以阅读。
  • 尝试将[UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];改为[UIStoryboard storyboardWithName:@"Main" bundle:nil];

标签: ios unity3d


【解决方案1】:

这段代码,对我来说很好用:

#import <UIKit/UIKit.h>
#import "UnityAppController.h"
#import "UI/UnityView.h"
#import "UI/UnityViewControllerBase.h"

#import "TopViewController.h"

@interface TNAppController : UnityAppController

@property (nonatomic, strong) UINavigationController *navController;

- (void)willStartWithViewController;

@end

@implementation TNAppController
- (void)willStartWithViewController:(UIViewController*)controller {

    UIStoryboard *storyBoard    = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *mainVC    = [storyBoard instantiateInitialViewController];

    _rootController    = [[UnityDefaultViewController alloc] init];
    _rootView        = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    _rootController.view = _rootView;

    //UnitySceneViewController *unityScene = [[UnitySceneViewController alloc] initWithNibName:nil bundle:nil];

    self.navController = [[UINavigationController alloc] initWithRootViewController:mainVC];
    [_rootView addSubview:self.navController.view];

    /*
    UIStoryboard *storyBoard    = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *mainVC    = [storyBoard instantiateInitialViewController];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = mainVC;
    _rootController             = [self.window rootViewController];
    _rootView                   = _rootController.view;
    */
}

@end

IMPL_APP_CONTROLLER_SUBCLASS(TNAppController)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-03
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多