Skip to content

Instantly share code, notes, and snippets.

@malavsoni
Created July 26, 2019 16:39
Show Gist options
  • Save malavsoni/0e10f1ad0d0a6b9b2e74bb0c0c778d86 to your computer and use it in GitHub Desktop.
Save malavsoni/0e10f1ad0d0a6b9b2e74bb0c0c778d86 to your computer and use it in GitHub Desktop.
UnityFramework Integration for Swift Project - AppDelegate.swift
//
// 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