Skip to content

Commit 4cf989d

Browse files
authored
Merge pull request #14 from handsomecode/develop
Develop
2 parents aa00ee5 + d5845fd commit 4cf989d

File tree

7 files changed

+39
-58
lines changed

7 files changed

+39
-58
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
TOOL_NAME = UnityBuildKit
2-
VERSION = 1.1.2
2+
VERSION = 1.1.3
33

44
PREFIX = /usr/local
55
INSTALL_PATH = $(PREFIX)/bin/$(TOOL_NAME)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img src="Assets/ubk_logo.png">
33
</p>
44
<p align="center">
5-
<img src="https://img.shields.io/badge/version-1.1.2-blue.svg?style=flat-square" />
5+
<img src="https://img.shields.io/badge/version-1.1.3-blue.svg?style=flat-square" />
66
<a href="https://github.com/handsomecode/UnityBuildKit/blob/master/LICENSE">
77
<img src="https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square"/>
88
</a>

Sources/UBKit/Files/Unity/UnityFrameworksScript.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Foundation
2626

2727
extension File {
2828

29-
class func unityFrameworksScriptFile(projectName: String, iOSProjectPath: String) -> Data? {
29+
class func unityFrameworksScriptFile(iOSProjectName: String, iOSProjectPath: String) -> Data? {
3030
let file = """
3131
using System.Collections;
3232
using System.IO;
@@ -39,7 +39,7 @@ extension File {
3939
public class XcodeFrameworks: MonoBehaviour {
4040
4141
private const string iOSProjectRoot = \"\(iOSProjectPath)\";
42-
private const string iOSProjectName = \"\(projectName)\";
42+
private const string iOSProjectName = \"\(iOSProjectName)\";
4343
private const string PbxFilePath = iOSProjectName + ".xcodeproj/project.pbxproj";
4444
4545
public static void Perform () {

Sources/UBKit/Files/Unity/UnityProjectScript.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Foundation
2626

2727
extension File {
2828

29-
class func unityProjectScriptFile(projectName: String, iOSProjectPath: String) -> Data? {
29+
class func unityProjectScriptFile(iOSProjectName: String, iOSProjectPath: String) -> Data? {
3030
let file = """
3131
using System.Linq;
3232
using System.Collections.Generic;
@@ -40,7 +40,7 @@ extension File {
4040
public class XcodeRefresher {
4141
4242
private const string iOSProjectRoot = \"\(iOSProjectPath)\";
43-
private const string iOSProjectName = \"\(projectName)\";
43+
private const string iOSProjectName = \"\(iOSProjectName)\";
4444
private const string ClassesProjectPath = "Vendor/UBK/Classes";
4545
private const string LibrariesProjectPath = "Vendor/UBK/Libraries";
4646
private const string PbxFilePath = iOSProjectName + ".xcodeproj/project.pbxproj";

Sources/UBKit/Workers/FileCopier.swift

+6-10
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class FileCopier {
3434
}
3535

3636
private let config: Config
37-
private let workingPath: String
38-
private let xcodeProjectPath: String
3937
private let xcodeProjectFilePath: String
4038

4139
private lazy var fileManager = FileManager.default
@@ -49,9 +47,7 @@ class FileCopier {
4947

5048
init(config: Config) {
5149
self.config = config
52-
self.workingPath = config.unity.projectPath
53-
self.xcodeProjectPath = config.iOS.projectPath
54-
self.xcodeProjectFilePath = String(format: "%@%@%@", xcodeProjectPath, config.iOS.projectName, ".xcodeproj")
50+
self.xcodeProjectFilePath = String(format: "%@%@%@", config.iOS.projectPath, config.iOS.projectName, ".xcodeproj")
5551
}
5652

5753
func copyFiles() -> Result {
@@ -119,7 +115,7 @@ private extension FileCopier {
119115
}
120116

121117
func changeUnityFiles() -> Result {
122-
let mainFilePath = workingPath.appending(config.unity.projectName).appending("/ios_build/Classes/main.mm")
118+
let mainFilePath = config.unity.projectPath.appending(config.unity.projectName).appending("/ios_build/Classes/main.mm")
123119
guard fileManager.fileExists(atPath: mainFilePath) else {
124120
return .failure(UBKitError.missingUnityFile("main.mm"))
125121
}
@@ -128,7 +124,7 @@ private extension FileCopier {
128124
return changeInitResult
129125
}
130126

131-
let appControllerFilePath = workingPath.appending(config.unity.projectName).appending("/ios_build/Classes/UnityAppController.h")
127+
let appControllerFilePath = config.unity.projectPath.appending(config.unity.projectName).appending("/ios_build/Classes/UnityAppController.h")
132128
guard fileManager.fileExists(atPath: appControllerFilePath) else {
133129
return .failure(UBKitError.missingUnityFile("UnityAppController.h"))
134130
}
@@ -137,7 +133,7 @@ private extension FileCopier {
137133
return changeAppControllerResult
138134
}
139135

140-
let metalHelperFilePath = workingPath.appending(config.unity.projectName).appending("/ios_build/Classes/Unity/MetalHelper.mm")
136+
let metalHelperFilePath = config.unity.projectPath.appending(config.unity.projectName).appending("/ios_build/Classes/Unity/MetalHelper.mm")
141137
guard fileManager.fileExists(atPath: metalHelperFilePath) else {
142138
return .failure(UBKitError.missingUnityFile("MetalHelper.mm"))
143139
}
@@ -151,7 +147,7 @@ private extension FileCopier {
151147
func addUnityFiles() -> Result {
152148
let semaphore = DispatchSemaphore(value: 0)
153149
var statusCode: Int32 = 999
154-
let projectPath = workingPath.appending(config.unity.projectName).appending("/ios_build")
150+
let projectPath = config.unity.projectPath.appending(config.unity.projectName).appending("/ios_build")
155151

156152
shell.perform(
157153
config.unity.applicationPath,
@@ -182,7 +178,7 @@ private extension FileCopier {
182178
func addXcodeFrameworks() -> Result {
183179
let semaphore = DispatchSemaphore(value: 0)
184180
var statusCode: Int32 = 999
185-
let projectPath = workingPath.appending(config.unity.projectName)
181+
let projectPath = config.unity.projectPath.appending(config.unity.projectName)
186182

187183
shell.perform(
188184
config.unity.applicationPath,

Sources/UBKit/Workers/UnityProject.swift

+14-23
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,19 @@ import Foundation
2626
class UnityProject {
2727

2828
private let config: Config
29-
private let workingPath: String
30-
private let projectName: String
31-
private let unitySceneNames: [String]
32-
3329
private let fileManager = FileManager()
3430
private lazy var shell = Shell()
35-
private let unityAppPath: String
3631

3732
init(config: Config) {
3833
self.config = config
39-
self.projectName = config.iOS.projectName
40-
self.workingPath = config.unity.projectPath
41-
self.unityAppPath = config.unity.applicationPath
42-
self.unitySceneNames = config.unity.sceneNames
4334
}
4435

4536
func create() -> Result {
46-
guard UBKit.validatePath(unityAppPath, isDirectory: false) else {
47-
return .failure(UBKitError.invalidFolder(unityAppPath))
37+
guard UBKit.validatePath(config.unity.applicationPath, isDirectory: false) else {
38+
return .failure(UBKitError.invalidFolder(config.unity.applicationPath))
4839
}
4940

50-
print("Unity Project Path: \(workingPath)\n")
41+
print("Unity Project Path: \(config.unity.projectPath)\n")
5142
let unityFolderResult = createUnityFolder()
5243
guard unityFolderResult == .success else {
5344
return unityFolderResult
@@ -83,7 +74,7 @@ private extension UnityProject {
8374
func createUnityFolder() -> Result {
8475
do {
8576
try fileManager.createDirectory(
86-
atPath: workingPath,
77+
atPath: config.unity.projectPath,
8778
withIntermediateDirectories: false,
8879
attributes: nil)
8980
} catch {
@@ -95,11 +86,11 @@ private extension UnityProject {
9586

9687
func generateUnityProject() -> Result {
9788
let semaphore = DispatchSemaphore(value: 0)
98-
let unityProjectPath = workingPath.appending(projectName)
89+
let unityProjectPath = config.unity.projectPath.appending(config.unity.projectName)
9990
var statusCode: Int32 = 0
10091

10192
shell.perform(
102-
unityAppPath,
93+
config.unity.applicationPath,
10394
UnityCommandLine.Arguments.batchmode,
10495
UnityCommandLine.Arguments.createProject,
10596
unityProjectPath,
@@ -123,7 +114,7 @@ private extension UnityProject {
123114
}
124115

125116
func createUnityEditorScripts() -> Result {
126-
let assetsFilePath = workingPath.appending(projectName).appending("/Assets/")
117+
let assetsFilePath = config.unity.projectPath.appending(config.unity.projectName).appending("/Assets/")
127118
guard UBKit.validatePath(assetsFilePath, isDirectory: true) else {
128119
return .failure(UBKitError.invalidFolder(assetsFilePath))
129120
}
@@ -139,21 +130,21 @@ private extension UnityProject {
139130

140131
guard fileManager.createFile(
141132
atPath: editorFilePath.appending("iOSBuildScript.cs"),
142-
contents: File.unityBuildScriptFile(iOSProjectFolderPath: config.iOS.projectPath, iOSProjectName: projectName),
133+
contents: File.unityBuildScriptFile(iOSProjectFolderPath: config.iOS.projectPath, iOSProjectName: config.iOS.projectName),
143134
attributes: nil) else {
144135
return .failure(UBKitError.unableToCreateFile("Unity iOS Build Script"))
145136
}
146137

147138
guard fileManager.createFile(
148139
atPath: editorFilePath.appending("XcodeProjectRefresher.cs"),
149-
contents: File.unityProjectScriptFile(projectName: projectName, iOSProjectPath: config.iOS.projectPath),
140+
contents: File.unityProjectScriptFile(iOSProjectName: config.iOS.projectName, iOSProjectPath: config.iOS.projectPath),
150141
attributes: nil) else {
151142
return .failure(UBKitError.unableToCreateFile("Unity Project Script"))
152143
}
153144

154145
guard fileManager.createFile(
155146
atPath: editorFilePath.appending("XcodeFrameworks.cs"),
156-
contents: File.unityFrameworksScriptFile(projectName: projectName, iOSProjectPath: config.iOS.projectPath),
147+
contents: File.unityFrameworksScriptFile(iOSProjectName: config.iOS.projectName, iOSProjectPath: config.iOS.projectPath),
157148
attributes: nil) else {
158149
return .failure(UBKitError.unableToCreateFile("Xcode Frameworks Script"))
159150
}
@@ -164,21 +155,21 @@ private extension UnityProject {
164155
func runInitialProjectBuild() -> Result {
165156
let semaphore = DispatchSemaphore(value: 0)
166157
var statusCode: Int32 = 999
167-
let projectPath = workingPath.appending(projectName)
158+
let projectPath = config.unity.projectPath.appending(config.unity.projectName)
168159
let outputLocation = projectPath.appending("/").appending("ios_build")
169160

170161
// MARK: - Main
171-
print("Initializing Unity scene \(unitySceneNames[0]) for iOS...")
162+
print("Initializing Unity scene \(config.unity.sceneNames[0]) for iOS...")
172163
print("This will take some time to complete\n")
173164
shell.perform(
174-
unityAppPath,
165+
config.unity.applicationPath,
175166
UnityCommandLine.Arguments.batchmode,
176167
UnityCommandLine.Arguments.projectPath,
177168
projectPath,
178169
UnityCommandLine.Arguments.outputLocation,
179170
outputLocation,
180171
UnityCommandLine.Arguments.sceneName,
181-
unitySceneNames[0],
172+
config.unity.sceneNames[0],
182173
UnityCommandLine.Arguments.executeMethod,
183174
UnityCommandLine.buildAction,
184175
UnityCommandLine.Arguments.quit,

Sources/UBKit/Workers/XcodeProject.swift

+13-19
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ import Foundation
2525

2626
class XcodeProject {
2727

28-
private let projectName: String
29-
private let bundleIdentifier: String
30-
private let workingPath: String
31-
private let unityVersion: String
28+
private let config: Config
3229
private let projectPath: String
3330
private let vendorFolderPath: String
3431
private let vendorClassesFolderPath: String
@@ -40,21 +37,18 @@ class XcodeProject {
4037
private var error: Error?
4138

4239
init(config: Config) {
43-
self.projectName = config.iOS.projectName
44-
self.bundleIdentifier = config.iOS.bundleId
45-
self.workingPath = config.iOS.projectPath
46-
self.unityVersion = config.unity.version
40+
self.config = config
4741

48-
self.projectPath = workingPath.appending(projectName).appending("/")
49-
self.vendorFolderPath = workingPath.appending("Vendor/UBK/")
42+
self.projectPath = config.iOS.projectPath.appending(config.iOS.projectName).appending("/")
43+
self.vendorFolderPath = config.iOS.projectPath.appending("Vendor/UBK/")
5044
self.vendorClassesFolderPath = vendorFolderPath.appending("Classes")
5145
self.vendorLibrariesFolderPath = vendorFolderPath.appending("Libraries")
5246
self.specFileName = "project.yml"
5347
self.bridgingFilesPath = projectPath.appending("UnityBridge/")
5448
}
5549

5650
func create() -> Result {
57-
print("iOS Project Path: \(workingPath)")
51+
print("iOS Project Path: \(config.iOS.projectPath)")
5852
let iOSFolderResult = createiOSFolder()
5953
guard iOSFolderResult == .success else {
6054
return iOSFolderResult
@@ -104,7 +98,7 @@ private extension XcodeProject {
10498
func createiOSFolder() -> Result {
10599
do {
106100
try fileManager.createDirectory(
107-
atPath: workingPath,
101+
atPath: config.iOS.projectPath,
108102
withIntermediateDirectories: false,
109103
attributes: nil)
110104

@@ -115,18 +109,18 @@ private extension XcodeProject {
115109
}
116110

117111
func createSpecFile() -> Result {
118-
guard UBKit.validatePath(workingPath, isDirectory: true) else {
119-
return .failure(UBKitError.invalidFolder(workingPath))
112+
guard UBKit.validatePath(config.iOS.projectPath, isDirectory: true) else {
113+
return .failure(UBKitError.invalidFolder(config.iOS.projectPath))
120114
}
121115

122116
let contents = File.specFile(
123-
projectName: projectName,
124-
bundleIdentifier: bundleIdentifier,
125-
unityVersion: unityVersion
117+
projectName: config.iOS.projectName,
118+
bundleIdentifier: config.iOS.bundleId,
119+
unityVersion: config.unity.version
126120
)
127121

128122
guard fileManager.createFile(
129-
atPath: workingPath.appending(specFileName),
123+
atPath: config.iOS.projectPath.appending(specFileName),
130124
contents: contents,
131125
attributes: nil) else {
132126
return .failure(UBKitError.unableToCreateFile("Spec file"))
@@ -270,7 +264,7 @@ private extension XcodeProject {
270264
}
271265

272266
func generateXcodeProject() -> Result {
273-
let generator = XcodeGenerator(path: workingPath, fileName: specFileName)
267+
let generator = XcodeGenerator(path: config.iOS.projectPath, fileName: specFileName)
274268
return generator.generateProject()
275269
}
276270
}

0 commit comments

Comments
 (0)