MenuChangeAppLanguage.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #endif
  18. #if UNITY_ANDROID
  19. if (CommonConfig.StandaloneModeOrPlatformB)
  20. {
  21. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrow.miBClient"); //com.xmjssvr.BowArrow
  22. }
  23. else {
  24. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrow.mi"); //com.xmjssvr.BowArrow
  25. }
  26. #endif
  27. SetIosAppIcon(0);
  28. }
  29. [MenuItem("APP语言版本切换/中文", true)]
  30. static bool ToCN_Check()
  31. {
  32. RefreshMenuChecked();
  33. return true;
  34. }
  35. [MenuItem("APP语言版本切换/英文")]
  36. static void ToEN()
  37. {
  38. //PlayerSettings.productName = CommonConfig.AppNames[1];
  39. PlayerSettings.productName = CommonConfig.StandaloneModeOrPlatformB ? CommonConfig.AppNames[2] : CommonConfig.AppNames[1];
  40. #if UNITY_IOS
  41. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, "com.xmjssvr.BowArrowEn");
  42. #endif
  43. #if UNITY_ANDROID
  44. if (CommonConfig.StandaloneModeOrPlatformB)
  45. {
  46. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn.BClient"); //com.xmjssvr.BowArrow
  47. }
  48. else
  49. {
  50. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn");//com.xmjssvr.BowArrow.mi
  51. }
  52. #endif
  53. SetIosAppIcon(1);
  54. }
  55. [MenuItem("APP语言版本切换/英文", true)]
  56. static bool ToEN_Check()
  57. {
  58. RefreshMenuChecked();
  59. return true;
  60. }
  61. static void SetIosAppIcon(int id)
  62. {
  63. string path = "Assets/BowArrow/Textures/Common/AppIcon2.png";
  64. if (id == 1) {
  65. path = "Assets/BowArrow/Textures/Common/AppIconEN.png";
  66. }
  67. Texture2D texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
  68. Texture2D[] textureArray = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Unknown);
  69. for (int i = 0; i < textureArray.Length; i++) textureArray[i] = texture;
  70. PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, textureArray);
  71. AssetDatabase.SaveAssets();
  72. }
  73. }