223 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			223 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			C#
		
	
	
	
| #if UNITY_IOS
 | |
| using System.IO;
 | |
| using System.Runtime.InteropServices.WindowsRuntime;
 | |
| using UnityEditor;
 | |
| using UnityEditor.Callbacks;
 | |
| #if UNITY_IOS
 | |
| using UnityEditor.iOS.Xcode;
 | |
| #endif
 | |
| using UnityEngine;
 | |
| 
 | |
| public class ToukaAnalyticsBuildPostProcessor
 | |
| {
 | |
| 	[PostProcessBuild]
 | |
| 	public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
 | |
| 	{
 | |
| 		if (buildTarget != BuildTarget.iOS) return;
 | |
| 
 | |
| #if UNITY_IOS
 | |
| 		copyConfigFile(path);
 | |
| 		SetTeamIdAutoSign(path);
 | |
| 		ModifyFrameworks(path);
 | |
| 		ModifyBuildSettings(path);
 | |
| 
 | |
| 		ModifyInfoPlist(path);
 | |
| 
 | |
| 		//AddLocalization(path);
 | |
| 		CopySplashImg(path);
 | |
| #endif
 | |
| 	}
 | |
| 
 | |
| 	private static void ModifyFrameworks(string _path)
 | |
| 	{
 | |
| #if UNITY_IOS
 | |
| 		string projPath = PBXProject.GetPBXProjectPath(_path);
 | |
| 		PBXProject proj = new PBXProject();
 | |
| 
 | |
| 
 | |
| 		proj.ReadFromString(File.ReadAllText(projPath));
 | |
| #if UNITY_2019_3_OR_NEWER
 | |
| 		string target = proj.GetUnityFrameworkTargetGuid();
 | |
| #else
 | |
| 		string target = proj.TargetGuidByName("Unity-iPhone");
 | |
| #endif
 | |
| 
 | |
| 		proj.AddFrameworkToProject(target, "GLKit.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "CoreGraphics.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "Photos.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "AppTrackingTransparency.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "StoreKit.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "CoreData.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "AVFoundation.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "Accelerate.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "AdSupport.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "AudioToolbox.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "CoreLocation.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "CoreMedia.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "CoreMotion.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "CoreTelephony.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "MobileCoreServices.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "SafariServices.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "VideoToolbox.framework", false);
 | |
| 		proj.AddFrameworkToProject(target, "WebKit.framework", false);
 | |
| 
 | |
| 
 | |
| 
 | |
| 		string fileGuidSqlite = proj.AddFile("usr/lib/libxml2.tbd", "Libraries/libxml2.tbd", PBXSourceTree.Sdk);
 | |
| 		proj.AddFileToBuild(target, fileGuidSqlite);
 | |
| 		fileGuidSqlite = proj.AddFile("usr/lib/libsqlite3.tbd", "Libraries/libsqlite3.tbd", PBXSourceTree.Sdk);
 | |
| 		proj.AddFileToBuild(target, fileGuidSqlite);
 | |
| 		fileGuidSqlite = proj.AddFile("usr/lib/libc++.tbd", "Libraries/libc++.tbd", PBXSourceTree.Sdk);
 | |
| 		proj.AddFileToBuild(target, fileGuidSqlite);
 | |
| 		fileGuidSqlite = proj.AddFile("usr/lib/libz.tbd", "Libraries/libz.tbd", PBXSourceTree.Sdk);
 | |
| 		proj.AddFileToBuild(target, fileGuidSqlite);
 | |
| 		fileGuidSqlite = proj.AddFile("usr/lib/libresolv.tbd", "Libraries/libresolv.tbd", PBXSourceTree.Sdk);
 | |
| 		proj.AddFileToBuild(target, fileGuidSqlite);
 | |
| 		fileGuidSqlite = proj.AddFile("usr/lib/libbz2.1.0.tbd", "Libraries/libbz2.1.0.tbd", PBXSourceTree.Sdk);
 | |
| 		proj.AddFileToBuild(target, fileGuidSqlite);
 | |
| 		fileGuidSqlite = proj.AddFile("usr/lib/libresolv.9.tbd", "Libraries/libresolv.9.tbd", PBXSourceTree.Sdk);
 | |
| 		proj.AddFileToBuild(target, fileGuidSqlite);
 | |
| 		fileGuidSqlite = proj.AddFile("usr/lib/libc++abi.tbd", "Libraries/libc++abi.tbd", PBXSourceTree.Sdk);
 | |
| 		proj.AddFileToBuild(target, fileGuidSqlite);
 | |
| 
 | |
| 		// sdk config files
 | |
| 		proj.AddFileToBuild(target, proj.AddFile("tkg_config.plist", "tkg_config.plist",PBXSourceTree.Source));
 | |
| 		File.WriteAllText(projPath, proj.WriteToString());
 | |
| 
 | |
| #if UNITY_2019_3_OR_NEWER
 | |
| 		string mainTarget = proj.GetUnityMainTargetGuid();
 | |
| #else
 | |
| 		string targetName = UnityEditor.iOS.Xcode.PBXProject.GetUnityTargetName();
 | |
| 		string mainTarget = proj.TargetGuidByName(targetName);
 | |
| #endif
 | |
| 		proj.AddFileToBuild(mainTarget, proj.AddFile("tkg_config.plist", "tkg_config.plist", PBXSourceTree.Source));
 | |
| 		proj.WriteToFile(projPath);
 | |
| 
 | |
| 		proj.AddFileToBuild(target, proj.AddFile("tkg_sdk_config.plist", "tkg_sdk_config.plist", PBXSourceTree.Source));
 | |
| 		File.WriteAllText(projPath, proj.WriteToString());
 | |
| 
 | |
| 		proj.AddFileToBuild(mainTarget, proj.AddFile("tkg_sdk_config.plist", "tkg_sdk_config.plist", PBXSourceTree.Source));
 | |
| 		proj.WriteToFile(projPath);
 | |
| 
 | |
| #if AppStore_GB
 | |
| 		proj.AddFileToBuild(target, proj.AddFile("GoogleService-Info.plist", "GoogleService-Info.plist", PBXSourceTree.Source));
 | |
| 		File.WriteAllText(projPath, proj.WriteToString());
 | |
| 
 | |
| 		proj.AddFileToBuild(mainTarget, proj.AddFile("GoogleService-Info.plist", "GoogleService-Info.plist", PBXSourceTree.Source));
 | |
| 		proj.WriteToFile(projPath);
 | |
| 
 | |
| #endif
 | |
| 		
 | |
| #endif
 | |
| 	}
 | |
| 
 | |
| 	private static void copyConfigFile(string path)
 | |
| 	{
 | |
| #if AppStore_GB
 | |
| 		string configPath = Application.dataPath + "/Configs/GB/tkg_config.plist";
 | |
| 		File.Copy(configPath, path + "/tkg_config.plist", true);
 | |
| 
 | |
| 		string sdkConfigPath = Application.dataPath + "/Configs/GB/tkg_sdk_config.plist";
 | |
| 		File.Copy(sdkConfigPath, path + "/tkg_sdk_config.plist", true);
 | |
| 
 | |
| 		string googlePath = Application.dataPath + "/Configs/GB/GoogleService-Info.plist";
 | |
| 		File.Copy(googlePath, path + "/GoogleService-Info.plist", true);
 | |
| #else
 | |
| 		string configPath = Application.dataPath + "/Configs/CN/tkg_config.plist";
 | |
| 		File.Copy(configPath, path + "/tkg_config.plist", true);
 | |
| 
 | |
| 		string sdkConfigPath = Application.dataPath + "/Configs/CN/tkg_sdk_config.plist";
 | |
| 		File.Copy(sdkConfigPath, path + "/tkg_sdk_config.plist", true);
 | |
| #endif
 | |
| 	}
 | |
| 
 | |
| 
 | |
| 	private static void ModifyBuildSettings(string _path)
 | |
| 	{
 | |
| #if UNITY_IOS
 | |
| 		string projPath = PBXProject.GetPBXProjectPath(_path);
 | |
| 		PBXProject proj = new PBXProject();
 | |
| 		proj.ReadFromString(File.ReadAllText(projPath));
 | |
| 
 | |
| #if UNITY_2019_3_OR_NEWER
 | |
| 		string target = proj.GetUnityFrameworkTargetGuid();
 | |
| #else
 | |
| 		string target = proj.TargetGuidByName("Unity-iPhone");
 | |
| #endif
 | |
| 
 | |
| 		proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
 | |
| 		proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
 | |
| 		proj.SetBuildProperty(target, "GCC_C_LANGUAGE_STANDARD", "gnu99");
 | |
| 		proj.SetBuildProperty(target, "GCC_ENABLE_OBJC_EXCEPTIONS","YES");
 | |
| 		proj.SetBuildProperty(target, "EXCLUDED_ARCHS", "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64=arm64 arm64e armv7 armv7s armv6 armv8 EXCLUDED_ARCHS=$(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT))");
 | |
| 
 | |
| 
 | |
| 		File.WriteAllText(projPath, proj.WriteToString());
 | |
| #endif
 | |
| 	}
 | |
| 
 | |
| 	private static void SetTeamIdAutoSign(string _path)
 | |
| 	{
 | |
| #if UNITY_IOS
 | |
| 		string projPath = PBXProject.GetPBXProjectPath(_path);
 | |
| 		PBXProject proj = new PBXProject();
 | |
| 		proj.ReadFromString(File.ReadAllText(projPath));
 | |
| 		File.WriteAllText(projPath, proj.WriteToString());
 | |
| #endif
 | |
| 	}
 | |
| 
 | |
| 	private static void ModifyInfoPlist(string _path)
 | |
| 	{
 | |
| #if UNITY_IOS
 | |
| 		//2、修改Info.plist文件
 | |
| 		var plistPath = Path.Combine(_path, "Info.plist");
 | |
| 		var plist = new PlistDocument();
 | |
| 		plist.ReadFromFile(plistPath);
 | |
| #if !AppStore_GB
 | |
| 		plist.root.SetString("NSLocationAlwaysUsageDescription", "为了更好的体验游戏");
 | |
| 		plist.root.SetString("NSLocationWhenInUseUsageDescription", "为了更好的体验游戏");
 | |
| 		plist.root.SetString("NSUserTrackingUsageDescription", "该标识符将用于向您投放个性化广告");
 | |
| 		plist.root.SetString("NSPhotoLibraryUsageDescription", "为了更好的体验游戏,请允许APP保存图片到您的相册");
 | |
| #else
 | |
| 		plist.root.SetString ("NSLocationAlwaysUsageDescription", "for better experience the game");
 | |
| 		plist.root.SetString ("NSLocationWhenInUseUsageDescription", "for better experience the game");
 | |
| 		plist.root.SetString("NSUserTrackingUsageDescription", "This identifier will be used to deliver personalized ads to you.");
 | |
| 		plist.root.SetString("NSPhotoLibraryUsageDescription", "In order to experience the game better, please allow the APP to save pictures to your album.");
 | |
| 		
 | |
| #endif
 | |
| 		File.WriteAllText(plistPath, plist.WriteToString());
 | |
| #endif
 | |
| 	}
 | |
| 
 | |
| 
 | |
| 
 | |
| //	static void AddLocalization(string path)
 | |
| //	{
 | |
| //#if !NO_SDK
 | |
| //		string pliststringPath = Application.dataPath + "/TKGSDK/UnitySDK/Plugins/ToukaGames/iOS/CommonPackage/lang/infoplist";
 | |
| //		NativeLocale.AddLocalizedStringsIOS(path, pliststringPath);
 | |
| //#endif
 | |
| //	}
 | |
| 
 | |
| 	static void CopySplashImg(string path)
 | |
| 	{
 | |
| #if !AppStore_GB
 | |
| 		string splashImgPath = Application.dataPath + "/TKGSDK/Splash/CN/LaunchScreen-iPhonePortrait.png";
 | |
| 		File.Copy(splashImgPath, path + "/LaunchScreen-iPhonePortrait.png", true);
 | |
| 
 | |
| 		string splashImgPathIpad = Application.dataPath + "/TKGSDK/Splash/CN/LaunchScreen-iPad.png";
 | |
| 		File.Copy(splashImgPathIpad, path + "/LaunchScreen-iPad.png", true);
 | |
| #else
 | |
| 
 | |
| 	string splashImgPath = Application.dataPath + "/TKGSDK/Splash/GB/LaunchScreen-iPhonePortrait.png";
 | |
| 		File.Copy(splashImgPath, path + "/LaunchScreen-iPhonePortrait.png", true);
 | |
| 
 | |
| 		string splashImgPathIpad = Application.dataPath + "/TKGSDK/Splash/GB/LaunchScreen-iPad.png";
 | |
| 		File.Copy(splashImgPathIpad, path + "/LaunchScreen-iPad.png", true);
 | |
| #endif
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| #endif |