MenuChangeAppLanguage.cs 2.2 KB

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