在Native iOS App中为Unity生成错误

时间:2018-12-28 04:41:20

标签: c# swift xcode unity3d native

iOS开发的Iam初学者。 我想在本机iOS应用示例中获得有关Unity的帮助。我参加了一些过时的在线课程,最后也显示了一些错误。我想问问是否有人可以发布视频教程或示例项目来在Native iOS应用中制作Unity。..这是示例链接:-https://medium.com/@IronEqual/how-to-embed-a-unity-game-into-an-ios-native-swift-app-772a0b65c82就是这样。

enter image description here

1 个答案:

答案 0 :(得分:0)

根据您的请求,我上传了一个视频教程,该视频教程用于在Native iOS App中使用最新版本的Xcode-10.1和unity -2018.2.18f1构建Unity。

Youtube链接-https://www.youtube.com/watch?v=DLkeGz5vCzk

App Delegate的源代码为

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIWindow *unityWindow;
@property (strong, nonatomic) UnityAppController *unityController;
- (void) showUnityWindow;
- (void) hideUnityWindow;


@end

AppDelegate.m

#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate
- (UIWindow *)unityWindow {
    return UnityGetMainWindow();
}
- (void) showUnityWindow {
    [self.unityWindow makeKeyAndVisible];
}
- (void) hideUnityWindow{
    [self.window makeKeyAndVisible];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ViewController *mainVC = [storyboard instantiateViewControllerWithIdentifier:@"MainIdentity"];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
    self.window.rootViewController = naVC;
    self.unityController = [[UnityAppController alloc] init];
    [self.unityController application:application didFinishLaunchingWithOptions: launchOptions];

    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application {

    [self.unityController applicationWillResignActive:application];
}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    [self.unityController applicationDidEnterBackground:application];
}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    [self.unityController applicationWillEnterForeground:application];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {

    [self.unityController applicationDidBecomeActive:application];
}


- (void)applicationWillTerminate:(UIApplication *)application {

    [self.unityController applicationWillTerminate:application];
}


@end

然后是View Controller.m

#import "ViewController.h"
#import "AppDelegate.h"

@interface ViewController ()
@property (nonatomic) BOOL isShowUnityWindow;
- (IBAction)showUnityTouched:(id)sender;
@property (weak, nonatomic) IBOutlet UIView *unityViewStart;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isShowUnityWindow = NO;

}


- (IBAction)showUnityTouched:(id)sender {
    self.isShowUnityWindow = !self.isShowUnityWindow;
    AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;

    if (self.isShowUnityWindow) {
       [appDelegate.unityWindow setFrame:CGRectMake(40, 200, 500, 500)];
        [appDelegate.unityWindow ]

        [appDelegate showUnityWindow];

    }
    else {
        [appDelegate hideUnityWindow];
    }
}
@end