Skip to content

Commit

Permalink
Merge pull request #27 from krispypen/master
Browse files Browse the repository at this point in the history
Adding Metal renderer support (on iOS)
  • Loading branch information
juicycleff committed Aug 2, 2019
2 parents 42fa3de + 2926146 commit 0ba8ae9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ Be sure you have at least one scene added to your build.

**iOS Platform**:
1. This only works with Unity version >=2019.3 because uses Unity as a library!
2. Other Settings find the Rendering part, uncheck the `Auto Graphics API` and select only `OpenGLES3`.
3. Depending on where you want to test or run your app, (simulator or physical device), you should select the appropriate SDK on `Target SDK`.
2. Depending on where you want to test or run your app, (simulator or physical device), you should select the appropriate SDK on `Target SDK`.
<br />



<br />

### Add Unity Build Scripts and Export
Expand Down
38 changes: 38 additions & 0 deletions scripts/Editor/XCodePostBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private static void PatchUnityNativeCode(string pathToBuiltProject)
EditUnityFrameworkH(Path.Combine(pathToBuiltProject, "UnityFramework/UnityFramework.h"));
EditUnityAppControllerH(Path.Combine(pathToBuiltProject, "Classes/UnityAppController.h"));
EditUnityAppControllerMM(Path.Combine(pathToBuiltProject, "Classes/UnityAppController.mm"));
EditUnityViewMM(Path.Combine(pathToBuiltProject, "Classes/UI/UnityView.mm"));
}


Expand Down Expand Up @@ -265,6 +266,43 @@ private static void EditUnityAppControllerMM(string path)
});
}

/// <summary>
/// Edit 'UnityView.mm': fix the width and height needed for the Metal renderer
/// </summary>
private static void EditUnityViewMM(string path)
{
var inScope = false;

// Add frameworkWarmup method
EditCodeFile(path, line =>
{
inScope |= line.Contains("UnityGetRenderingResolution(&requestedW, &requestedH)");
if (inScope)
{
if (line.Trim() == "")
{
inScope = false;
return new string[]
{
"",
"// Added by " + TouchedMarker,
" if (requestedW == 0) {",
" requestedW = _surfaceSize.width;",
" }",
" if (requestedH == 0) {",
" requestedH = _surfaceSize.height;",
" }",
""
};
}
}
return new string[] { line };
});
}

private static void EditCodeFile(string path, Func<string, IEnumerable<string>> lineHandler)
{
var bakPath = path + ".bak";
Expand Down

0 comments on commit 0ba8ae9

Please sign in to comment.