Last active
October 5, 2018 15:07
Star
You must be signed in to star a gist
iPhoneXでのみStatusBarを表示する設定
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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