Created
July 26, 2019 16:39
-
-
Save malavsoni/0e10f1ad0d0a6b9b2e74bb0c0c778d86 to your computer and use it in GitHub Desktop.
UnityFramework Integration for Swift Project - AppDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.swift | |
// SwiftNative | |
// | |
// Created by Malav Soni on 23/07/19. | |
// Copyright © 2019 Malav Soni. All rights reserved. | |
// | |
import UIKit | |
import UnityFramework | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
//MARK:- Unity Methods | |
var unityFramework:UnityFramework? | |
func unityFrameworkLoad() -> UnityFramework? { | |
let bundlePath = Bundle.main.bundlePath.appending("/Frameworks/UnityFramework.framework") | |
if let unityBundle = Bundle.init(path: bundlePath){ | |
if let frameworkInstance = unityBundle.principalClass?.getInstance(){ | |
return frameworkInstance | |
} | |
} | |
return nil | |
} | |
func initAndShowUnity() -> Void { | |
if let framework = self.unityFrameworkLoad(){ | |
self.unityFramework = framework | |
self.unityFramework?.setDataBundleId("com.unity3d.framework") | |
self.unityFramework?.runEmbedded(withArgc: CommandLine.argc, argv: CommandLine.unsafeArgv, appLaunchOpts: [:]) | |
self.unityFramework?.showUnityWindow() | |
} | |
} | |
//MARK:- Application LifeCycle | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment