MenuChangeAppLanguage.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using UnityEditor;
  2. using UnityEngine;
  3. //在编辑菜单中增加功能-APP语言版本切换
  4. public class MenuChangeAppLanguage
  5. {
  6. static void RefreshMenuChecked()
  7. {
  8. Menu.SetChecked("APP语言版本切换/中文", CommonConfig.AppLanguage == 0);
  9. Menu.SetChecked("APP语言版本切换/英文", CommonConfig.AppLanguage == 1);
  10. }
  11. [MenuItem("APP语言版本切换/中文")]
  12. static void ToCN()
  13. {
  14. PlayerSettings.productName = CommonConfig.StandaloneModeOrPlatformB ? CommonConfig.AppNames[2]: CommonConfig.AppNames[0];
  15. #if UNITY_IOS
  16. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, "com.xmjssvr.BowArrow");
  17. PlayerSettings.iOS.appleDeveloperTeamID = "WR7WD35237";
  18. PlayerSettings.iOS.appleEnableAutomaticSigning = true;
  19. #endif
  20. #if UNITY_ANDROID
  21. if (CommonConfig.StandaloneModeOrPlatformB)
  22. {
  23. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrow.miBClient"); //com.xmjssvr.BowArrow
  24. }
  25. else {
  26. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrow.mi"); //com.xmjssvr.BowArrow
  27. }
  28. #endif
  29. SetIosAppIcon(0);
  30. }
  31. [MenuItem("APP语言版本切换/中文", true)]
  32. static bool ToCN_Check()
  33. {
  34. RefreshMenuChecked();
  35. return true;
  36. }
  37. [MenuItem("APP语言版本切换/英文")]
  38. static void ToEN()
  39. {
  40. //PlayerSettings.productName = CommonConfig.AppNames[1];
  41. PlayerSettings.productName = CommonConfig.StandaloneModeOrPlatformB ? CommonConfig.AppNames[2] : CommonConfig.AppNames[1];
  42. #if UNITY_IOS
  43. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, "com.xmjssvr.BowArrowEn");
  44. PlayerSettings.iOS.appleDeveloperTeamID = "WR7WD35237";
  45. PlayerSettings.iOS.appleEnableAutomaticSigning = true;
  46. #endif
  47. #if UNITY_ANDROID
  48. if (CommonConfig.StandaloneModeOrPlatformB)
  49. {
  50. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn.BClient"); //com.xmjssvr.BowArrow
  51. }
  52. else
  53. {
  54. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn");//com.xmjssvr.BowArrow.mi
  55. }
  56. #endif
  57. SetIosAppIcon(1);
  58. }
  59. [MenuItem("APP语言版本切换/英文", true)]
  60. static bool ToEN_Check()
  61. {
  62. RefreshMenuChecked();
  63. return true;
  64. }
  65. static void SetIosAppIcon(int id)
  66. {
  67. string path = "Assets/BowArrow/Textures/Common/AppIcon2.png";
  68. if (id == 1) {
  69. path = "Assets/BowArrow/Textures/Common/AppIconEN.png";
  70. }
  71. Texture2D texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
  72. Texture2D[] textureArray = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Unknown);
  73. for (int i = 0; i < textureArray.Length; i++) textureArray[i] = texture;
  74. PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, textureArray);
  75. AssetDatabase.SaveAssets();
  76. }
  77. }