From 4bf72c06a69b3093bfbcf7a37a9e4d1d934112b8 Mon Sep 17 00:00:00 2001 From: Kris Pypen Date: Fri, 2 Aug 2019 13:05:41 +0200 Subject: [PATCH] Adding Metal renderer support (on iOS) --- README.md | 6 +---- scripts/Editor/XCodePostBuild.cs | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 16758fb..c15ac99 100644 --- a/README.md +++ b/README.md @@ -80,13 +80,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`.
- - -
### Add Unity Build Scripts and Export diff --git a/scripts/Editor/XCodePostBuild.cs b/scripts/Editor/XCodePostBuild.cs index 9ae503a..d9176a2 100644 --- a/scripts/Editor/XCodePostBuild.cs +++ b/scripts/Editor/XCodePostBuild.cs @@ -79,6 +79,7 @@ public static class XcodePostBuild 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")); } @@ -265,6 +266,43 @@ public static class XcodePostBuild }); } + /// + /// Edit 'UnityView.mm': fix the width and height needed for the Metal renderer + /// + 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> lineHandler) { var bakPath = path + ".bak";