Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.library(name: "UBKit", targets: ["UBKit"]),
],
dependencies: [
.package(url: "https://github.com/yonaskolb/XcodeGen.git", from: "1.2.4")
.package(url: "https://github.com/yonaskolb/XcodeGen.git", from: "1.4.0")
],
targets: [
.target(
Expand Down
24 changes: 23 additions & 1 deletion Sources/UBKit/Files/Unity/UnityEditorBuildScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@ import Foundation

extension File {

class func unityBuildScriptFile() -> Data? {
class func unityBuildScriptFile(iOSProjectFolderPath: String, iOSProjectName: String) -> Data? {
let file = """
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using UnityEditor.iOS.Xcode;

public class iOSBuilder: MonoBehaviour {

private const string iOSProjectRoot = \"\(iOSProjectFolderPath)\";
private const string iOSProjectName = \"\(iOSProjectName)\";
private const string DataProjectPath = "Vendor/UBK/Data";
private const string PbxFilePath = iOSProjectName + ".xcodeproj/project.pbxproj";

public static void Perform () {
var outputLocation = GetArg ("-outputLocation");
var sceneName = GetArg ("-sceneName");
Expand All @@ -51,6 +58,21 @@ extension File {
playerOptions.target = BuildTarget.iOS;
playerOptions.options = BuildOptions.None;
BuildPipeline.BuildPlayer (playerOptions);

CopyDataFolderReference (outputLocation);
}

private static void CopyDataFolderReference (string folderRootPath) {
var pbx = new PBXProject();
var pbxPath = Path.Combine(iOSProjectRoot, PbxFilePath);
pbx.ReadFromFile(pbxPath);

var folderGuid = pbx.AddFolderReference(Path.Combine(folderRootPath, "Data"), Path.Combine(iOSProjectRoot, DataProjectPath), PBXSourceTree.Absolute);
var targetGiud = pbx.TargetGuidByName(iOSProjectName);
var resourceGiud = pbx.GetResourcesBuildPhaseByTarget(targetGiud);
pbx.AddFileToBuildSection(targetGiud, resourceGiud, folderGuid);

pbx.WriteToFile(pbxPath);
}

private static string GetArg (string name) {
Expand Down
3 changes: 0 additions & 3 deletions Sources/UBKit/Files/Xcode/SpecFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ extension File {
sources:
- \(projectName)
- Vendor
postbuildScripts:
- script: rm -rf "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data"\\ncp -Rf "$UNITY_IOS_EXPORT_PATH/Data" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data"
name: UnityBuildKit Postbuild
settings:
PRODUCT_BUNDLE_IDENTIFIER: \(bundleIdentifier)
IOS_DEPLOYMENT_TARGET: 11.0
Expand Down
29 changes: 22 additions & 7 deletions Sources/UBKit/Workers/FileCopier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,21 @@ class FileCopier {
return parseProjectResult
}

// print("Preparing Build Phase")
let frameworkPhaseResult = addFrameworksBuildPhase()
guard frameworkPhaseResult == .success else {
return frameworkPhaseResult
}

// print("Saving Xcode project")
let saveResult = saveProject()
guard saveResult == .success else {
return saveResult
}

// print("Changing Unity Files")
let changeFilesResult = changeUnityFiles()
guard changeFilesResult == .success else {
return changeFilesResult
}

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

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

let frameworksBuildPhase = PBXFrameworksBuildPhase(reference: generateUUID(PBXFrameworksBuildPhase.self,
"frameworks".appending(nameSalt)))
mainTarget.buildPhases.append(frameworksBuildPhase.reference)
project.pbxproj.addObject(frameworksBuildPhase)
mainTarget.value.buildPhases.append(frameworksBuildPhase.reference)
project.pbxproj.objects.addObject(frameworksBuildPhase)

return .success
}

func x() -> Result {
guard let project = project else {
return .failure(UBKitError.invalidXcodeProject("Failed to find project file"))
}

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

for phase in mainTarget.value.buildPhases {
if phase.starts(with: "RBP_") {

break
}
}

return .success
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/UBKit/Workers/UnityProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private extension UnityProject {

guard fileManager.createFile(
atPath: editorFilePath.appending("iOSBuildScript.cs"),
contents: File.unityBuildScriptFile(),
contents: File.unityBuildScriptFile(iOSProjectFolderPath: config.iOS.projectPath, iOSProjectName: projectName),
attributes: nil) else {
return .failure(UBKitError.unableToCreateFile("Unity iOS Build Script"))
}
Expand Down Expand Up @@ -175,7 +175,6 @@ private extension UnityProject {
UnityCommandLine.buildAction,
UnityCommandLine.Arguments.quit,
terminationHandler: { (process) in
print(process.terminationStatus)
statusCode = process.terminationStatus
semaphore.signal()
})
Expand Down
2 changes: 1 addition & 1 deletion Sources/UBKit/Workers/XcodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private extension XcodeGenerator {

let spec: ProjectSpec
do {
spec = try SpecLoader.loadSpec(path: specPath)
spec = try ProjectSpec(path: specPath)
} catch let error as JSONUtilities.DecodingError {
return .failure(error)
} catch {
Expand Down
4 changes: 0 additions & 4 deletions Sources/UBKit/Workers/XcodeProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class XcodeProject {
return iOSFolderResult
}

// print("Generating iOS spec file")
let specFileResult = createSpecFile()
guard specFileResult == .success else {
return specFileResult
Expand All @@ -66,7 +65,6 @@ class XcodeProject {
return projectFolderResult
}

// print("Generating iOS source files")
let sourceFileResult = createSourceFiles()
guard sourceFileResult == .success else {
return sourceFileResult
Expand All @@ -77,7 +75,6 @@ class XcodeProject {
return assetCatalogResult
}

// print("Generating Unity bridging files")
let unityFilesResult = createUnityBridgeFiles()
guard unityFilesResult == .success else {
return unityFilesResult
Expand All @@ -88,7 +85,6 @@ class XcodeProject {
return unityFolderResult
}

// print("Generating iOS project")
let projectGenerationResult = generateXcodeProject()
guard projectGenerationResult == .success else {
return projectGenerationResult
Expand Down
41 changes: 21 additions & 20 deletions UnityBuildKit.xcodeproj/UBKit_Info.plist
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
Loading