Skip to content

Commit 7399a38

Browse files
authored
Fix broken UnityReady trigger in iOS exports. (#747)
* Fix UnityReady trigger being placed on the wrong line in UnityAppController.mm * Fix a compilation error in Unity 2020.3 and 2021.1.
1 parent 1cfd4f3 commit 7399a38

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private static void DoBuildAndroid(String buildPath, bool isPlugin, bool isRelea
211211
#if UNITY_2022_1_OR_NEWER
212212
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
213213
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
214-
#elif UNITY_2020_3_OR_NEWER
214+
#elif UNITY_2021_2_OR_NEWER
215215
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
216216
EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize;
217217
#endif
@@ -371,7 +371,7 @@ private static void BuildIOS(String path, bool isReleaseBuild)
371371
#if UNITY_2022_1_OR_NEWER
372372
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
373373
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.iOS, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
374-
#elif UNITY_2020_3_OR_NEWER
374+
#elif UNITY_2021_2_OR_NEWER
375375
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, isReleaseBuild ? Il2CppCompilerConfiguration.Release : Il2CppCompilerConfiguration.Debug);
376376
EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize;
377377
#endif

example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/XCodePostBuild.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424

2525
using System.Collections.Generic;
2626
using System.IO;
27+
using System.Text.RegularExpressions;
2728

2829
using UnityEditor;
2930
using UnityEditor.iOS.Xcode;
@@ -323,7 +324,9 @@ private static void EditUnityAppControllerMM(string path)
323324
inScope |= line.Contains("- (void)startUnity:");
324325
markerDetected |= inScope && line.Contains(TouchedMarker);
325326

326-
if (inScope && line.Trim() == "}")
327+
//Find the end of the startUnity function, a } without any indentation. (regex: starts with } followed by any whitespace)
328+
//Avoid indentation before } as newer unity versions include an if-statement inside this function.
329+
if (inScope && Regex.Match(line, @"^}(\s)*$").Success)
327330
{
328331
inScope = false;
329332

@@ -333,6 +336,7 @@ private static void EditUnityAppControllerMM(string path)
333336
}
334337
else
335338
{
339+
//Add a UnityReady notification at the end of the startUnity function.
336340
return new string[]
337341
{
338342
" // Modified by " + TouchedMarker,

0 commit comments

Comments
 (0)