Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate iOS integration steps 5 and 6 #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions UnityProject/Assets/Editor/iOSPBXProjectModifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

public class iOSPBXProjectModifier
{
[PostProcessBuildAttribute]
public static void OnPostProcessBuild(BuildTarget target, string buildPath)
{
// Modify Unity generated Xcode project to enable Unity as a library
if (target == BuildTarget.iOS)
{
// Read project
string projectPath = PBXProject.GetPBXProjectPath(buildPath);
PBXProject project = new PBXProject();
project.ReadFromFile(projectPath);

// Get main and framework target guids
string unityMainTargetGuid = project.GetUnityMainTargetGuid();
string unityFrameworkTargetGuid = project.GetUnityFrameworkTargetGuid();

// Set NativeCallProxy plugin header visibility to public
string pluginHeaderGuid = project.FindFileGuidByProjectPath("Libraries/Plugins/iOS/NativeCallProxy.h");
project.AddPublicHeaderToBuild(unityFrameworkTargetGuid, pluginHeaderGuid);

// Change data directory target membership to framework only
string dataDirectoryGuid = project.FindFileGuidByProjectPath("Data");
project.RemoveFileFromBuild(unityMainTargetGuid, dataDirectoryGuid);
project.AddFileToBuild(unityFrameworkTargetGuid, dataDirectoryGuid);

// Overwrite project
project.WriteToFile(projectPath);
}
}
}
2 changes: 2 additions & 0 deletions UnityProject/Assets/Editor/iOSPBXProjectModifier.cs.meta

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

Binary file removed docs/images/ios/dataTargetMembership.png
Binary file not shown.
Binary file removed docs/images/ios/nativeCallProxyTarget.png
Binary file not shown.
13 changes: 2 additions & 11 deletions docs/ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,9 @@ This document explains how to include Unity as a Library into standard iOS appli
- in "Build Phases" tab, expand "Link Binary With Libraries"
- remove UnityFramework.framework from the list (select it and press - )
<br><img src="images/ios/removeLink.png">

**5. Expose NativeCallProxy.h**
<br>Native application implements NativeCallsProtocol defined in following file:
- In Project navigator, find and select Unity-iPhone / Libraries / Plugins / iOS / NativeCallProxy.h
- enable UnityFramework in Target Membership and set header visibility from project to public (small dropdown on right side to UnityFramework)
<br><img src="images/ios/nativeCallProxyTarget.png">

**6. Make Data folder to be part of the UnityFramework**
<br>By default Data folder is part of Unity-iPhone target, we change that to make everything encapsulated in one single framework file.
- change Target Membership for Data folder to UnityFramework
<br><img src="images/ios/dataTargetMembership.png" height='300px'>
- (optional) If you want to use Unity-iPhone sheme you need to point UnityFramework to a new place where Data is located by calling from Unity-iPhone/MainApp/main.mm:
**5. (optional) If you want to use Unity-iPhone scheme**
- you need to point UnityFramework to a new place where Data is located by calling from Unity-iPhone/MainApp/main.mm:
```
[ufw setDataBundleId: "com.unity3d.framework"];
// On Demand Resources are not supported in this case. To make them work instead of the calls above
Expand Down