Skip to content

Commit 0ba8ae9

Browse files
authored
Merge pull request #27 from krispypen/master
Adding Metal renderer support (on iOS)
2 parents 42fa3de + 2926146 commit 0ba8ae9

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,9 @@ Be sure you have at least one scene added to your build.
8181

8282
**iOS Platform**:
8383
1. This only works with Unity version >=2019.3 because uses Unity as a library!
84-
2. Other Settings find the Rendering part, uncheck the `Auto Graphics API` and select only `OpenGLES3`.
85-
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`.
84+
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`.
8685
<br />
8786

88-
89-
90-
9187
<br />
9288

9389
### Add Unity Build Scripts and Export

scripts/Editor/XCodePostBuild.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private static void PatchUnityNativeCode(string pathToBuiltProject)
7979
EditUnityFrameworkH(Path.Combine(pathToBuiltProject, "UnityFramework/UnityFramework.h"));
8080
EditUnityAppControllerH(Path.Combine(pathToBuiltProject, "Classes/UnityAppController.h"));
8181
EditUnityAppControllerMM(Path.Combine(pathToBuiltProject, "Classes/UnityAppController.mm"));
82+
EditUnityViewMM(Path.Combine(pathToBuiltProject, "Classes/UI/UnityView.mm"));
8283
}
8384

8485

@@ -265,6 +266,43 @@ private static void EditUnityAppControllerMM(string path)
265266
});
266267
}
267268

269+
/// <summary>
270+
/// Edit 'UnityView.mm': fix the width and height needed for the Metal renderer
271+
/// </summary>
272+
private static void EditUnityViewMM(string path)
273+
{
274+
var inScope = false;
275+
276+
// Add frameworkWarmup method
277+
EditCodeFile(path, line =>
278+
{
279+
inScope |= line.Contains("UnityGetRenderingResolution(&requestedW, &requestedH)");
280+
281+
if (inScope)
282+
{
283+
if (line.Trim() == "")
284+
{
285+
inScope = false;
286+
287+
return new string[]
288+
{
289+
"",
290+
"// Added by " + TouchedMarker,
291+
" if (requestedW == 0) {",
292+
" requestedW = _surfaceSize.width;",
293+
" }",
294+
" if (requestedH == 0) {",
295+
" requestedH = _surfaceSize.height;",
296+
" }",
297+
""
298+
};
299+
}
300+
}
301+
302+
return new string[] { line };
303+
});
304+
}
305+
268306
private static void EditCodeFile(string path, Func<string, IEnumerable<string>> lineHandler)
269307
{
270308
var bakPath = path + ".bak";

0 commit comments

Comments
 (0)