MenuChangeAppLanguage.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #if UNITY_IOS
  40. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, "com.xmjssvr.BowArrowEn");
  41. #endif
  42. #if UNITY_ANDROID
  43. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.xmjssvr.BowArrowEn");//com.xmjssvr.BowArrow.mi
  44. #endif
  45. SetIosAppIcon(1);
  46. }
  47. [MenuItem("APP语言版本切换/英文", true)]
  48. static bool ToEN_Check()
  49. {
  50. RefreshMenuChecked();
  51. return true;
  52. }
  53. static void SetIosAppIcon(int id)
  54. {
  55. string path = "Assets/BowArrow/Textures/Common/AppIcon2.png";
  56. if (id == 1) {
  57. path = "Assets/BowArrow/Textures/Common/AppIconEN.png";
  58. }
  59. Texture2D texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
  60. Texture2D[] textureArray = PlayerSettings.GetIconsForTargetGroup(BuildTargetGroup.Unknown);
  61. for (int i = 0; i < textureArray.Length; i++) textureArray[i] = texture;
  62. PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Unknown, textureArray);
  63. AssetDatabase.SaveAssets();
  64. }
  65. }