Skip to content

Instantly share code, notes, and snippets.

@n-taku
Last active October 5, 2018 15:07
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save n-taku/4b20e2e153f2e0d09484dddcca0e1861 to your computer and use it in GitHub Desktop.
iPhoneXでのみStatusBarを表示する設定
#if UNITY_IOS
using UnityEditor;
using UnityEditor.Callbacks;
using System.IO;
using UnityEditor.iOS.Xcode;
using UnityEngine;
public class IPhoneXStatusBarSetting
{
[PostProcessBuild]
public static void OnPostProcessBuild (BuildTarget buildTarget, string path)
{
if (UnityEditor.PlayerSettings.statusBarHidden)
{
//StatusBarをデフォルトで非表示
var plistPath = Path.Combine (path, "Info.plist");
var plist = new PlistDocument ();
plist.ReadFromFile (plistPath);
plist.root.SetBoolean ("UIStatusBarHidden", false);
plist.WriteToFile (plistPath);
//Unityで出力されるViewControllerファイルを書き換える
string viewControllerPath = Path.Combine (path, "Classes/UI/UnityViewControllerBase+iOS.mm");
string viewControllerContent = File.ReadAllText (viewControllerPath);
string vcOldText =
" return _PrefersStatusBarHidden;";
string vcNewText =
" CGSize size = [UIScreen mainScreen].nativeBounds.size;\n" +
" if ( (int)size.width == 1125 && (int)size.height == 2436)\n" +
" {\n" +
" return NO;\n" +
" }\n" +
" else\n" +
" {\n" +
" return YES;\n" +
" }";
viewControllerContent = viewControllerContent.Replace (vcOldText, vcNewText);
File.WriteAllText (viewControllerPath, viewControllerContent);
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment