Skip to content

Commit 371bb27

Browse files
author
Eric Miller
committed
Initial Commit
1 parent 6e0f93b commit 371bb27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+5397
-15
lines changed

.gitignore

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ DerivedData/
1616
*.perspectivev3
1717
!default.perspectivev3
1818
xcuserdata/
19+
.DS_Store
20+
iOS/
21+
Unity/
1922

2023
## Other
2124
*.moved-aside
@@ -33,25 +36,12 @@ timeline.xctimeline
3336
playground.xcworkspace
3437

3538
# Swift Package Manager
36-
#
37-
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
38-
# Packages/
39-
# Package.pins
39+
Packages/
40+
Package.pins
4041
.build/
4142

42-
# CocoaPods
43-
#
44-
# We recommend against adding the Pods directory to your .gitignore. However
45-
# you should judge for yourself, the pros and cons are mentioned at:
46-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
47-
#
48-
# Pods/
4943

5044
# Carthage
51-
#
52-
# Add this line if you want to avoid checking in source code from Carthage dependencies.
53-
# Carthage/Checkouts
54-
5545
Carthage/Build
5646

5747
# fastlane

Package.resolved

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version:4.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "UnityBuildKit",
8+
products: [
9+
.executable(name: "UnityBuildKit", targets: ["UnityBuildKit"]),
10+
.library(name: "UBKit", targets: ["UBKit"]),
11+
],
12+
dependencies: [
13+
.package(url: "https://github.com/yonaskolb/XcodeGen.git", from: "1.2.4")
14+
],
15+
targets: [
16+
.target(
17+
name: "UnityBuildKit",
18+
dependencies: ["UBKit"]),
19+
.target(
20+
name: "UBKit",
21+
dependencies: ["XcodeGenKit"]),
22+
]
23+
)
24+

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# UnityBuildKit
2+
3+
A description of this package.

Sources/UBKit/Files/File.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// File.swift
3+
// UEKit
4+
//
5+
// Created by Eric Miller on 10/11/17.
6+
//
7+
8+
import Foundation
9+
10+
class File { }
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// BridgeHeaderFile.swift
3+
// unity.embedPackageDescription
4+
//
5+
// Created by Eric Miller on 10/11/17.
6+
//
7+
8+
import Foundation
9+
10+
extension File {
11+
12+
class func unityBridgeFile() -> Data? {
13+
let file = """
14+
//
15+
// UnityBridge.h
16+
//
17+
// Created by Adam Venturella on 10/28/15.
18+
//
19+
20+
#ifndef UnityBridge_h
21+
#define UnityBridge_h
22+
23+
#import <UIKit/UIKit.h>
24+
#import "UnityUtils.h"
25+
#import "UnityAppController.h"
26+
#import "UnityInterface.h"
27+
28+
#import "UnityMessageBridge.h"
29+
30+
#endif /* UnityBridge_h */
31+
""".data(using: .utf8)
32+
return file
33+
}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// MessageBridge.swift
3+
// UEKit
4+
//
5+
// Created by Eric Miller on 10/11/17.
6+
//
7+
8+
import Foundation
9+
10+
extension File {
11+
12+
class func unityMessageBridgeFile() -> Data? {
13+
let file = """
14+
//
15+
// UnityMessageBridge.h
16+
//
17+
// Copyright © 2017 Handsome. All rights reserved.
18+
//
19+
20+
#import <Foundation/Foundation.h>
21+
22+
void sendUnityMessage(const char* obj, const char* method, const char* msg) {
23+
UnitySendMessage(obj, method, msg);
24+
}
25+
""".data(using: .utf8)
26+
return file
27+
}
28+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// UnityUtilsFile.swift
3+
// unity.embedPackageDescription
4+
//
5+
// Created by Eric Miller on 10/11/17.
6+
//
7+
8+
import Foundation
9+
10+
extension File {
11+
12+
class func unityUtilsHeaderFile() -> Data? {
13+
let file = """
14+
//
15+
// UnityUtils.h
16+
//
17+
// Created by Adam Venturella on 10/28/15.
18+
//
19+
20+
#ifndef UnityUtils_h
21+
#define UnityUtils_h
22+
23+
24+
void unity_init(int argc, char* argv[]);
25+
26+
#endif /* UnityUtils_h */
27+
""".data(using: .utf8)
28+
return file
29+
}
30+
31+
class func unityUtilsFile() -> Data? {
32+
let file = """
33+
//
34+
// UnityUtils.m
35+
//
36+
// Created by Adam Venturella on 10/28/15.
37+
//
38+
// this is taken directly from the unity generated main.mm file.
39+
// if they change that initialization, this will need to be updated
40+
// as well.
41+
//
42+
// Updated by Martin Straub on 03/15/17.
43+
//
44+
// updated to Unity 5.5.0f3 => working on Xcode 8.2.1 with Swift 3.0.2
45+
46+
47+
#include "RegisterMonoModules.h"
48+
#include "RegisterFeatures.h"
49+
#include <csignal>
50+
51+
52+
// Hack to work around iOS SDK 4.3 linker problem
53+
// we need at least one __TEXT, __const section entry in main application .o files
54+
// to get this section emitted at right time and so avoid LC_ENCRYPTION_INFO size miscalculation
55+
static const int constsection = 0;
56+
57+
void UnityInitTrampoline();
58+
59+
extern "C" void unity_init(int argc, char* argv[])
60+
{
61+
@autoreleasepool
62+
{
63+
UnityInitTrampoline();
64+
UnityInitRuntime(argc, argv);
65+
66+
RegisterMonoModules();
67+
NSLog(@"-> registered mono modules %p", &constsection);
68+
RegisterFeatures();
69+
70+
// iOS terminates open sockets when an application enters background mode.
71+
// The next write to any of such socket causes SIGPIPE signal being raised,
72+
// even if the request has been done from scripting side. This disables the
73+
// signal and allows Mono to throw a proper C# exception.
74+
std::signal(SIGPIPE, SIG_IGN);
75+
}
76+
}
77+
""".data(using: .utf8)
78+
return file
79+
}
80+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// appDelegateFile.swift
3+
// UEKit
4+
//
5+
// Created by Eric Miller on 10/11/17.
6+
//
7+
8+
import Foundation
9+
10+
extension File {
11+
12+
class func appDelegateFile() -> Data? {
13+
let file = """
14+
import UIKit
15+
16+
@UIApplicationMain
17+
class AppDelegate: UIResponder, UIApplicationDelegate {
18+
19+
var window: UIWindow?
20+
@objc var currentUnityController: UnityAppController!
21+
private var application: UIApplication?
22+
private var isUnityRunning = false
23+
24+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
25+
self.application = application
26+
27+
unity_init(CommandLine.argc, CommandLine.unsafeArgv)
28+
currentUnityController = UnityAppController()
29+
currentUnityController!.application(application, didFinishLaunchingWithOptions: launchOptions)
30+
31+
// first call to startUnity will do some init stuff, so just call it here and directly stop it again
32+
startUnity()
33+
stopUnity()
34+
35+
return true
36+
}
37+
38+
func applicationWillResignActive(_ application: UIApplication) {
39+
if isUnityRunning {
40+
currentUnityController?.applicationWillResignActive(application)
41+
}
42+
}
43+
44+
func applicationDidEnterBackground(_ application: UIApplication) {
45+
if isUnityRunning {
46+
currentUnityController?.applicationDidEnterBackground(application)
47+
}
48+
}
49+
50+
func applicationWillEnterForeground(_ application: UIApplication) {
51+
if isUnityRunning {
52+
currentUnityController?.applicationWillEnterForeground(application)
53+
}
54+
}
55+
56+
func applicationDidBecomeActive(_ application: UIApplication) {
57+
if isUnityRunning {
58+
currentUnityController?.applicationDidBecomeActive(application)
59+
}
60+
}
61+
62+
func applicationWillTerminate(_ application: UIApplication) {
63+
if isUnityRunning {
64+
currentUnityController?.applicationWillTerminate(application)
65+
}
66+
}
67+
68+
func startUnity() {
69+
if !isUnityRunning, let app = application, let unityController = currentUnityController {
70+
isUnityRunning = true
71+
unityController.applicationDidBecomeActive(app)
72+
}
73+
}
74+
75+
func stopUnity() {
76+
if isUnityRunning, let app = application, let unityController = currentUnityController {
77+
unityController.applicationWillResignActive(app)
78+
isUnityRunning = false
79+
}
80+
}
81+
}
82+
""".data(using: .utf8)
83+
return file
84+
}
85+
}

0 commit comments

Comments
 (0)