unity 用代碼編輯打包出來(lái)的xcode工程腳本UnityAppController

1.首先我的目標(biāo)是要寫(xiě)入圖1中紅色框那個(gè),主要是用來(lái)處理UIApplicationInvalidInterfaceOrientation Supported orientations has no common orientation with the application, and [GADFullScreenAdViewController shouldAutorotate] is returning YES -[UnityAppController(Rendering) processTouchEvents]的問(wèn)題的,http://www.itdecent.cn/p/5ca358d29d88,可以看上面的鏈接有說(shuō)明

圖 1

2.

```

usingUnityEngine;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.IO;namespaceUnityEditor.XCodeEditor{publicpartialclassXClass:System.IDisposable{privatestring filePath;publicXClass(string fPath){filePath=fPath;if(!System.IO.File.Exists(filePath)){Debug.LogError(filePath+"路徑下文件不存在");return;}}publicvoidWriteBelow(string below,string text){StreamReader streamReader=newStreamReader(filePath);string text_all=streamReader.ReadToEnd();streamReader.Close();intbeginIndex=text_all.IndexOf(below);if(beginIndex==-1){Debug.LogError(filePath+"中沒(méi)有找到標(biāo)致"+below);return;}intendIndex=text_all.LastIndexOf("\n",beginIndex+below.Length);text_all=text_all.Substring(0,endIndex)+"\n"+text+"\n"+text_all.Substring(endIndex);StreamWriter streamWriter=newStreamWriter(filePath);streamWriter.Write(text_all);streamWriter.Close();}publicvoidReplace(string below,string newText){StreamReader streamReader=newStreamReader(filePath);string text_all=streamReader.ReadToEnd();streamReader.Close();intbeginIndex=text_all.IndexOf(below);if(beginIndex==-1){Debug.LogError(filePath+"中沒(méi)有找到標(biāo)致"+below);return;}text_all=text_all.Replace(below,newText);StreamWriter streamWriter=newStreamWriter(filePath);streamWriter.Write(text_all);streamWriter.Close();}publicvoidDispose(){}}}

```


```

usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEditor;usingUnityEditor.Callbacks;usingUnityEditor.iOS.Xcode;usingSystem.IO;usingSystem;usingUnityEditor.XCodeEditor;publicclassZPXCodePostProcess{#ifUNITY_EDITOR[PostProcessBuild(1000)]publicstaticvoidOnPostProcessBuild(BuildTargettarget,stringpathToBuiltProject){if(target!=BuildTarget.iOS)return;//得到xcode工程的路徑stringpath=Path.GetFullPath(pathToBuiltProject);//編輯代碼文件EditorCode(path);}privatestaticvoidEditorCode(stringfilePath){//讀取UnityAppController.mm文件XClassUnityAppController=newXClass(filePath+"/Classes/UnityAppController.mm");//在指定代碼后面增加一行代碼UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"","#import \"IOSLoader.h\"");//在指定代碼后面增加一行代碼UnityAppController.WriteBelow("AppController_SendNotificationWithArg(kUnityWillFinishLaunchingWithOptions, launchOptions);","\r\t [IOSLoader splashReport];");UnityAppController.WriteBelow("AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);","\r\t return [IOSLoader application:app openURL:url options:options];");UnityAppController.WriteBelow("UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]);","\r\t [IOSLoader application:application DidFinishLaunchingWithOptions:launchOptions];");UnityAppController.WriteBelow("- (void)applicationDidEnterBackground:(UIApplication*)application\n{","\r\t [IOSLoader applicationDidEnterBackground:application];");UnityAppController.WriteBelow("- (void)applicationWillEnterForeground:(UIApplication*)application\n{","\r\t [IOSLoader applicationWillEnterForeground:application];");UnityAppController.WriteBelow("- (void)applicationDidBecomeActive:(UIApplication*)application\n{","\r\t [IOSLoader applicationDidBecomeActive:application];");UnityAppController.WriteBelow(" SensorsCleanup();\n}","- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler \r{\r\t return [IOSLoader application:application continueUserActivity:userActivity restorationHandler:restorationHandler];\r}");}#endif}

```

這里我之前主要是參考http://www.itdecent.cn/p/366110eb1610來(lái)編寫(xiě)的

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容