MenuChangeAppLanguage.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. //和国内版一样名字
  40. PlayerSettings.productName = CommonConfig.StandaloneModeOrPlatformB ? CommonConfig.AppNames[2] : CommonConfig.AppNames[0];
  41. #if UNITY_IOS
  42. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, "com.xmjssvr.BowArrowEn");
  43. #endif
  44. #if UNITY_ANDROID
  45. if (CommonConfig.StandaloneModeOrPlatformB)
  46. {
  47. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn.BClient"); //com.xmjssvr.BowArrow
  48. }
  49. else
  50. {
  51. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn");//com.xmjssvr.BowArrow.mi
  52. }
  53. #endif
  54. SetIosAppIcon(1);
  55. }
  56. [MenuItem("APP语言版本切换/英文", true)]
  57. static bool ToEN_Check()
  58. {
  59. RefreshMenuChecked();
  60. return true;
  61. }
  62. static void SetIosAppIcon(int id)
  63. {
  64. string path = "Assets/BowArrow/Textures/Common/AppIcon2.png";
  65. if (id == 1) {
  66. path = "Assets/BowArrow/Textures/Common/AppIconEN.png";
  67. }
  68. Texture2D texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
  69. Texture2D[] textureArray = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Unknown);
  70. for (int i = 0; i < textureArray.Length; i++) textureArray[i] = texture;
  71. PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, textureArray);
  72. AssetDatabase.SaveAssets();
  73. }
  74. }