using UnityEditor; using UnityEngine; public class MenuChangeAppLanguage { enum LanguageType { CN = 0, EN = 1 } enum DeviceType { iPhone, iPad } static void RefreshMenuChecked() { int lang = CommonConfig.AppLanguage; //EditorPrefs.GetInt("AppLanguage", 0); string iosTarget = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS); Menu.SetChecked("APP语言版本切换/中文/iPhone", lang == 0 && iosTarget.Contains("BowArrow") && !iosTarget.Contains("Pad")); Menu.SetChecked("APP语言版本切换/中文/iPad", lang == 0 && iosTarget.Contains("PadBowArrow")); Menu.SetChecked("APP语言版本切换/英文/iPhone", lang == 1 && iosTarget.Contains("BowArrowEn") && !iosTarget.Contains("Pad")); Menu.SetChecked("APP语言版本切换/英文/iPad", lang == 1 && iosTarget.Contains("PadBowArrowEn")); } [MenuItem("APP语言版本切换/中文/iPhone")] static void CN_iPhone() => ApplySetting(LanguageType.CN, DeviceType.iPhone); [MenuItem("APP语言版本切换/中文/iPhone", true)] static bool CN_iPhone_Validate() { RefreshMenuChecked(); return true; } [MenuItem("APP语言版本切换/中文/iPad")] static void CN_iPad() => ApplySetting(LanguageType.CN, DeviceType.iPad); [MenuItem("APP语言版本切换/中文/iPad", true)] static bool CN_iPad_Validate() { RefreshMenuChecked(); return true; } [MenuItem("APP语言版本切换/英文/iPhone")] static void EN_iPhone() => ApplySetting(LanguageType.EN, DeviceType.iPhone); [MenuItem("APP语言版本切换/英文/iPhone", true)] static bool EN_iPhone_Validate() { RefreshMenuChecked(); return true; } [MenuItem("APP语言版本切换/英文/iPad")] static void EN_iPad() => ApplySetting(LanguageType.EN, DeviceType.iPad); [MenuItem("APP语言版本切换/英文/iPad", true)] static bool EN_iPad_Validate() { RefreshMenuChecked(); return true; } static void ApplySetting(LanguageType lang, DeviceType device) { int langId = (int)lang; // EditorPrefs.SetInt("AppLanguage", langId); PlayerSettings.productName = CommonConfig.StandaloneModeOrPlatformB ? CommonConfig.AppNames[2] : CommonConfig.AppNames[langId]; #if UNITY_IOS string bundleId = lang switch { LanguageType.CN => device == DeviceType.iPhone ? "com.xmjssvr.BowArrow" : "com.xmjssvr.PadBowArrow", LanguageType.EN => device == DeviceType.iPhone ? "com.xmjssvr.BowArrowEn" : "com.xmjssvr.PadBowArrowEn", _ => "com.xmjssvr.BowArrow" }; PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, bundleId); PlayerSettings.iOS.targetDevice = device == DeviceType.iPhone ? iOSTargetDevice.iPhoneOnly : iOSTargetDevice.iPadOnly; PlayerSettings.iOS.appleDeveloperTeamID = "WR7WD35237"; PlayerSettings.iOS.appleEnableAutomaticSigning = true; #endif #if UNITY_ANDROID string androidId = lang switch { LanguageType.CN => CommonConfig.StandaloneModeOrPlatformB ? "com.xmjssvr.BowArrow.miBClient" : "com.xmjssvr.BowArrow.mi", LanguageType.EN => CommonConfig.StandaloneModeOrPlatformB ? "com.xmjssvr.BowArrowEn.BClient" : "com.xmjssvr.BowArrowEn", _ => "com.xmjssvr.BowArrow" }; PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, androidId); #endif SetIosAppIcon(langId, device); } static void SetIosAppIcon(int langId, DeviceType device) { //string path = langId == 1 // ? "Assets/BowArrow/Textures/Common/AppIconEN.png" // : "Assets/BowArrow/Textures/Common/AppIcon2.png"; string path; if (device == DeviceType.iPad) { // iPad版,选用 Pad 专用图标 path = langId == 1 ? "Assets/BowArrow/Textures/Common/AppIconPadEN.png" : "Assets/BowArrow/Textures/Common/AppIconPad.png"; } else { // 普通版 path = langId == 1 ? "Assets/BowArrow/Textures/Common/AppIconEN.png" : "Assets/BowArrow/Textures/Common/AppIcon2.png"; } Texture2D texture = AssetDatabase.LoadAssetAtPath(path); if (texture == null) { Debug.LogWarning("图标文件未找到:" + path); return; } Texture2D[] icons = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Unknown); for (int i = 0; i < icons.Length; i++) icons[i] = texture; PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, icons); AssetDatabase.SaveAssets(); } }