Skip to content

Commit 11982de

Browse files
authored
Merge pull request #8 from handsomecode/develop
Develop
2 parents 66daddd + b61811e commit 11982de

File tree

11 files changed

+1086
-1277
lines changed

11 files changed

+1086
-1277
lines changed

Package.resolved

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

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
.library(name: "UBKit", targets: ["UBKit"]),
1111
],
1212
dependencies: [
13-
.package(url: "https://github.com/yonaskolb/XcodeGen.git", from: "1.2.4")
13+
.package(url: "https://github.com/yonaskolb/XcodeGen.git", from: "1.4.0")
1414
],
1515
targets: [
1616
.target(

Sources/UBKit/Files/Unity/UnityEditorBuildScript.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@ import Foundation
2525

2626
extension File {
2727

28-
class func unityBuildScriptFile() -> Data? {
28+
class func unityBuildScriptFile(iOSProjectFolderPath: String, iOSProjectName: String) -> Data? {
2929
let file = """
3030
using System.Collections;
3131
using System.IO;
3232
using UnityEngine;
3333
using UnityEditor;
3434
using UnityEditor.SceneManagement;
3535
using UnityEngine.SceneManagement;
36+
using UnityEditor.iOS.Xcode;
3637
3738
public class iOSBuilder: MonoBehaviour {
39+
40+
private const string iOSProjectRoot = \"\(iOSProjectFolderPath)\";
41+
private const string iOSProjectName = \"\(iOSProjectName)\";
42+
private const string DataProjectPath = "Vendor/UBK/Data";
43+
private const string PbxFilePath = iOSProjectName + ".xcodeproj/project.pbxproj";
44+
3845
public static void Perform () {
3946
var outputLocation = GetArg ("-outputLocation");
4047
var sceneName = GetArg ("-sceneName");
@@ -51,6 +58,21 @@ extension File {
5158
playerOptions.target = BuildTarget.iOS;
5259
playerOptions.options = BuildOptions.None;
5360
BuildPipeline.BuildPlayer (playerOptions);
61+
62+
CopyDataFolderReference (outputLocation);
63+
}
64+
65+
private static void CopyDataFolderReference (string folderRootPath) {
66+
var pbx = new PBXProject();
67+
var pbxPath = Path.Combine(iOSProjectRoot, PbxFilePath);
68+
pbx.ReadFromFile(pbxPath);
69+
70+
var folderGuid = pbx.AddFolderReference(Path.Combine(folderRootPath, "Data"), Path.Combine(iOSProjectRoot, DataProjectPath), PBXSourceTree.Absolute);
71+
var targetGiud = pbx.TargetGuidByName(iOSProjectName);
72+
var resourceGiud = pbx.GetResourcesBuildPhaseByTarget(targetGiud);
73+
pbx.AddFileToBuildSection(targetGiud, resourceGiud, folderGuid);
74+
75+
pbx.WriteToFile(pbxPath);
5476
}
5577
5678
private static string GetArg (string name) {

Sources/UBKit/Files/Xcode/SpecFile.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ extension File {
4343
sources:
4444
- \(projectName)
4545
- Vendor
46-
postbuildScripts:
47-
- script: rm -rf "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data"\\ncp -Rf "$UNITY_IOS_EXPORT_PATH/Data" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data"
48-
name: UnityBuildKit Postbuild
4946
settings:
5047
PRODUCT_BUNDLE_IDENTIFIER: \(bundleIdentifier)
5148
IOS_DEPLOYMENT_TARGET: 11.0

Sources/UBKit/Workers/FileCopier.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,21 @@ class FileCopier {
6060
return parseProjectResult
6161
}
6262

63-
// print("Preparing Build Phase")
6463
let frameworkPhaseResult = addFrameworksBuildPhase()
6564
guard frameworkPhaseResult == .success else {
6665
return frameworkPhaseResult
6766
}
6867

69-
// print("Saving Xcode project")
7068
let saveResult = saveProject()
7169
guard saveResult == .success else {
7270
return saveResult
7371
}
7472

75-
// print("Changing Unity Files")
7673
let changeFilesResult = changeUnityFiles()
7774
guard changeFilesResult == .success else {
7875
return changeFilesResult
7976
}
8077

81-
// print("Adding Unity Files")
8278
let unityFilesResult = addUnityFiles()
8379
guard unityFilesResult == .success else {
8480
return unityFilesResult
@@ -105,14 +101,33 @@ private extension FileCopier {
105101
return .failure(UBKitError.invalidXcodeProject("Failed to find project file"))
106102
}
107103

108-
guard let mainTarget = project.pbxproj.nativeTargets.filter({ $0.name == config.iOS.projectName }).first else {
104+
guard let mainTarget = project.pbxproj.objects.nativeTargets.filter({ $0.value.name == config.iOS.projectName }).first else {
109105
return .failure(UBKitError.invalidXcodeProject("Missing main target"))
110106
}
111107

112108
let frameworksBuildPhase = PBXFrameworksBuildPhase(reference: generateUUID(PBXFrameworksBuildPhase.self,
113109
"frameworks".appending(nameSalt)))
114-
mainTarget.buildPhases.append(frameworksBuildPhase.reference)
115-
project.pbxproj.addObject(frameworksBuildPhase)
110+
mainTarget.value.buildPhases.append(frameworksBuildPhase.reference)
111+
project.pbxproj.objects.addObject(frameworksBuildPhase)
112+
113+
return .success
114+
}
115+
116+
func x() -> Result {
117+
guard let project = project else {
118+
return .failure(UBKitError.invalidXcodeProject("Failed to find project file"))
119+
}
120+
121+
guard let mainTarget = project.pbxproj.objects.nativeTargets.filter({ $0.value.name == config.iOS.projectName }).first else {
122+
return .failure(UBKitError.invalidXcodeProject("Missing main target"))
123+
}
124+
125+
for phase in mainTarget.value.buildPhases {
126+
if phase.starts(with: "RBP_") {
127+
128+
break
129+
}
130+
}
116131

117132
return .success
118133
}

Sources/UBKit/Workers/UnityProject.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private extension UnityProject {
138138

139139
guard fileManager.createFile(
140140
atPath: editorFilePath.appending("iOSBuildScript.cs"),
141-
contents: File.unityBuildScriptFile(),
141+
contents: File.unityBuildScriptFile(iOSProjectFolderPath: config.iOS.projectPath, iOSProjectName: projectName),
142142
attributes: nil) else {
143143
return .failure(UBKitError.unableToCreateFile("Unity iOS Build Script"))
144144
}
@@ -175,7 +175,6 @@ private extension UnityProject {
175175
UnityCommandLine.buildAction,
176176
UnityCommandLine.Arguments.quit,
177177
terminationHandler: { (process) in
178-
print(process.terminationStatus)
179178
statusCode = process.terminationStatus
180179
semaphore.signal()
181180
})

Sources/UBKit/Workers/XcodeGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private extension XcodeGenerator {
5353

5454
let spec: ProjectSpec
5555
do {
56-
spec = try SpecLoader.loadSpec(path: specPath)
56+
spec = try ProjectSpec(path: specPath)
5757
} catch let error as JSONUtilities.DecodingError {
5858
return .failure(error)
5959
} catch {

Sources/UBKit/Workers/XcodeProject.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class XcodeProject {
5555
return iOSFolderResult
5656
}
5757

58-
// print("Generating iOS spec file")
5958
let specFileResult = createSpecFile()
6059
guard specFileResult == .success else {
6160
return specFileResult
@@ -66,7 +65,6 @@ class XcodeProject {
6665
return projectFolderResult
6766
}
6867

69-
// print("Generating iOS source files")
7068
let sourceFileResult = createSourceFiles()
7169
guard sourceFileResult == .success else {
7270
return sourceFileResult
@@ -77,7 +75,6 @@ class XcodeProject {
7775
return assetCatalogResult
7876
}
7977

80-
// print("Generating Unity bridging files")
8178
let unityFilesResult = createUnityBridgeFiles()
8279
guard unityFilesResult == .success else {
8380
return unityFilesResult
@@ -88,7 +85,6 @@ class XcodeProject {
8885
return unityFolderResult
8986
}
9087

91-
// print("Generating iOS project")
9288
let projectGenerationResult = generateXcodeProject()
9389
guard projectGenerationResult == .success else {
9490
return projectGenerationResult
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
23
<plist version="1.0">
34
<dict>
4-
<key>CFBundleDevelopmentRegion</key>
5-
<string>en</string>
6-
<key>CFBundleExecutable</key>
7-
<string>$(EXECUTABLE_NAME)</string>
8-
<key>CFBundleIdentifier</key>
9-
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
10-
<key>CFBundleInfoDictionaryVersion</key>
11-
<string>6.0</string>
12-
<key>CFBundleName</key>
13-
<string>$(PRODUCT_NAME)</string>
14-
<key>CFBundlePackageType</key>
15-
<string>FMWK</string>
16-
<key>CFBundleShortVersionString</key>
17-
<string>1.0</string>
18-
<key>CFBundleSignature</key>
19-
<string>????</string>
20-
<key>CFBundleVersion</key>
21-
<string>$(CURRENT_PROJECT_VERSION)</string>
22-
<key>NSPrincipalClass</key>
23-
<string></string>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>FMWK</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.1</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>$(CURRENT_PROJECT_VERSION)</string>
23+
<key>NSPrincipalClass</key>
24+
<string></string>
2425
</dict>
2526
</plist>

0 commit comments

Comments
 (0)