Created
April 13, 2020 00:12
-
-
Save mattbajorek/2f6b513dab04f628b86e996d46d9fd92 to your computer and use it in GitHub Desktop.
Copy edited Objective C folders and files back to Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.Callbacks; | |
using UnityEditor.iOS.Xcode; | |
using System.IO; | |
using System.Linq; | |
public class BuildPostProcessor | |
{ | |
[PostProcessBuild] | |
public static void OnPostProcessBuild(BuildTarget target, string path) | |
{ | |
if (target == BuildTarget.iOS) | |
{ | |
// Get project into C# | |
var projectPath = PBXProject.GetPBXProjectPath(path); | |
var project = new PBXProject(); | |
project.ReadFromFile(projectPath); | |
// Get targetGUID | |
var targetName = PBXProject.GetUnityTargetName(); | |
var targetGUID = project.TargetGuidByName(targetName); | |
... | |
// Add Shell Script to copy folders and files after running successfully | |
var shellScriptName = "Copy edited Objective C folders and files back to Unity"; | |
var shellPath = "/bin/sh"; | |
var shellScript = $"cp -r \"$PROJECT_DIR/Libraries/Plugins/iOS\" {Directory.GetCurrentDirectory()}/Assets/Plugins"; | |
var allBuildPhasesGUIDS = project.GetAllBuildPhasesForTarget(targetGUID); | |
var foundShellScript = allBuildPhasesGUIDS.Where(buildPhasesGUID => project.GetBuildPhaseName(buildPhasesGUID) == shellScriptName).FirstOrDefault(); | |
if (foundShellScript == null) | |
{ | |
project.AddShellScriptBuildPhase(targetGUID, shellScriptName, shellPath, shellScript); | |
Debug.Log($"Added custom shell script: {shellScriptName}"); | |
} | |
... | |
// Overwrite | |
project.WriteToFile(projectPath); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment