MenuChangeAppLanguage.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. SetIosAppIcon(false);
  18. #endif
  19. #if UNITY_ANDROID
  20. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrow.mi");
  21. #endif
  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. SetIosAppIcon(true);
  36. #endif
  37. #if UNITY_ANDROID
  38. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn");
  39. #endif
  40. }
  41. [MenuItem("APP语言版本切换/英文", true)]
  42. static bool ToEN_Check()
  43. {
  44. RefreshMenuChecked();
  45. return true;
  46. }
  47. static void SetIosAppIcon(bool en)
  48. {
  49. Texture2D texture = null;
  50. if (en) {
  51. texture = AssetDatabase.LoadAssetAtPath(
  52. "Assets/BowArrow/Textures/Common/AppIconEN.png", typeof(Texture2D)) as Texture2D;
  53. }
  54. int[] iconSize = PlayerSettings.GetIconSizesForTargetGroup(BuildTargetGroup.iOS);
  55. Texture2D[] textureArray = new Texture2D[iconSize.Length];
  56. for (int i = 0; i < textureArray.Length; i++) textureArray[i] = texture;
  57. PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.iOS, textureArray);
  58. AssetDatabase.SaveAssets();
  59. }
  60. }