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

Update XcodePostBuild.cs #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
84 changes: 84 additions & 0 deletions XcodePostBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ private static void PatchUnityNativeCode(string pathToBuiltProject)
{
EditSplashScreenMM(Path.Combine(pathToBuiltProject, "Classes/UI/SplashScreen.mm"));
}

// TODO: There are possibly more versions with this issue.
if (Application.unityVersion.StartsWith("2018."))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you simply put this condition into the if condition above, will it still work?

Looking at the function in the issue you mentioned, the logic is pretty similar with 2017.3+ versions. If hasStoryboard is set to false, these storyboards won't conflict with each other, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give it a try this week and report back shortly!

{
EditSplashScreenMM2018(Path.Combine(pathToBuiltProject, "Classes/UI/SplashScreen.mm"));
}
}

/// <summary>
Expand Down Expand Up @@ -404,6 +410,84 @@ private static void EditMetalHelperMM(string path)
return new string[] { line };
});
}

/// <summary>
/// Edit 'SplashScreen.mm': Unity introduces its own 'LaunchScreen.storyboard' since 2017.3.0f3.
/// Disable it here and use Swift project's launch screen instead.
/// This solves an issue where an identifier cannot be found for unitySplashStoryboard
/// </summary>
private static void EditSplashScreenMM2018(string path)
{
var markerDetected = false;
var markerAdded = false;
var inScope = false;
var level = 0;

EditCodeFile(path, line =>
{
inScope |= line.Trim() == "void ShowSplashScreen(UIWindow* window)";
markerDetected |= line.Contains(TouchedMarker);

if (inScope && !markerDetected)
{
if (line.Trim() == "{")
{
level++;
}
else if (line.Trim() == "}")
{
level--;
}

if (line.Trim() == "}" && level == 0)
{
inScope = false;
}

if (level > 1 && line.Trim().StartsWith("_controller = [storyboard instantiateViewControllerWithIdentifier"))
{
return new string[]
{
" //" + line,
" _controller = [storyboard instantiateInitialViewController];",
" window.rootViewController = _controller;"
};
}

if (level > 0 && line.Trim().StartsWith("_controller = [[SplashScreenController alloc] init];"))
{
return new string[]
{
" {",
line,
" [_controller create: window];",
" }"
};
}

if (level > 0 && line.Trim().StartsWith("[_controller create: window];"))
{
return new string[]
{
" //" + line
};
}


if (!markerAdded)
{
markerAdded = true;
return new string[]
{
"// Modified by " + TouchedMarker,
line,
};
}
}

return new string[] { line };
});
}

/// <summary>
/// Edit 'SplashScreen.mm': Unity introduces its own 'LaunchScreen.storyboard' since 2017.3.0f3.
Expand Down