|
|
@@ -1,85 +1,117 @@
|
|
|
using UnityEditor;
|
|
|
using UnityEngine;
|
|
|
|
|
|
-//在编辑菜单中增加功能-APP语言版本切换
|
|
|
public class MenuChangeAppLanguage
|
|
|
{
|
|
|
+ enum LanguageType { CN = 0, EN = 1 }
|
|
|
+ enum DeviceType { iPhone, iPad }
|
|
|
+
|
|
|
static void RefreshMenuChecked()
|
|
|
{
|
|
|
- Menu.SetChecked("APP语言版本切换/中文", CommonConfig.AppLanguage == 0);
|
|
|
- Menu.SetChecked("APP语言版本切换/英文", CommonConfig.AppLanguage == 1);
|
|
|
+ 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语言版本切换/中文")]
|
|
|
- static void ToCN()
|
|
|
+ [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)
|
|
|
{
|
|
|
- PlayerSettings.productName = CommonConfig.StandaloneModeOrPlatformB ? CommonConfig.AppNames[2]: CommonConfig.AppNames[0];
|
|
|
+ int langId = (int)lang;
|
|
|
+ // EditorPrefs.SetInt("AppLanguage", langId);
|
|
|
+
|
|
|
+ PlayerSettings.productName = CommonConfig.StandaloneModeOrPlatformB
|
|
|
+ ? CommonConfig.AppNames[2]
|
|
|
+ : CommonConfig.AppNames[langId];
|
|
|
+
|
|
|
#if UNITY_IOS
|
|
|
- PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, "com.xmjssvr.BowArrow");
|
|
|
+ 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
|
|
|
- if (CommonConfig.StandaloneModeOrPlatformB)
|
|
|
+ string androidId = lang switch
|
|
|
{
|
|
|
+ LanguageType.CN => CommonConfig.StandaloneModeOrPlatformB
|
|
|
+ ? "com.xmjssvr.BowArrow.miBClient"
|
|
|
+ : "com.xmjssvr.BowArrow.mi",
|
|
|
|
|
|
- PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrow.miBClient"); //com.xmjssvr.BowArrow
|
|
|
- }
|
|
|
- else {
|
|
|
+ LanguageType.EN => CommonConfig.StandaloneModeOrPlatformB
|
|
|
+ ? "com.xmjssvr.BowArrowEn.BClient"
|
|
|
+ : "com.xmjssvr.BowArrowEn",
|
|
|
|
|
|
- PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrow.mi"); //com.xmjssvr.BowArrow
|
|
|
- }
|
|
|
+ _ => "com.xmjssvr.BowArrow"
|
|
|
+ };
|
|
|
+
|
|
|
+ PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, androidId);
|
|
|
#endif
|
|
|
- SetIosAppIcon(0);
|
|
|
- }
|
|
|
|
|
|
- [MenuItem("APP语言版本切换/中文", true)]
|
|
|
- static bool ToCN_Check()
|
|
|
- {
|
|
|
- RefreshMenuChecked();
|
|
|
- return true;
|
|
|
+ SetIosAppIcon(langId, device);
|
|
|
}
|
|
|
|
|
|
- [MenuItem("APP语言版本切换/英文")]
|
|
|
- static void ToEN()
|
|
|
+ static void SetIosAppIcon(int langId, DeviceType device)
|
|
|
{
|
|
|
- //PlayerSettings.productName = CommonConfig.AppNames[1];
|
|
|
- PlayerSettings.productName = CommonConfig.StandaloneModeOrPlatformB ? CommonConfig.AppNames[2] : CommonConfig.AppNames[1];
|
|
|
-#if UNITY_IOS
|
|
|
- PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, "com.xmjssvr.BowArrowEn");
|
|
|
- PlayerSettings.iOS.appleDeveloperTeamID = "WR7WD35237";
|
|
|
- PlayerSettings.iOS.appleEnableAutomaticSigning = true;
|
|
|
-#endif
|
|
|
-#if UNITY_ANDROID
|
|
|
- if (CommonConfig.StandaloneModeOrPlatformB)
|
|
|
+ //string path = langId == 1
|
|
|
+ // ? "Assets/BowArrow/Textures/Common/AppIconEN.png"
|
|
|
+ // : "Assets/BowArrow/Textures/Common/AppIcon2.png";
|
|
|
+ string path;
|
|
|
+
|
|
|
+ if (device == DeviceType.iPad)
|
|
|
{
|
|
|
- PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn.BClient"); //com.xmjssvr.BowArrow
|
|
|
+ // iPad版,选用 Pad 专用图标
|
|
|
+ path = langId == 1
|
|
|
+ ? "Assets/BowArrow/Textures/Common/AppIconPadEN.png"
|
|
|
+ : "Assets/BowArrow/Textures/Common/AppIconPad.png";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn");//com.xmjssvr.BowArrow.mi
|
|
|
+ // 普通版
|
|
|
+ path = langId == 1
|
|
|
+ ? "Assets/BowArrow/Textures/Common/AppIconEN.png"
|
|
|
+ : "Assets/BowArrow/Textures/Common/AppIcon2.png";
|
|
|
}
|
|
|
-#endif
|
|
|
- SetIosAppIcon(1);
|
|
|
- }
|
|
|
-
|
|
|
- [MenuItem("APP语言版本切换/英文", true)]
|
|
|
- static bool ToEN_Check()
|
|
|
- {
|
|
|
- RefreshMenuChecked();
|
|
|
- return true;
|
|
|
- }
|
|
|
|
|
|
- static void SetIosAppIcon(int id)
|
|
|
- {
|
|
|
- string path = "Assets/BowArrow/Textures/Common/AppIcon2.png";
|
|
|
- if (id == 1) {
|
|
|
- path = "Assets/BowArrow/Textures/Common/AppIconEN.png";
|
|
|
+ Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
|
|
|
+ if (texture == null)
|
|
|
+ {
|
|
|
+ Debug.LogWarning("图标文件未找到:" + path);
|
|
|
+ return;
|
|
|
}
|
|
|
- Texture2D texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
|
|
|
- Texture2D[] textureArray = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Unknown);
|
|
|
- for (int i = 0; i < textureArray.Length; i++) textureArray[i] = texture;
|
|
|
- PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, textureArray);
|
|
|
+
|
|
|
+ Texture2D[] icons = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Unknown);
|
|
|
+ for (int i = 0; i < icons.Length; i++) icons[i] = texture;
|
|
|
+ PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, icons);
|
|
|
AssetDatabase.SaveAssets();
|
|
|
}
|
|
|
}
|